From 0d8e1c413435c5ac6332cf8b2a21c894c30b6b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20T=C3=BCrken?= Date: Tue, 6 Aug 2024 20:38:55 +0300 Subject: [PATCH] Change external name configurations for the AccessPolicyAssociation and AccessEntry resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fatih Türken --- config/externalname.go | 23 ++--------------------- examples/eks/v1beta1/accessentry.yaml | 23 ----------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/config/externalname.go b/config/externalname.go index daed26b40e..d5b50bbdc6 100644 --- a/config/externalname.go +++ b/config/externalname.go @@ -1118,9 +1118,9 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // eks // // import EKS access entry using the cluster_name and principal_arn separated by a colon (:). - "aws_eks_access_entry": FormattedIdentifierFromParameters(":", "cluster_name", "principal_arn"), + "aws_eks_access_entry": TemplatedStringAsIdentifierWithNoName("{{ .parameters.cluster_name }}:{{ .parameters.principal_arn }}"), // import EKS access entry using the cluster_name principal_arn and policy_arn separated by a (#) which the tf provider docs incorrectly describe as a colon. - "aws_eks_access_policy_association": FormattedIdentifierFromParameters("#", "cluster_name", "principal_arn", "policy_arn"), + "aws_eks_access_policy_association": TemplatedStringAsIdentifierWithNoName("{{ .parameters.cluster_name }}#{{ .parameters.principal_arn }}#{{ .parameters.policy_arn }}"), // "aws_eks_addon": config.TemplatedStringAsIdentifier("addon_name", "{{ .parameters.cluster_name }}:{{ .external_name }}"), // my_cluster:my_eks_addon "aws_eks_addon": FormattedIdentifierFromProvider(":", "cluster_name", "addon_name"), @@ -2977,12 +2977,6 @@ func getPermissionSetId(tfstate map[string]any) (string, error) { // IDs that use elements from the parameters in a certain string format. // It should be used in cases where all information in the ID is gathered from // the spec and not user defined like name. For example, zone_id:vpc_id. -// -// TODO: This should set keys as IdentifierFields, because if they're missing observe-only resources won't work. -// But that would remove them from spec.initProvider, which would be a breaking schema change for existing resources -// that we don't have a good way to handle yet. -// -// For new resources, prefer using FormattedIdentifierFromParameters instead. func FormattedIdentifierFromProvider(separator string, keys ...string) config.ExternalName { e := config.IdentifierFromProvider e.GetIDFn = func(_ context.Context, _ string, parameters map[string]interface{}, _ map[string]interface{}) (string, error) { @@ -3003,19 +2997,6 @@ func FormattedIdentifierFromProvider(separator string, keys ...string) config.Ex return e } -// FormattedIdentifierFromParameters is a helper function to construct Terraform -// IDs that use elements from the parameters joined by some separator string. -// It should be used in cases where all information in the ID is gathered from -// the spec and not user defined like name. For example, zone_id:vpc_id. -// This function sets the keys as IdentifierFields, which means that they are always required, even for observe-only -// resources. Because the id is constructed exclusively from the keys, omitting them (even if the external name -// annotation is set) leaves the provider unable to find the terraform id to use to observe the resource. -func FormattedIdentifierFromParameters(separator string, keys ...string) config.ExternalName { - e := FormattedIdentifierFromProvider(separator, keys...) - e.IdentifierFields = append(e.IdentifierFields, keys...) - return e -} - // FormattedIdentifierUserDefinedNameLast is used in cases where the ID is constructed // using some of the spec fields as well as a field that users use to name the // resource. For example, vpc_id:cluster_name where vpc_id comes from spec diff --git a/examples/eks/v1beta1/accessentry.yaml b/examples/eks/v1beta1/accessentry.yaml index 091726e605..85d6aa39ec 100644 --- a/examples/eks/v1beta1/accessentry.yaml +++ b/examples/eks/v1beta1/accessentry.yaml @@ -22,7 +22,6 @@ spec: name: custom-role region: us-east-2 type: STANDARD - --- apiVersion: eks.aws.upbound.io/v1beta1 kind: AccessPolicyAssociation @@ -44,8 +43,6 @@ spec: policyArn: "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy" accessScope: type: cluster - - --- apiVersion: iam.aws.upbound.io/v1beta1 kind: Role @@ -68,7 +65,6 @@ spec: } ] } - --- apiVersion: eks.aws.upbound.io/v1beta1 kind: Cluster @@ -91,9 +87,7 @@ spec: - subnetIdRefs: - name: sample-subnet1 - name: sample-subnet2 - --- - apiVersion: iam.aws.upbound.io/v1beta1 kind: Role metadata: @@ -116,7 +110,6 @@ spec: ] } --- - apiVersion: iam.aws.upbound.io/v1beta1 kind: RolePolicyAttachment metadata: @@ -128,9 +121,7 @@ spec: policyArn: arn:aws:iam::aws:policy/AmazonEKSClusterPolicy roleRef: name: access-entry-eks-cluster - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: Subnet metadata: @@ -145,9 +136,7 @@ spec: vpcIdRef: name: sample-vpc cidrBlock: 172.16.10.0/24 - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: Subnet metadata: @@ -162,9 +151,7 @@ spec: vpcIdRef: name: sample-vpc cidrBlock: 172.16.11.0/24 - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: Subnet metadata: @@ -178,9 +165,7 @@ spec: vpcIdRef: name: sample-vpc cidrBlock: 172.16.12.0/24 - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: RouteTable metadata: @@ -194,9 +179,7 @@ spec: Name: example vpcIdRef: name: sample-vpc - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: RouteTableAssociation metadata: @@ -210,9 +193,7 @@ spec: name: example subnetIdRef: name: private-subnet - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: VPC metadata: @@ -226,9 +207,7 @@ spec: cidrBlock: 172.16.0.0/16 tags: Name: DemoVpc - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: InternetGateway metadata: @@ -240,9 +219,7 @@ spec: region: us-east-2 vpcIdRef: name: sample-vpc - --- - apiVersion: ec2.aws.upbound.io/v1beta1 kind: DefaultRouteTable metadata: