Hi - any idea how to force pulumi to depends on th...
# golang
j
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:
Copy code
}, pulumi.DependsOn([]pulumi.Resource{e.Cluster}))
but somehow it doesn’t work. Any hit? 😞
b
that should work, what error message do you get?
g
@jolly-church-88521 maybe you could have a try on pulumi.Parent func?
b
Parent would make any difference
j
This is my code:
Copy 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
e
is type
e *EKSAddons
e.Cluster
likely doesn’t exist on
EKSAddons
?
j
No, not yet. This EKSAddons is just a wrapper to debug this issue. In my main.go I’m creating EKS cluster like:
Copy code
pawelEKS, err := eksCluster.CreateInfrastructure(ctx, "pawels-eks", ...
And now I’m trying to debug it like:
Copy code
_, err = eksAddons.CreateInfrastructure(ctx, "pawels-eks", pawelEKS)
		if err != nil {
			return err
		}
pawels-eks
struct is:
Copy code
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
}
Copy code
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
where is the cluster itself defined?
j
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:
Copy code
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
? 🤦‍♂️