Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_eks_identity_provider_config - Adds a new resource for EKS OIDC Identity Provider Config #17959

Merged
merged 16 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17959.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_eks_identity_provider_config
```
4 changes: 4 additions & 0 deletions aws/internal/service/eks/enum.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package eks

const (
IdentityProviderConfigTypeOidc = "oidc"
)

const (
ResourcesSecrets = "secrets"
)
Expand Down
33 changes: 33 additions & 0 deletions aws/internal/service/eks/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/service/eks"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tfeks "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/eks"
)

func AddonByClusterNameAndAddonName(ctx context.Context, conn *eks.EKS, clusterName, addonName string) (*eks.Addon, error) {
Expand Down Expand Up @@ -214,3 +215,35 @@ func NodegroupUpdateByClusterNameNodegroupNameAndID(conn *eks.EKS, clusterName,

return output.Update, nil
}

func OidcIdentityProviderConfigByClusterNameAndConfigName(ctx context.Context, conn *eks.EKS, clusterName, configName string) (*eks.OidcIdentityProviderConfig, error) {
input := &eks.DescribeIdentityProviderConfigInput{
ClusterName: aws.String(clusterName),
IdentityProviderConfig: &eks.IdentityProviderConfig{
Name: aws.String(configName),
Type: aws.String(tfeks.IdentityProviderConfigTypeOidc),
},
}

output, err := conn.DescribeIdentityProviderConfigWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, eks.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.IdentityProviderConfig == nil || output.IdentityProviderConfig.Oidc == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output.IdentityProviderConfig.Oidc, nil
}
19 changes: 19 additions & 0 deletions aws/internal/service/eks/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ func FargateProfileParseResourceID(id string) (string, string, error) {
return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected cluster-name%[2]sfargate-profile-name", id, fargateProfileResourceIDSeparator)
}

const identityProviderConfigResourceIDSeparator = ":"

func IdentityProviderConfigCreateResourceID(clusterName, configName string) string {
parts := []string{clusterName, configName}
id := strings.Join(parts, identityProviderConfigResourceIDSeparator)

return id
}

func IdentityProviderConfigParseResourceID(id string) (string, string, error) {
parts := strings.Split(id, identityProviderConfigResourceIDSeparator)

if len(parts) == 2 && parts[0] != "" && parts[1] != "" {
return parts[0], parts[1], nil
}

return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected cluster-name%[2]sconfig-name", id, identityProviderConfigResourceIDSeparator)
}

const nodeGroupResourceIDSeparator = ":"

func NodeGroupCreateResourceID(clusterName, nodeGroupName string) string {
Expand Down
16 changes: 16 additions & 0 deletions aws/internal/service/eks/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@ func NodegroupUpdateStatus(conn *eks.EKS, clusterName, nodeGroupName, id string)
return output, aws.StringValue(output.Status), nil
}
}

func OidcIdentityProviderConfigStatus(ctx context.Context, conn *eks.EKS, clusterName, configName string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.OidcIdentityProviderConfigByClusterNameAndConfigName(ctx, conn, clusterName, configName)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, aws.StringValue(output.Status), nil
}
}
34 changes: 34 additions & 0 deletions aws/internal/service/eks/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,37 @@ func NodegroupUpdateSuccessful(conn *eks.EKS, clusterName, nodeGroupName, id str

return nil, err
}

func OidcIdentityProviderConfigCreated(ctx context.Context, conn *eks.EKS, clusterName, configName string, timeout time.Duration) (*eks.OidcIdentityProviderConfig, error) {
stateConf := resource.StateChangeConf{
Pending: []string{eks.ConfigStatusCreating},
Target: []string{eks.ConfigStatusActive},
Refresh: OidcIdentityProviderConfigStatus(ctx, conn, clusterName, configName),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*eks.OidcIdentityProviderConfig); ok {
return output, err
}

return nil, err
}

func OidcIdentityProviderConfigDeleted(ctx context.Context, conn *eks.EKS, clusterName, configName string, timeout time.Duration) (*eks.OidcIdentityProviderConfig, error) {
stateConf := resource.StateChangeConf{
Pending: []string{eks.ConfigStatusActive, eks.ConfigStatusDeleting},
Target: []string{},
Refresh: OidcIdentityProviderConfigStatus(ctx, conn, clusterName, configName),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*eks.OidcIdentityProviderConfig); ok {
return output, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func Provider() *schema.Provider {
"aws_eks_cluster": resourceAwsEksCluster(),
"aws_eks_addon": resourceAwsEksAddon(),
"aws_eks_fargate_profile": resourceAwsEksFargateProfile(),
"aws_eks_identity_provider_config": resourceAwsEksIdentityProviderConfig(),
"aws_eks_node_group": resourceAwsEksNodeGroup(),
"aws_elasticache_cluster": resourceAwsElasticacheCluster(),
"aws_elasticache_global_replication_group": resourceAwsElasticacheGlobalReplicationGroup(),
Expand Down
Loading