https://pulumi.com logo
Title
j

jolly-church-88521

11/10/2022, 4:17 PM
Hi - any idea how to force pulumi to depends on the EKS cluster when creating https://www.pulumi.com/registry/packages/aws-iam/api-docs/eksrole/ ? I already tried things like:
}, pulumi.DependsOn([]pulumi.Resource{e.Cluster}))
but somehow it doesn’t work. Any hit? 😞
b

billowy-army-68599

11/10/2022, 4:51 PM
that should work, what error message do you get?
g

gray-fountain-32432

11/10/2022, 5:04 PM
@jolly-church-88521 maybe you could have a try on pulumi.Parent func?
b

billowy-army-68599

11/10/2022, 5:12 PM
Parent would make any difference
j

jolly-church-88521

11/10/2022, 7:38 PM
This is my code:
func (e *EKSAddons) newServiceAccountRole(ctx *pulumi.Context, roleName string, serviceAccountName string, namespace string) (*iamv2.EKSRole, error) {
	serviceAccount := fmt.Sprintf("%v:%v", namespace, serviceAccountName)

	eksRole, err := iamv2.NewEKSRole(ctx, roleName, &iamv2.EKSRoleArgs{
		Role: iamv2.RoleArgs{
			Name: pulumi.String(roleName),
			PolicyArns: pulumi.ToStringArray([]string{
				"arn:aws:iam::aws:policy/AmazonRoute53DomainsFullAccess",
			}),
		},
		Tags: pulumi.ToStringMap(map[string]string{
			"Role": roleName,
		}),
		ClusterServiceAccounts: &iamv2.EKSServiceAccountArray{
			iamv2.EKSServiceAccountArgs{
				Name: pulumi.String(e.Name),
				ServiceAccounts: pulumi.StringArray{
					pulumi.String(serviceAccount),
				},
			},
		},
	}, pulumi.DependsOn([]pulumi.Resource{e.Cluster}))
	if err != nil {
		return nil, err
	}

	return eksRole, nil
}
This
e.Name
is a new EKS cluster which I want to create.
When I change it to some existing one, it all works fine.
Is there any way to somehow debug it or verify if I’m not missing something? 😕
b

billowy-army-68599

11/10/2022, 7:43 PM
e
is type
e *EKSAddons
e.Cluster
likely doesn’t exist on
EKSAddons
?
j

jolly-church-88521

11/10/2022, 7:45 PM
No, not yet. This EKSAddons is just a wrapper to debug this issue. In my main.go I’m creating EKS cluster like:
pawelEKS, err := eksCluster.CreateInfrastructure(ctx, "pawels-eks", ...
And now I’m trying to debug it like:
_, err = eksAddons.CreateInfrastructure(ctx, "pawels-eks", pawelEKS)
		if err != nil {
			return err
		}
pawels-eks
struct is:
type EKSCluster struct {
	pulumi.ResourceState

	Name             string
	Cluster          *eks.Cluster
	Providers        pulumi.ResourceOption
	InstanceProfile  *iam.InstanceProfile
	InstanceRole     *iam.Role
	UserRolesMapping eks.RoleMappingArray
	Tags             pulumi.StringMap
}
Diagnostics:
  pulumi:pulumi:Stack (pawel-pre):
    error: an unhandled error occurred: program failed:
    waiting for RPCs: rpc error: code = Unknown desc = waiting for RPCs: marshaling properties: awaiting input property assumeRolePolicy: rpc error: code = Unknown desc = invocation of aws:eks/getCluster:getCluster returned an error: invoking aws:eks/getCluster:getCluster: 1 error occurred:
    	* error reading EKS Cluster (pawels-eks): couldn't find resource
This is the error.
b

billowy-army-68599

11/10/2022, 8:15 PM
where is the cluster itself defined?
j

jolly-church-88521

11/12/2022, 3:13 PM
Ok it works now. Very strange, from what I see in the documentation
name
should be a
string.
And when I’m printing it I see the proper name of the EKS cluster. It started to work with this:
ClusterServiceAccounts: &iamv2.EKSServiceAccountArray{
			iamv2.EKSServiceAccountArgs{
				Name: e.Cluster.Core.Cluster().Name()
So somehow
e.Cluster.Core.Cluster().Name()
works and just
Name()
or
"pawels-eks"
does not.
Ahh, maybe because this should be a
pulumi.StringPtrInput
? 🤦‍♂️