Skip to content

Commit

Permalink
Change external name configurations for the AccessPolicyAssociation a…
Browse files Browse the repository at this point in the history
…nd AccessEntry resources

Signed-off-by: Fatih Türken <[email protected]>
  • Loading branch information
turkenf committed Aug 8, 2024
1 parent ca8d73c commit 0d8e1c4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
23 changes: 2 additions & 21 deletions config/externalname.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
23 changes: 0 additions & 23 deletions examples/eks/v1beta1/accessentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ spec:
name: custom-role
region: us-east-2
type: STANDARD

---
apiVersion: eks.aws.upbound.io/v1beta1
kind: AccessPolicyAssociation
Expand All @@ -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
Expand All @@ -68,7 +65,6 @@ spec:
}
]
}
---
apiVersion: eks.aws.upbound.io/v1beta1
kind: Cluster
Expand All @@ -91,9 +87,7 @@ spec:
- subnetIdRefs:
- name: sample-subnet1
- name: sample-subnet2

---

apiVersion: iam.aws.upbound.io/v1beta1
kind: Role
metadata:
Expand All @@ -116,7 +110,6 @@ spec:
]
}
---

apiVersion: iam.aws.upbound.io/v1beta1
kind: RolePolicyAttachment
metadata:
Expand All @@ -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:
Expand All @@ -145,9 +136,7 @@ spec:
vpcIdRef:
name: sample-vpc
cidrBlock: 172.16.10.0/24

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: Subnet
metadata:
Expand All @@ -162,9 +151,7 @@ spec:
vpcIdRef:
name: sample-vpc
cidrBlock: 172.16.11.0/24

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: Subnet
metadata:
Expand All @@ -178,9 +165,7 @@ spec:
vpcIdRef:
name: sample-vpc
cidrBlock: 172.16.12.0/24

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: RouteTable
metadata:
Expand All @@ -194,9 +179,7 @@ spec:
Name: example
vpcIdRef:
name: sample-vpc

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: RouteTableAssociation
metadata:
Expand All @@ -210,9 +193,7 @@ spec:
name: example
subnetIdRef:
name: private-subnet

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: VPC
metadata:
Expand All @@ -226,9 +207,7 @@ spec:
cidrBlock: 172.16.0.0/16
tags:
Name: DemoVpc

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: InternetGateway
metadata:
Expand All @@ -240,9 +219,7 @@ spec:
region: us-east-2
vpcIdRef:
name: sample-vpc

---

apiVersion: ec2.aws.upbound.io/v1beta1
kind: DefaultRouteTable
metadata:
Expand Down

0 comments on commit 0d8e1c4

Please sign in to comment.