I'm creating EKS cluster using AWS CDK. I want to assigned clustername as per the environment. We have prefix for each environment in SSM parameter. I'm trying to specifiy cluster name as follows:
First step- fetch prefix:
const clusternamevalue = ssm.StringParameter.fromStringParameterAttributes(this, 'clustername', {
parameterName:'environment-identifier-short'
} ).stringValue
Second step- create cluster:
new eks.Cluster(this, 'cluster', {
version: eks.KubernetesVersion.V1_19,
clusterName: 'eks-'.concat(clusternamevalue),
});
But cluster is not getting created and throws message in Cloudformation: Respective role<rolearn> is not authorized to perform: eks:CreateCluster on resource <ClusterARN>
On checking Cfn template I see that the policy to create cluster is getting created in below way:
Resource": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":eks:eu-west-1:XXXXXXXXX:cluster/[object Object]"
]
]
},
I think due to [object object] part , policy is not getting created with correct cluster name. Hence it getting failed. if we hardcode clustername, it will work.
Any suggestion, how i solve this issue? or how i can explicitly pass the role while creating cluster?