From e3e8e75b5fffcc7281b4c61934d806ad9ef55b92 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 26 Nov 2023 22:57:33 +0100 Subject: [PATCH 01/12] chore: set controltower service to aws-sdk-go-v2 and run `make gen` --- go.mod | 1 + go.sum | 2 + internal/conns/awsclient_gen.go | 6 +- internal/provider/service_packages_gen.go | 415 +----------------- .../controltower/service_package_gen.go | 17 +- names/names.go | 1 + names/names_data.csv | 2 +- 7 files changed, 19 insertions(+), 425 deletions(-) diff --git a/go.mod b/go.mod index dd4ca607f7e..e6b349e1c89 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/comprehend v1.28.2 github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4 github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3 + github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2 github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3 github.com/aws/aws-sdk-go-v2/service/directoryservice v1.21.3 github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.5.3 diff --git a/go.sum b/go.sum index 3400309ca5e..7c8d40ecd1e 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4 h1:s7jPagjsA1DyZYu github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4/go.mod h1:z2ipEqlHBaieu+POGuEptwkKOBhumxLZjeO7iAJqjuk= github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3 h1:ONDuYy0oFEwNvmO3kBu3JLYp9BJsxVZCLv0+L5fIArA= github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3/go.mod h1:K//ScfyKrxpEpC5VSZesWjdYtdJXCj8sCau9iSsYdMk= +github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2 h1:yHEn7sEB3i9eqqlZPcrjwWRiMiRw9TwEzHxNJTjW+OQ= +github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2/go.mod h1:mir55k6nOvOHhHj93umjlFnlODrfOAt2hA3CX8a6+8Y= github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3 h1:GXyai+Ti0BoxNfMotRFDYywCGlTV5IzXMGyG4RV6oq4= github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3/go.mod h1:ALbeVeoYNXakmRHRZBIpAVRXXlesm6v5jH1037hVkac= github.com/aws/aws-sdk-go-v2/service/directoryservice v1.21.3 h1:/cMlzdpSJjjwUzBDuIeazKQtYB2VDOqCSV3zq1sDpzg= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index e661b0b4a91..602ae8f2cd1 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -25,6 +25,7 @@ import ( comprehend_sdkv2 "github.com/aws/aws-sdk-go-v2/service/comprehend" computeoptimizer_sdkv2 "github.com/aws/aws-sdk-go-v2/service/computeoptimizer" connectcases_sdkv2 "github.com/aws/aws-sdk-go-v2/service/connectcases" + controltower_sdkv2 "github.com/aws/aws-sdk-go-v2/service/controltower" customerprofiles_sdkv2 "github.com/aws/aws-sdk-go-v2/service/customerprofiles" directoryservice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/directoryservice" docdbelastic_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdbelastic" @@ -118,7 +119,6 @@ import ( cognitoidentityprovider_sdkv1 "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" configservice_sdkv1 "github.com/aws/aws-sdk-go/service/configservice" connect_sdkv1 "github.com/aws/aws-sdk-go/service/connect" - controltower_sdkv1 "github.com/aws/aws-sdk-go/service/controltower" costandusagereportservice_sdkv1 "github.com/aws/aws-sdk-go/service/costandusagereportservice" costexplorer_sdkv1 "github.com/aws/aws-sdk-go/service/costexplorer" databasemigrationservice_sdkv1 "github.com/aws/aws-sdk-go/service/databasemigrationservice" @@ -446,8 +446,8 @@ func (c *AWSClient) ConnectCasesClient(ctx context.Context) *connectcases_sdkv2. return errs.Must(client[*connectcases_sdkv2.Client](ctx, c, names.ConnectCases)) } -func (c *AWSClient) ControlTowerConn(ctx context.Context) *controltower_sdkv1.ControlTower { - return errs.Must(conn[*controltower_sdkv1.ControlTower](ctx, c, names.ControlTower)) +func (c *AWSClient) ControlTowerClient(ctx context.Context) *controltower_sdkv2.Client { + return errs.Must(client[*controltower_sdkv2.Client](ctx, c, names.ControlTower)) } func (c *AWSClient) CustomerProfilesClient(ctx context.Context) *customerprofiles_sdkv2.Client { diff --git a/internal/provider/service_packages_gen.go b/internal/provider/service_packages_gen.go index 93f1982554d..17d80912c85 100644 --- a/internal/provider/service_packages_gen.go +++ b/internal/provider/service_packages_gen.go @@ -6,424 +6,11 @@ import ( "context" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/service/accessanalyzer" - "github.com/hashicorp/terraform-provider-aws/internal/service/account" - "github.com/hashicorp/terraform-provider-aws/internal/service/acm" - "github.com/hashicorp/terraform-provider-aws/internal/service/acmpca" - "github.com/hashicorp/terraform-provider-aws/internal/service/amp" - "github.com/hashicorp/terraform-provider-aws/internal/service/amplify" - "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" - "github.com/hashicorp/terraform-provider-aws/internal/service/apigatewayv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling" - "github.com/hashicorp/terraform-provider-aws/internal/service/appconfig" - "github.com/hashicorp/terraform-provider-aws/internal/service/appflow" - "github.com/hashicorp/terraform-provider-aws/internal/service/appintegrations" - "github.com/hashicorp/terraform-provider-aws/internal/service/applicationinsights" - "github.com/hashicorp/terraform-provider-aws/internal/service/appmesh" - "github.com/hashicorp/terraform-provider-aws/internal/service/apprunner" - "github.com/hashicorp/terraform-provider-aws/internal/service/appstream" - "github.com/hashicorp/terraform-provider-aws/internal/service/appsync" - "github.com/hashicorp/terraform-provider-aws/internal/service/athena" - "github.com/hashicorp/terraform-provider-aws/internal/service/auditmanager" - "github.com/hashicorp/terraform-provider-aws/internal/service/autoscaling" - "github.com/hashicorp/terraform-provider-aws/internal/service/autoscalingplans" - "github.com/hashicorp/terraform-provider-aws/internal/service/backup" - "github.com/hashicorp/terraform-provider-aws/internal/service/batch" - "github.com/hashicorp/terraform-provider-aws/internal/service/bedrock" - "github.com/hashicorp/terraform-provider-aws/internal/service/budgets" - "github.com/hashicorp/terraform-provider-aws/internal/service/ce" - "github.com/hashicorp/terraform-provider-aws/internal/service/chime" - "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkmediapipelines" - "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkvoice" - "github.com/hashicorp/terraform-provider-aws/internal/service/cleanrooms" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloud9" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudcontrol" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudformation" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudfront" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudhsmv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudtrail" - "github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch" - "github.com/hashicorp/terraform-provider-aws/internal/service/codeartifact" - "github.com/hashicorp/terraform-provider-aws/internal/service/codebuild" - "github.com/hashicorp/terraform-provider-aws/internal/service/codecatalyst" - "github.com/hashicorp/terraform-provider-aws/internal/service/codecommit" - "github.com/hashicorp/terraform-provider-aws/internal/service/codegurureviewer" - "github.com/hashicorp/terraform-provider-aws/internal/service/codepipeline" - "github.com/hashicorp/terraform-provider-aws/internal/service/codestarconnections" - "github.com/hashicorp/terraform-provider-aws/internal/service/codestarnotifications" - "github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidentity" - "github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp" - "github.com/hashicorp/terraform-provider-aws/internal/service/comprehend" - "github.com/hashicorp/terraform-provider-aws/internal/service/computeoptimizer" - "github.com/hashicorp/terraform-provider-aws/internal/service/configservice" - "github.com/hashicorp/terraform-provider-aws/internal/service/connect" - "github.com/hashicorp/terraform-provider-aws/internal/service/controltower" - "github.com/hashicorp/terraform-provider-aws/internal/service/cur" - "github.com/hashicorp/terraform-provider-aws/internal/service/dataexchange" - "github.com/hashicorp/terraform-provider-aws/internal/service/datapipeline" - "github.com/hashicorp/terraform-provider-aws/internal/service/datasync" - "github.com/hashicorp/terraform-provider-aws/internal/service/dax" - "github.com/hashicorp/terraform-provider-aws/internal/service/deploy" - "github.com/hashicorp/terraform-provider-aws/internal/service/detective" - "github.com/hashicorp/terraform-provider-aws/internal/service/devicefarm" - "github.com/hashicorp/terraform-provider-aws/internal/service/directconnect" - "github.com/hashicorp/terraform-provider-aws/internal/service/dlm" - "github.com/hashicorp/terraform-provider-aws/internal/service/dms" - "github.com/hashicorp/terraform-provider-aws/internal/service/docdb" - "github.com/hashicorp/terraform-provider-aws/internal/service/docdbelastic" - "github.com/hashicorp/terraform-provider-aws/internal/service/ds" - "github.com/hashicorp/terraform-provider-aws/internal/service/dynamodb" - "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" - "github.com/hashicorp/terraform-provider-aws/internal/service/ecr" - "github.com/hashicorp/terraform-provider-aws/internal/service/ecrpublic" - "github.com/hashicorp/terraform-provider-aws/internal/service/ecs" - "github.com/hashicorp/terraform-provider-aws/internal/service/efs" - "github.com/hashicorp/terraform-provider-aws/internal/service/eks" - "github.com/hashicorp/terraform-provider-aws/internal/service/elasticache" - "github.com/hashicorp/terraform-provider-aws/internal/service/elasticbeanstalk" - "github.com/hashicorp/terraform-provider-aws/internal/service/elasticsearch" - "github.com/hashicorp/terraform-provider-aws/internal/service/elastictranscoder" - "github.com/hashicorp/terraform-provider-aws/internal/service/elb" - "github.com/hashicorp/terraform-provider-aws/internal/service/elbv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/emr" - "github.com/hashicorp/terraform-provider-aws/internal/service/emrcontainers" - "github.com/hashicorp/terraform-provider-aws/internal/service/emrserverless" - "github.com/hashicorp/terraform-provider-aws/internal/service/events" - "github.com/hashicorp/terraform-provider-aws/internal/service/evidently" - "github.com/hashicorp/terraform-provider-aws/internal/service/finspace" - "github.com/hashicorp/terraform-provider-aws/internal/service/firehose" - "github.com/hashicorp/terraform-provider-aws/internal/service/fis" - "github.com/hashicorp/terraform-provider-aws/internal/service/fms" - "github.com/hashicorp/terraform-provider-aws/internal/service/fsx" - "github.com/hashicorp/terraform-provider-aws/internal/service/gamelift" - "github.com/hashicorp/terraform-provider-aws/internal/service/glacier" - "github.com/hashicorp/terraform-provider-aws/internal/service/globalaccelerator" - "github.com/hashicorp/terraform-provider-aws/internal/service/glue" - "github.com/hashicorp/terraform-provider-aws/internal/service/grafana" - "github.com/hashicorp/terraform-provider-aws/internal/service/greengrass" - "github.com/hashicorp/terraform-provider-aws/internal/service/guardduty" - "github.com/hashicorp/terraform-provider-aws/internal/service/healthlake" - "github.com/hashicorp/terraform-provider-aws/internal/service/iam" - "github.com/hashicorp/terraform-provider-aws/internal/service/identitystore" - "github.com/hashicorp/terraform-provider-aws/internal/service/imagebuilder" - "github.com/hashicorp/terraform-provider-aws/internal/service/inspector" - "github.com/hashicorp/terraform-provider-aws/internal/service/inspector2" - "github.com/hashicorp/terraform-provider-aws/internal/service/internetmonitor" - "github.com/hashicorp/terraform-provider-aws/internal/service/iot" - "github.com/hashicorp/terraform-provider-aws/internal/service/iotanalytics" - "github.com/hashicorp/terraform-provider-aws/internal/service/iotevents" - "github.com/hashicorp/terraform-provider-aws/internal/service/ivs" - "github.com/hashicorp/terraform-provider-aws/internal/service/ivschat" - "github.com/hashicorp/terraform-provider-aws/internal/service/kafka" - "github.com/hashicorp/terraform-provider-aws/internal/service/kafkaconnect" - "github.com/hashicorp/terraform-provider-aws/internal/service/kendra" - "github.com/hashicorp/terraform-provider-aws/internal/service/keyspaces" - "github.com/hashicorp/terraform-provider-aws/internal/service/kinesis" - "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisanalytics" - "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisanalyticsv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisvideo" - "github.com/hashicorp/terraform-provider-aws/internal/service/kms" - "github.com/hashicorp/terraform-provider-aws/internal/service/lakeformation" - "github.com/hashicorp/terraform-provider-aws/internal/service/lambda" - "github.com/hashicorp/terraform-provider-aws/internal/service/lexmodels" - "github.com/hashicorp/terraform-provider-aws/internal/service/lexv2models" - "github.com/hashicorp/terraform-provider-aws/internal/service/licensemanager" - "github.com/hashicorp/terraform-provider-aws/internal/service/lightsail" - "github.com/hashicorp/terraform-provider-aws/internal/service/location" - "github.com/hashicorp/terraform-provider-aws/internal/service/logs" - "github.com/hashicorp/terraform-provider-aws/internal/service/macie2" - "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconnect" - "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert" - "github.com/hashicorp/terraform-provider-aws/internal/service/medialive" - "github.com/hashicorp/terraform-provider-aws/internal/service/mediapackage" - "github.com/hashicorp/terraform-provider-aws/internal/service/mediastore" - "github.com/hashicorp/terraform-provider-aws/internal/service/memorydb" - "github.com/hashicorp/terraform-provider-aws/internal/service/meta" - "github.com/hashicorp/terraform-provider-aws/internal/service/mq" - "github.com/hashicorp/terraform-provider-aws/internal/service/mwaa" - "github.com/hashicorp/terraform-provider-aws/internal/service/neptune" - "github.com/hashicorp/terraform-provider-aws/internal/service/networkfirewall" - "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" - "github.com/hashicorp/terraform-provider-aws/internal/service/oam" - "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" - "github.com/hashicorp/terraform-provider-aws/internal/service/opensearchserverless" - "github.com/hashicorp/terraform-provider-aws/internal/service/opsworks" - "github.com/hashicorp/terraform-provider-aws/internal/service/organizations" - "github.com/hashicorp/terraform-provider-aws/internal/service/outposts" - "github.com/hashicorp/terraform-provider-aws/internal/service/pinpoint" - "github.com/hashicorp/terraform-provider-aws/internal/service/pipes" - "github.com/hashicorp/terraform-provider-aws/internal/service/pricing" - "github.com/hashicorp/terraform-provider-aws/internal/service/qldb" - "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight" - "github.com/hashicorp/terraform-provider-aws/internal/service/ram" - "github.com/hashicorp/terraform-provider-aws/internal/service/rbin" - "github.com/hashicorp/terraform-provider-aws/internal/service/rds" - "github.com/hashicorp/terraform-provider-aws/internal/service/redshift" - "github.com/hashicorp/terraform-provider-aws/internal/service/redshiftdata" - "github.com/hashicorp/terraform-provider-aws/internal/service/redshiftserverless" - "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2" - "github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups" - "github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroupstaggingapi" - "github.com/hashicorp/terraform-provider-aws/internal/service/rolesanywhere" - "github.com/hashicorp/terraform-provider-aws/internal/service/route53" - "github.com/hashicorp/terraform-provider-aws/internal/service/route53domains" - "github.com/hashicorp/terraform-provider-aws/internal/service/route53recoverycontrolconfig" - "github.com/hashicorp/terraform-provider-aws/internal/service/route53recoveryreadiness" - "github.com/hashicorp/terraform-provider-aws/internal/service/route53resolver" - "github.com/hashicorp/terraform-provider-aws/internal/service/rum" - "github.com/hashicorp/terraform-provider-aws/internal/service/s3" - "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" - "github.com/hashicorp/terraform-provider-aws/internal/service/s3outposts" - "github.com/hashicorp/terraform-provider-aws/internal/service/sagemaker" - "github.com/hashicorp/terraform-provider-aws/internal/service/scheduler" - "github.com/hashicorp/terraform-provider-aws/internal/service/schemas" - "github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager" - "github.com/hashicorp/terraform-provider-aws/internal/service/securityhub" - "github.com/hashicorp/terraform-provider-aws/internal/service/securitylake" - "github.com/hashicorp/terraform-provider-aws/internal/service/serverlessrepo" - "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalog" - "github.com/hashicorp/terraform-provider-aws/internal/service/servicediscovery" - "github.com/hashicorp/terraform-provider-aws/internal/service/servicequotas" - "github.com/hashicorp/terraform-provider-aws/internal/service/ses" - "github.com/hashicorp/terraform-provider-aws/internal/service/sesv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/sfn" - "github.com/hashicorp/terraform-provider-aws/internal/service/shield" - "github.com/hashicorp/terraform-provider-aws/internal/service/signer" - "github.com/hashicorp/terraform-provider-aws/internal/service/simpledb" - "github.com/hashicorp/terraform-provider-aws/internal/service/sns" - "github.com/hashicorp/terraform-provider-aws/internal/service/sqs" - "github.com/hashicorp/terraform-provider-aws/internal/service/ssm" - "github.com/hashicorp/terraform-provider-aws/internal/service/ssmcontacts" - "github.com/hashicorp/terraform-provider-aws/internal/service/ssmincidents" - "github.com/hashicorp/terraform-provider-aws/internal/service/ssoadmin" - "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" - "github.com/hashicorp/terraform-provider-aws/internal/service/sts" - "github.com/hashicorp/terraform-provider-aws/internal/service/swf" - "github.com/hashicorp/terraform-provider-aws/internal/service/synthetics" - "github.com/hashicorp/terraform-provider-aws/internal/service/timestreamwrite" - "github.com/hashicorp/terraform-provider-aws/internal/service/transcribe" - "github.com/hashicorp/terraform-provider-aws/internal/service/transfer" - "github.com/hashicorp/terraform-provider-aws/internal/service/verifiedpermissions" - "github.com/hashicorp/terraform-provider-aws/internal/service/vpclattice" - "github.com/hashicorp/terraform-provider-aws/internal/service/waf" - "github.com/hashicorp/terraform-provider-aws/internal/service/wafregional" - "github.com/hashicorp/terraform-provider-aws/internal/service/wafv2" - "github.com/hashicorp/terraform-provider-aws/internal/service/worklink" - "github.com/hashicorp/terraform-provider-aws/internal/service/workspaces" - "github.com/hashicorp/terraform-provider-aws/internal/service/xray" "golang.org/x/exp/slices" ) func servicePackages(ctx context.Context) []conns.ServicePackage { - v := []conns.ServicePackage{ - accessanalyzer.ServicePackage(ctx), - account.ServicePackage(ctx), - acm.ServicePackage(ctx), - acmpca.ServicePackage(ctx), - amp.ServicePackage(ctx), - amplify.ServicePackage(ctx), - apigateway.ServicePackage(ctx), - apigatewayv2.ServicePackage(ctx), - appautoscaling.ServicePackage(ctx), - appconfig.ServicePackage(ctx), - appflow.ServicePackage(ctx), - appintegrations.ServicePackage(ctx), - applicationinsights.ServicePackage(ctx), - appmesh.ServicePackage(ctx), - apprunner.ServicePackage(ctx), - appstream.ServicePackage(ctx), - appsync.ServicePackage(ctx), - athena.ServicePackage(ctx), - auditmanager.ServicePackage(ctx), - autoscaling.ServicePackage(ctx), - autoscalingplans.ServicePackage(ctx), - backup.ServicePackage(ctx), - batch.ServicePackage(ctx), - bedrock.ServicePackage(ctx), - budgets.ServicePackage(ctx), - ce.ServicePackage(ctx), - chime.ServicePackage(ctx), - chimesdkmediapipelines.ServicePackage(ctx), - chimesdkvoice.ServicePackage(ctx), - cleanrooms.ServicePackage(ctx), - cloud9.ServicePackage(ctx), - cloudcontrol.ServicePackage(ctx), - cloudformation.ServicePackage(ctx), - cloudfront.ServicePackage(ctx), - cloudhsmv2.ServicePackage(ctx), - cloudsearch.ServicePackage(ctx), - cloudtrail.ServicePackage(ctx), - cloudwatch.ServicePackage(ctx), - codeartifact.ServicePackage(ctx), - codebuild.ServicePackage(ctx), - codecatalyst.ServicePackage(ctx), - codecommit.ServicePackage(ctx), - codegurureviewer.ServicePackage(ctx), - codepipeline.ServicePackage(ctx), - codestarconnections.ServicePackage(ctx), - codestarnotifications.ServicePackage(ctx), - cognitoidentity.ServicePackage(ctx), - cognitoidp.ServicePackage(ctx), - comprehend.ServicePackage(ctx), - computeoptimizer.ServicePackage(ctx), - configservice.ServicePackage(ctx), - connect.ServicePackage(ctx), - controltower.ServicePackage(ctx), - cur.ServicePackage(ctx), - dataexchange.ServicePackage(ctx), - datapipeline.ServicePackage(ctx), - datasync.ServicePackage(ctx), - dax.ServicePackage(ctx), - deploy.ServicePackage(ctx), - detective.ServicePackage(ctx), - devicefarm.ServicePackage(ctx), - directconnect.ServicePackage(ctx), - dlm.ServicePackage(ctx), - dms.ServicePackage(ctx), - docdb.ServicePackage(ctx), - docdbelastic.ServicePackage(ctx), - ds.ServicePackage(ctx), - dynamodb.ServicePackage(ctx), - ec2.ServicePackage(ctx), - ecr.ServicePackage(ctx), - ecrpublic.ServicePackage(ctx), - ecs.ServicePackage(ctx), - efs.ServicePackage(ctx), - eks.ServicePackage(ctx), - elasticache.ServicePackage(ctx), - elasticbeanstalk.ServicePackage(ctx), - elasticsearch.ServicePackage(ctx), - elastictranscoder.ServicePackage(ctx), - elb.ServicePackage(ctx), - elbv2.ServicePackage(ctx), - emr.ServicePackage(ctx), - emrcontainers.ServicePackage(ctx), - emrserverless.ServicePackage(ctx), - events.ServicePackage(ctx), - evidently.ServicePackage(ctx), - finspace.ServicePackage(ctx), - firehose.ServicePackage(ctx), - fis.ServicePackage(ctx), - fms.ServicePackage(ctx), - fsx.ServicePackage(ctx), - gamelift.ServicePackage(ctx), - glacier.ServicePackage(ctx), - globalaccelerator.ServicePackage(ctx), - glue.ServicePackage(ctx), - grafana.ServicePackage(ctx), - greengrass.ServicePackage(ctx), - guardduty.ServicePackage(ctx), - healthlake.ServicePackage(ctx), - iam.ServicePackage(ctx), - identitystore.ServicePackage(ctx), - imagebuilder.ServicePackage(ctx), - inspector.ServicePackage(ctx), - inspector2.ServicePackage(ctx), - internetmonitor.ServicePackage(ctx), - iot.ServicePackage(ctx), - iotanalytics.ServicePackage(ctx), - iotevents.ServicePackage(ctx), - ivs.ServicePackage(ctx), - ivschat.ServicePackage(ctx), - kafka.ServicePackage(ctx), - kafkaconnect.ServicePackage(ctx), - kendra.ServicePackage(ctx), - keyspaces.ServicePackage(ctx), - kinesis.ServicePackage(ctx), - kinesisanalytics.ServicePackage(ctx), - kinesisanalyticsv2.ServicePackage(ctx), - kinesisvideo.ServicePackage(ctx), - kms.ServicePackage(ctx), - lakeformation.ServicePackage(ctx), - lambda.ServicePackage(ctx), - lexmodels.ServicePackage(ctx), - lexv2models.ServicePackage(ctx), - licensemanager.ServicePackage(ctx), - lightsail.ServicePackage(ctx), - location.ServicePackage(ctx), - logs.ServicePackage(ctx), - macie2.ServicePackage(ctx), - mediaconnect.ServicePackage(ctx), - mediaconvert.ServicePackage(ctx), - medialive.ServicePackage(ctx), - mediapackage.ServicePackage(ctx), - mediastore.ServicePackage(ctx), - memorydb.ServicePackage(ctx), - meta.ServicePackage(ctx), - mq.ServicePackage(ctx), - mwaa.ServicePackage(ctx), - neptune.ServicePackage(ctx), - networkfirewall.ServicePackage(ctx), - networkmanager.ServicePackage(ctx), - oam.ServicePackage(ctx), - opensearch.ServicePackage(ctx), - opensearchserverless.ServicePackage(ctx), - opsworks.ServicePackage(ctx), - organizations.ServicePackage(ctx), - outposts.ServicePackage(ctx), - pinpoint.ServicePackage(ctx), - pipes.ServicePackage(ctx), - pricing.ServicePackage(ctx), - qldb.ServicePackage(ctx), - quicksight.ServicePackage(ctx), - ram.ServicePackage(ctx), - rbin.ServicePackage(ctx), - rds.ServicePackage(ctx), - redshift.ServicePackage(ctx), - redshiftdata.ServicePackage(ctx), - redshiftserverless.ServicePackage(ctx), - resourceexplorer2.ServicePackage(ctx), - resourcegroups.ServicePackage(ctx), - resourcegroupstaggingapi.ServicePackage(ctx), - rolesanywhere.ServicePackage(ctx), - route53.ServicePackage(ctx), - route53domains.ServicePackage(ctx), - route53recoverycontrolconfig.ServicePackage(ctx), - route53recoveryreadiness.ServicePackage(ctx), - route53resolver.ServicePackage(ctx), - rum.ServicePackage(ctx), - s3.ServicePackage(ctx), - s3control.ServicePackage(ctx), - s3outposts.ServicePackage(ctx), - sagemaker.ServicePackage(ctx), - scheduler.ServicePackage(ctx), - schemas.ServicePackage(ctx), - secretsmanager.ServicePackage(ctx), - securityhub.ServicePackage(ctx), - securitylake.ServicePackage(ctx), - serverlessrepo.ServicePackage(ctx), - servicecatalog.ServicePackage(ctx), - servicediscovery.ServicePackage(ctx), - servicequotas.ServicePackage(ctx), - ses.ServicePackage(ctx), - sesv2.ServicePackage(ctx), - sfn.ServicePackage(ctx), - shield.ServicePackage(ctx), - signer.ServicePackage(ctx), - simpledb.ServicePackage(ctx), - sns.ServicePackage(ctx), - sqs.ServicePackage(ctx), - ssm.ServicePackage(ctx), - ssmcontacts.ServicePackage(ctx), - ssmincidents.ServicePackage(ctx), - ssoadmin.ServicePackage(ctx), - storagegateway.ServicePackage(ctx), - sts.ServicePackage(ctx), - swf.ServicePackage(ctx), - synthetics.ServicePackage(ctx), - timestreamwrite.ServicePackage(ctx), - transcribe.ServicePackage(ctx), - transfer.ServicePackage(ctx), - verifiedpermissions.ServicePackage(ctx), - vpclattice.ServicePackage(ctx), - waf.ServicePackage(ctx), - wafregional.ServicePackage(ctx), - wafv2.ServicePackage(ctx), - worklink.ServicePackage(ctx), - workspaces.ServicePackage(ctx), - xray.ServicePackage(ctx), - } + v := []conns.ServicePackage{} return slices.Clone(v) } diff --git a/internal/service/controltower/service_package_gen.go b/internal/service/controltower/service_package_gen.go index 02e9a984e42..b208587f2da 100644 --- a/internal/service/controltower/service_package_gen.go +++ b/internal/service/controltower/service_package_gen.go @@ -5,9 +5,8 @@ package controltower import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - controltower_sdkv1 "github.com/aws/aws-sdk-go/service/controltower" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + controltower_sdkv2 "github.com/aws/aws-sdk-go-v2/service/controltower" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -45,11 +44,15 @@ func (p *servicePackage) ServicePackageName() string { return names.ControlTower } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*controltower_sdkv1.ControlTower, error) { - sess := config["session"].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*controltower_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return controltower_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return controltower_sdkv2.NewFromConfig(cfg, func(o *controltower_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/names/names.go b/names/names.go index 81352a1017b..5f90413c379 100644 --- a/names/names.go +++ b/names/names.go @@ -44,6 +44,7 @@ const ( CodeStarNotificationsEndpointID = "codestar-notifications" ComprehendEndpointID = "comprehend" ComputeOptimizerEndpointID = "computeoptimizer" + ControlTowerEndpointID = "controltower" DSEndpointID = "ds" EKSEndpointID = "eks" EMREndpointID = "elasticmapreduce" diff --git a/names/names_data.csv b/names/names_data.csv index 5d42c6ca4d5..16475550ef7 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -98,7 +98,7 @@ connectparticipant,connectparticipant,connectparticipant,connectparticipant,,con voice-id,voiceid,voiceid,voiceid,,voiceid,,,VoiceID,VoiceID,,1,,,aws_voiceid_,,voiceid_,Connect Voice ID,Amazon,,x,,,,, wisdom,wisdom,connectwisdomservice,wisdom,,wisdom,,connectwisdomservice,Wisdom,ConnectWisdomService,,1,,,aws_wisdom_,,wisdom_,Connect Wisdom,Amazon,,x,,,,, ,,,,,,,,,,,,,,,,,Console Mobile Application,AWS,x,,,,,,No SDK support -controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,1,,,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, +controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,,2,aws_controltower_,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, cur,cur,costandusagereportservice,costandusagereportservice,,cur,,costandusagereportservice,CUR,CostandUsageReportService,,1,,,aws_cur_,,cur_,Cost and Usage Report,AWS,,,,,,, ,,,,,,,,,,,,,,,,,Crypto Tools,AWS,x,,,,,,No SDK support ,,,,,,,,,,,,,,,,,Cryptographic Services Overview,AWS,x,,,,,,No SDK support From f5c3f5adbd336604f4afd022b45ab47331210605 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 26 Nov 2023 23:11:06 +0100 Subject: [PATCH 02/12] chore: port `internal/service/controltower/control_test.go` to `aws-sdk-go-v2` --- internal/service/controltower/control_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/service/controltower/control_test.go b/internal/service/controltower/control_test.go index 0ac8c1fcde3..c37a04e9079 100644 --- a/internal/service/controltower/control_test.go +++ b/internal/service/controltower/control_test.go @@ -8,13 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/controltower" + types "github.com/aws/aws-sdk-go-v2/service/controltower/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfcontroltower "github.com/hashicorp/terraform-provider-aws/internal/service/controltower" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccControlTowerControl_serial(t *testing.T) { @@ -32,7 +33,7 @@ func TestAccControlTowerControl_serial(t *testing.T) { func testAccControl_basic(t *testing.T) { ctx := acctest.Context(t) - var control controltower.EnabledControlSummary + var control types.EnabledControlSummary resourceName := "aws_controltower_control.test" controlName := "AWS-GR_EC2_VOLUME_INUSE_CHECK" ouName := "Security" @@ -43,7 +44,7 @@ func testAccControl_basic(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), CheckDestroy: testAccCheckControlDestroy(ctx), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ @@ -60,7 +61,7 @@ func testAccControl_basic(t *testing.T) { func testAccControl_disappears(t *testing.T) { ctx := acctest.Context(t) - var control controltower.EnabledControlSummary + var control types.EnabledControlSummary resourceName := "aws_controltower_control.test" controlName := "AWS-GR_EC2_VOLUME_INUSE_CHECK" ouName := "Security" @@ -71,7 +72,7 @@ func testAccControl_disappears(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckControlDestroy(ctx), Steps: []resource.TestStep{ @@ -87,7 +88,7 @@ func testAccControl_disappears(t *testing.T) { }) } -func testAccCheckControlExists(ctx context.Context, n string, v *controltower.EnabledControlSummary) resource.TestCheckFunc { +func testAccCheckControlExists(ctx context.Context, n string, v *types.EnabledControlSummary) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -103,7 +104,7 @@ func testAccCheckControlExists(ctx context.Context, n string, v *controltower.En return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerClient(ctx) output, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) @@ -119,7 +120,7 @@ func testAccCheckControlExists(ctx context.Context, n string, v *controltower.En func testAccCheckControlDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_controltower_control" { From 1c4d4317fe94ab0361dcae0cf0b68e7810ba7524 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 26 Nov 2023 23:11:23 +0100 Subject: [PATCH 03/12] chore [WIP]: port `internal/service/controltower/control.go` to `aws-sdk-go-v2` --- internal/service/controltower/control.go | 48 ++++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index aa331ba4b36..2de952ce46a 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -11,9 +11,9 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/controltower" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/controltower" + types "github.com/aws/aws-sdk-go-v2/service/controltower/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -56,7 +56,7 @@ func ResourceControl() *schema.Resource { } func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) controlIdentifier := d.Get("control_identifier").(string) targetIdentifier := d.Get("target_identifier").(string) @@ -66,7 +66,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int TargetIdentifier: aws.String(targetIdentifier), } - output, err := conn.EnableControlWithContext(ctx, input) + output, err := conn.EnableControl(ctx, input) if err != nil { return diag.Errorf("creating ControlTower Control (%s): %s", id, err) @@ -74,7 +74,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int d.SetId(id) - if _, err := waitOperationSucceeded(ctx, conn, aws.StringValue(output.OperationIdentifier), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitOperationSucceeded(ctx, conn, aws.ToString(output.OperationIdentifier), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("waiting for ControlTower Control (%s) create: %s", d.Id(), err) } @@ -82,7 +82,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int } func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) @@ -109,7 +109,7 @@ func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta inter } func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) @@ -118,7 +118,7 @@ func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta int } log.Printf("[DEBUG] Deleting ControlTower Control: %s", d.Id()) - output, err := conn.DisableControlWithContext(ctx, &controltower.DisableControlInput{ + output, err := conn.DisableControl(ctx, &controltower.DisableControlInput{ ControlIdentifier: aws.String(controlIdentifier), TargetIdentifier: aws.String(targetIdentifier), }) @@ -127,7 +127,7 @@ func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta int return diag.Errorf("deleting ControlTower Control (%s): %s", d.Id(), err) } - if _, err := waitOperationSucceeded(ctx, conn, aws.StringValue(output.OperationIdentifier), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitOperationSucceeded(ctx, conn, aws.ToString(output.OperationIdentifier), d.Timeout(schema.TimeoutDelete)); err != nil { return diag.Errorf("waiting for ControlTower Control (%s) delete: %s", d.Id(), err) } @@ -153,13 +153,13 @@ func ControlParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected TargetIdentifier%[2]sControlIdentifier", id, controlResourceIDSeparator) } -func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.ControlTower, targetIdentifier, controlIdentifier string) (*controltower.EnabledControlSummary, error) { +func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { input := &controltower.ListEnabledControlsInput{ TargetIdentifier: aws.String(targetIdentifier), } - var output *controltower.EnabledControlSummary + var output *types.EnabledControlSummary - err := conn.ListEnabledControlsPagesWithContext(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { + err := conn.ListEnabledControlsPages(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { if page == nil { return !lastPage } @@ -169,7 +169,7 @@ func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Cont continue } - if aws.StringValue(v.ControlIdentifier) == controlIdentifier { + if aws.ToString(v.ControlIdentifier) == controlIdentifier { output = v return false @@ -179,7 +179,7 @@ func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Cont return !lastPage }) - if tfawserr.ErrCodeEquals(err, controltower.ErrCodeResourceNotFoundException) { + if tfresource.NotFound(err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -197,14 +197,14 @@ func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Cont return output, nil } -func findControlOperationByID(ctx context.Context, conn *controltower.ControlTower, id string) (*controltower.ControlOperation, error) { +func findControlOperationByID(ctx context.Context, conn *controltower.Client, id string) (*types.ControlOperation, error) { input := &controltower.GetControlOperationInput{ OperationIdentifier: aws.String(id), } - output, err := conn.GetControlOperationWithContext(ctx, input) + output, err := conn.GetControlOperation(ctx, input) - if tfawserr.ErrCodeEquals(err, controltower.ErrCodeResourceNotFoundException) { + if tfresource.NotFound(err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -222,7 +222,7 @@ func findControlOperationByID(ctx context.Context, conn *controltower.ControlTow return output.ControlOperation, nil } -func statusControlOperation(ctx context.Context, conn *controltower.ControlTower, id string) retry.StateRefreshFunc { +func statusControlOperation(ctx context.Context, conn *controltower.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findControlOperationByID(ctx, conn, id) @@ -234,11 +234,11 @@ func statusControlOperation(ctx context.Context, conn *controltower.ControlTower return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } -func waitOperationSucceeded(ctx context.Context, conn *controltower.ControlTower, id string, timeout time.Duration) (*controltower.ControlOperation, error) { //nolint:unparam +func waitOperationSucceeded(ctx context.Context, conn *controltower.Client, id string, timeout time.Duration) (*types.ControlOperation, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{controltower.ControlOperationStatusInProgress}, Target: []string{controltower.ControlOperationStatusSucceeded}, @@ -248,9 +248,9 @@ func waitOperationSucceeded(ctx context.Context, conn *controltower.ControlTower outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*controltower.ControlOperation); ok { - if status := aws.StringValue(output.Status); status == controltower.ControlOperationStatusFailed { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*controltower.Client); ok { + if status := aws.ToString(output.Status); status == controltower.ControlOperationStatusFailed { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) } return output, err From ccd3255293e4a278939bc54f49faaacb133de398 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 26 Nov 2023 23:11:40 +0100 Subject: [PATCH 04/12] chore [WIP]: port `internal/service/controltower/control_data_source.go` to `aws-sdk-go-v2` --- internal/service/controltower/controls_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/controltower/controls_data_source.go b/internal/service/controltower/controls_data_source.go index 225bbaf93e6..9617521a171 100644 --- a/internal/service/controltower/controls_data_source.go +++ b/internal/service/controltower/controls_data_source.go @@ -35,7 +35,7 @@ func DataSourceControls() *schema.Resource { } func DataSourceControlsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier := d.Get("target_identifier").(string) input := &controltower.ListEnabledControlsInput{ From 45258cac4c0d337f7c642c5dd2d59347ce472766 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 26 Nov 2023 23:18:21 +0100 Subject: [PATCH 05/12] chore [WIP]: port `internal/service/controltower/control_data_source_test.go` to `aws-sdk-go-v2` --- internal/service/controltower/controls_data_source_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/controltower/controls_data_source_test.go b/internal/service/controltower/controls_data_source_test.go index 3c0a7aa8ac2..127f8431f08 100644 --- a/internal/service/controltower/controls_data_source_test.go +++ b/internal/service/controltower/controls_data_source_test.go @@ -9,10 +9,10 @@ import ( "testing" "github.com/aws/aws-sdk-go/service/cloudtrail" - "github.com/aws/aws-sdk-go/service/controltower" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccControlTowerControlsDataSource_basic(t *testing.T) { @@ -26,7 +26,7 @@ func TestAccControlTowerControlsDataSource_basic(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { From 1f352e6205eaef5fb1dde1ec40f7a108ea99e018 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Mon, 27 Nov 2023 23:19:15 +0100 Subject: [PATCH 06/12] chore: refactor ListEnabledControls function --- internal/service/controltower/control.go | 49 +++++++------------ .../controltower/controls_data_source.go | 38 +++++++------- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index 2de952ce46a..a2c8c2ffdf8 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -154,47 +154,34 @@ func ControlParseResourceID(id string) (string, string, error) { } func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { - input := &controltower.ListEnabledControlsInput{ - TargetIdentifier: aws.String(targetIdentifier), - } - var output *types.EnabledControlSummary - - err := conn.ListEnabledControlsPages(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + var nextToken string + for { + input := &controltower.ListEnabledControlsInput{ + TargetIdentifier: aws.String(targetIdentifier), + } + if nextToken != "" { + input.NextToken = aws.String(nextToken) } - for _, v := range page.EnabledControls { - if v == nil { - continue - } - - if aws.ToString(v.ControlIdentifier) == controlIdentifier { - output = v + out, err := conn.ListEnabledControls(ctx, input) + if err != nil { + return nil, err + } - return false + for _, control := range out.EnabledControls { + if aws.ToString(control.ControlIdentifier) == controlIdentifier { + return &control, nil } } - return !lastPage - }) - - if tfresource.NotFound(err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if out.NextToken == nil { + break } - } - if err != nil { - return nil, err - } - - if output == nil { - return nil, tfresource.NewEmptyResultError(input) + nextToken = aws.ToString(out.NextToken) } - return output, nil + return nil, nil } func findControlOperationByID(ctx context.Context, conn *controltower.Client, id string) (*types.ControlOperation, error) { diff --git a/internal/service/controltower/controls_data_source.go b/internal/service/controltower/controls_data_source.go index 9617521a171..3bd320a1d84 100644 --- a/internal/service/controltower/controls_data_source.go +++ b/internal/service/controltower/controls_data_source.go @@ -6,8 +6,8 @@ package controltower import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/controltower" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/controltower" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -38,28 +38,32 @@ func DataSourceControlsRead(ctx context.Context, d *schema.ResourceData, meta in conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier := d.Get("target_identifier").(string) - input := &controltower.ListEnabledControlsInput{ - TargetIdentifier: aws.String(targetIdentifier), - } var controls []string - err := conn.ListEnabledControlsPagesWithContext(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + var nextToken string + + for { + input := &controltower.ListEnabledControlsInput{ + TargetIdentifier: aws.String(targetIdentifier), + } + if nextToken != "" { + input.NextToken = aws.String(nextToken) } - for _, control := range page.EnabledControls { - if control == nil { - continue - } - controls = append(controls, aws.StringValue(control.ControlIdentifier)) + out, err := conn.ListEnabledControls(ctx, input) + if err != nil { + return diag.FromErr(err) } - return !lastPage - }) + for _, control := range out.EnabledControls { + controls = append(controls, aws.ToString(control.ControlIdentifier)) + } + + if out.NextToken == nil { + break + } - if err != nil { - return diag.Errorf("listing ControlTower Controls (%s): %s", targetIdentifier, err) + nextToken = aws.ToString(out.NextToken) } d.SetId(targetIdentifier) From 19975ba3dc52979c50666a95e8f323bb919e9136 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Mon, 27 Nov 2023 23:24:23 +0100 Subject: [PATCH 07/12] chore: refactor `waitOperationSucceeded` --- internal/service/controltower/control.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index a2c8c2ffdf8..43a0aa7c2d9 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -221,26 +221,24 @@ func statusControlOperation(ctx context.Context, conn *controltower.Client, id s return nil, "", err } - return output, aws.ToString(output.Status), nil + return output, aws.ToString((*string)(&output.Status)), nil } } func waitOperationSucceeded(ctx context.Context, conn *controltower.Client, id string, timeout time.Duration) (*types.ControlOperation, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ - Pending: []string{controltower.ControlOperationStatusInProgress}, - Target: []string{controltower.ControlOperationStatusSucceeded}, + Pending: []string{string(types.ControlOperationStatusInProgress)}, + Target: []string{string(types.ControlOperationStatusSucceeded)}, Refresh: statusControlOperation(ctx, conn, id), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*controltower.Client); ok { - if status := aws.ToString(output.Status); status == controltower.ControlOperationStatusFailed { - tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) - } + if output, ok := outputRaw.(*controltower.GetControlOperationOutput); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.ControlOperation.StatusMessage))) - return output, err + return output.ControlOperation, err } return nil, err From 422b08a713a0231e4c6c375f901f2b8164802061 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Mon, 27 Nov 2023 23:35:56 +0100 Subject: [PATCH 08/12] chore: use enum.Slice --- internal/service/controltower/control.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index 43a0aa7c2d9..e3ebba7feab 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -227,8 +228,8 @@ func statusControlOperation(ctx context.Context, conn *controltower.Client, id s func waitOperationSucceeded(ctx context.Context, conn *controltower.Client, id string, timeout time.Duration) (*types.ControlOperation, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ - Pending: []string{string(types.ControlOperationStatusInProgress)}, - Target: []string{string(types.ControlOperationStatusSucceeded)}, + Pending: enum.Slice(types.ControlOperationStatusInProgress), + Target: enum.Slice(types.ControlOperationStatusSucceeded), Refresh: statusControlOperation(ctx, conn, id), Timeout: timeout, } From 8fe9afaec9a0757f5232af5292fa4baa7d9427a4 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Mon, 27 Nov 2023 23:50:49 +0100 Subject: [PATCH 09/12] chore: make gen --- internal/provider/service_packages_gen.go | 415 +++++++++++++++++++++- names/names_data.csv | 2 +- 2 files changed, 415 insertions(+), 2 deletions(-) diff --git a/internal/provider/service_packages_gen.go b/internal/provider/service_packages_gen.go index 17d80912c85..93f1982554d 100644 --- a/internal/provider/service_packages_gen.go +++ b/internal/provider/service_packages_gen.go @@ -6,11 +6,424 @@ import ( "context" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/service/accessanalyzer" + "github.com/hashicorp/terraform-provider-aws/internal/service/account" + "github.com/hashicorp/terraform-provider-aws/internal/service/acm" + "github.com/hashicorp/terraform-provider-aws/internal/service/acmpca" + "github.com/hashicorp/terraform-provider-aws/internal/service/amp" + "github.com/hashicorp/terraform-provider-aws/internal/service/amplify" + "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" + "github.com/hashicorp/terraform-provider-aws/internal/service/apigatewayv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling" + "github.com/hashicorp/terraform-provider-aws/internal/service/appconfig" + "github.com/hashicorp/terraform-provider-aws/internal/service/appflow" + "github.com/hashicorp/terraform-provider-aws/internal/service/appintegrations" + "github.com/hashicorp/terraform-provider-aws/internal/service/applicationinsights" + "github.com/hashicorp/terraform-provider-aws/internal/service/appmesh" + "github.com/hashicorp/terraform-provider-aws/internal/service/apprunner" + "github.com/hashicorp/terraform-provider-aws/internal/service/appstream" + "github.com/hashicorp/terraform-provider-aws/internal/service/appsync" + "github.com/hashicorp/terraform-provider-aws/internal/service/athena" + "github.com/hashicorp/terraform-provider-aws/internal/service/auditmanager" + "github.com/hashicorp/terraform-provider-aws/internal/service/autoscaling" + "github.com/hashicorp/terraform-provider-aws/internal/service/autoscalingplans" + "github.com/hashicorp/terraform-provider-aws/internal/service/backup" + "github.com/hashicorp/terraform-provider-aws/internal/service/batch" + "github.com/hashicorp/terraform-provider-aws/internal/service/bedrock" + "github.com/hashicorp/terraform-provider-aws/internal/service/budgets" + "github.com/hashicorp/terraform-provider-aws/internal/service/ce" + "github.com/hashicorp/terraform-provider-aws/internal/service/chime" + "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkmediapipelines" + "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkvoice" + "github.com/hashicorp/terraform-provider-aws/internal/service/cleanrooms" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloud9" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudcontrol" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudformation" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudfront" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudhsmv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudtrail" + "github.com/hashicorp/terraform-provider-aws/internal/service/cloudwatch" + "github.com/hashicorp/terraform-provider-aws/internal/service/codeartifact" + "github.com/hashicorp/terraform-provider-aws/internal/service/codebuild" + "github.com/hashicorp/terraform-provider-aws/internal/service/codecatalyst" + "github.com/hashicorp/terraform-provider-aws/internal/service/codecommit" + "github.com/hashicorp/terraform-provider-aws/internal/service/codegurureviewer" + "github.com/hashicorp/terraform-provider-aws/internal/service/codepipeline" + "github.com/hashicorp/terraform-provider-aws/internal/service/codestarconnections" + "github.com/hashicorp/terraform-provider-aws/internal/service/codestarnotifications" + "github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidentity" + "github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp" + "github.com/hashicorp/terraform-provider-aws/internal/service/comprehend" + "github.com/hashicorp/terraform-provider-aws/internal/service/computeoptimizer" + "github.com/hashicorp/terraform-provider-aws/internal/service/configservice" + "github.com/hashicorp/terraform-provider-aws/internal/service/connect" + "github.com/hashicorp/terraform-provider-aws/internal/service/controltower" + "github.com/hashicorp/terraform-provider-aws/internal/service/cur" + "github.com/hashicorp/terraform-provider-aws/internal/service/dataexchange" + "github.com/hashicorp/terraform-provider-aws/internal/service/datapipeline" + "github.com/hashicorp/terraform-provider-aws/internal/service/datasync" + "github.com/hashicorp/terraform-provider-aws/internal/service/dax" + "github.com/hashicorp/terraform-provider-aws/internal/service/deploy" + "github.com/hashicorp/terraform-provider-aws/internal/service/detective" + "github.com/hashicorp/terraform-provider-aws/internal/service/devicefarm" + "github.com/hashicorp/terraform-provider-aws/internal/service/directconnect" + "github.com/hashicorp/terraform-provider-aws/internal/service/dlm" + "github.com/hashicorp/terraform-provider-aws/internal/service/dms" + "github.com/hashicorp/terraform-provider-aws/internal/service/docdb" + "github.com/hashicorp/terraform-provider-aws/internal/service/docdbelastic" + "github.com/hashicorp/terraform-provider-aws/internal/service/ds" + "github.com/hashicorp/terraform-provider-aws/internal/service/dynamodb" + "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" + "github.com/hashicorp/terraform-provider-aws/internal/service/ecr" + "github.com/hashicorp/terraform-provider-aws/internal/service/ecrpublic" + "github.com/hashicorp/terraform-provider-aws/internal/service/ecs" + "github.com/hashicorp/terraform-provider-aws/internal/service/efs" + "github.com/hashicorp/terraform-provider-aws/internal/service/eks" + "github.com/hashicorp/terraform-provider-aws/internal/service/elasticache" + "github.com/hashicorp/terraform-provider-aws/internal/service/elasticbeanstalk" + "github.com/hashicorp/terraform-provider-aws/internal/service/elasticsearch" + "github.com/hashicorp/terraform-provider-aws/internal/service/elastictranscoder" + "github.com/hashicorp/terraform-provider-aws/internal/service/elb" + "github.com/hashicorp/terraform-provider-aws/internal/service/elbv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/emr" + "github.com/hashicorp/terraform-provider-aws/internal/service/emrcontainers" + "github.com/hashicorp/terraform-provider-aws/internal/service/emrserverless" + "github.com/hashicorp/terraform-provider-aws/internal/service/events" + "github.com/hashicorp/terraform-provider-aws/internal/service/evidently" + "github.com/hashicorp/terraform-provider-aws/internal/service/finspace" + "github.com/hashicorp/terraform-provider-aws/internal/service/firehose" + "github.com/hashicorp/terraform-provider-aws/internal/service/fis" + "github.com/hashicorp/terraform-provider-aws/internal/service/fms" + "github.com/hashicorp/terraform-provider-aws/internal/service/fsx" + "github.com/hashicorp/terraform-provider-aws/internal/service/gamelift" + "github.com/hashicorp/terraform-provider-aws/internal/service/glacier" + "github.com/hashicorp/terraform-provider-aws/internal/service/globalaccelerator" + "github.com/hashicorp/terraform-provider-aws/internal/service/glue" + "github.com/hashicorp/terraform-provider-aws/internal/service/grafana" + "github.com/hashicorp/terraform-provider-aws/internal/service/greengrass" + "github.com/hashicorp/terraform-provider-aws/internal/service/guardduty" + "github.com/hashicorp/terraform-provider-aws/internal/service/healthlake" + "github.com/hashicorp/terraform-provider-aws/internal/service/iam" + "github.com/hashicorp/terraform-provider-aws/internal/service/identitystore" + "github.com/hashicorp/terraform-provider-aws/internal/service/imagebuilder" + "github.com/hashicorp/terraform-provider-aws/internal/service/inspector" + "github.com/hashicorp/terraform-provider-aws/internal/service/inspector2" + "github.com/hashicorp/terraform-provider-aws/internal/service/internetmonitor" + "github.com/hashicorp/terraform-provider-aws/internal/service/iot" + "github.com/hashicorp/terraform-provider-aws/internal/service/iotanalytics" + "github.com/hashicorp/terraform-provider-aws/internal/service/iotevents" + "github.com/hashicorp/terraform-provider-aws/internal/service/ivs" + "github.com/hashicorp/terraform-provider-aws/internal/service/ivschat" + "github.com/hashicorp/terraform-provider-aws/internal/service/kafka" + "github.com/hashicorp/terraform-provider-aws/internal/service/kafkaconnect" + "github.com/hashicorp/terraform-provider-aws/internal/service/kendra" + "github.com/hashicorp/terraform-provider-aws/internal/service/keyspaces" + "github.com/hashicorp/terraform-provider-aws/internal/service/kinesis" + "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisanalytics" + "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisanalyticsv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/kinesisvideo" + "github.com/hashicorp/terraform-provider-aws/internal/service/kms" + "github.com/hashicorp/terraform-provider-aws/internal/service/lakeformation" + "github.com/hashicorp/terraform-provider-aws/internal/service/lambda" + "github.com/hashicorp/terraform-provider-aws/internal/service/lexmodels" + "github.com/hashicorp/terraform-provider-aws/internal/service/lexv2models" + "github.com/hashicorp/terraform-provider-aws/internal/service/licensemanager" + "github.com/hashicorp/terraform-provider-aws/internal/service/lightsail" + "github.com/hashicorp/terraform-provider-aws/internal/service/location" + "github.com/hashicorp/terraform-provider-aws/internal/service/logs" + "github.com/hashicorp/terraform-provider-aws/internal/service/macie2" + "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconnect" + "github.com/hashicorp/terraform-provider-aws/internal/service/mediaconvert" + "github.com/hashicorp/terraform-provider-aws/internal/service/medialive" + "github.com/hashicorp/terraform-provider-aws/internal/service/mediapackage" + "github.com/hashicorp/terraform-provider-aws/internal/service/mediastore" + "github.com/hashicorp/terraform-provider-aws/internal/service/memorydb" + "github.com/hashicorp/terraform-provider-aws/internal/service/meta" + "github.com/hashicorp/terraform-provider-aws/internal/service/mq" + "github.com/hashicorp/terraform-provider-aws/internal/service/mwaa" + "github.com/hashicorp/terraform-provider-aws/internal/service/neptune" + "github.com/hashicorp/terraform-provider-aws/internal/service/networkfirewall" + "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" + "github.com/hashicorp/terraform-provider-aws/internal/service/oam" + "github.com/hashicorp/terraform-provider-aws/internal/service/opensearch" + "github.com/hashicorp/terraform-provider-aws/internal/service/opensearchserverless" + "github.com/hashicorp/terraform-provider-aws/internal/service/opsworks" + "github.com/hashicorp/terraform-provider-aws/internal/service/organizations" + "github.com/hashicorp/terraform-provider-aws/internal/service/outposts" + "github.com/hashicorp/terraform-provider-aws/internal/service/pinpoint" + "github.com/hashicorp/terraform-provider-aws/internal/service/pipes" + "github.com/hashicorp/terraform-provider-aws/internal/service/pricing" + "github.com/hashicorp/terraform-provider-aws/internal/service/qldb" + "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight" + "github.com/hashicorp/terraform-provider-aws/internal/service/ram" + "github.com/hashicorp/terraform-provider-aws/internal/service/rbin" + "github.com/hashicorp/terraform-provider-aws/internal/service/rds" + "github.com/hashicorp/terraform-provider-aws/internal/service/redshift" + "github.com/hashicorp/terraform-provider-aws/internal/service/redshiftdata" + "github.com/hashicorp/terraform-provider-aws/internal/service/redshiftserverless" + "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2" + "github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroups" + "github.com/hashicorp/terraform-provider-aws/internal/service/resourcegroupstaggingapi" + "github.com/hashicorp/terraform-provider-aws/internal/service/rolesanywhere" + "github.com/hashicorp/terraform-provider-aws/internal/service/route53" + "github.com/hashicorp/terraform-provider-aws/internal/service/route53domains" + "github.com/hashicorp/terraform-provider-aws/internal/service/route53recoverycontrolconfig" + "github.com/hashicorp/terraform-provider-aws/internal/service/route53recoveryreadiness" + "github.com/hashicorp/terraform-provider-aws/internal/service/route53resolver" + "github.com/hashicorp/terraform-provider-aws/internal/service/rum" + "github.com/hashicorp/terraform-provider-aws/internal/service/s3" + "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" + "github.com/hashicorp/terraform-provider-aws/internal/service/s3outposts" + "github.com/hashicorp/terraform-provider-aws/internal/service/sagemaker" + "github.com/hashicorp/terraform-provider-aws/internal/service/scheduler" + "github.com/hashicorp/terraform-provider-aws/internal/service/schemas" + "github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager" + "github.com/hashicorp/terraform-provider-aws/internal/service/securityhub" + "github.com/hashicorp/terraform-provider-aws/internal/service/securitylake" + "github.com/hashicorp/terraform-provider-aws/internal/service/serverlessrepo" + "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalog" + "github.com/hashicorp/terraform-provider-aws/internal/service/servicediscovery" + "github.com/hashicorp/terraform-provider-aws/internal/service/servicequotas" + "github.com/hashicorp/terraform-provider-aws/internal/service/ses" + "github.com/hashicorp/terraform-provider-aws/internal/service/sesv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/sfn" + "github.com/hashicorp/terraform-provider-aws/internal/service/shield" + "github.com/hashicorp/terraform-provider-aws/internal/service/signer" + "github.com/hashicorp/terraform-provider-aws/internal/service/simpledb" + "github.com/hashicorp/terraform-provider-aws/internal/service/sns" + "github.com/hashicorp/terraform-provider-aws/internal/service/sqs" + "github.com/hashicorp/terraform-provider-aws/internal/service/ssm" + "github.com/hashicorp/terraform-provider-aws/internal/service/ssmcontacts" + "github.com/hashicorp/terraform-provider-aws/internal/service/ssmincidents" + "github.com/hashicorp/terraform-provider-aws/internal/service/ssoadmin" + "github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway" + "github.com/hashicorp/terraform-provider-aws/internal/service/sts" + "github.com/hashicorp/terraform-provider-aws/internal/service/swf" + "github.com/hashicorp/terraform-provider-aws/internal/service/synthetics" + "github.com/hashicorp/terraform-provider-aws/internal/service/timestreamwrite" + "github.com/hashicorp/terraform-provider-aws/internal/service/transcribe" + "github.com/hashicorp/terraform-provider-aws/internal/service/transfer" + "github.com/hashicorp/terraform-provider-aws/internal/service/verifiedpermissions" + "github.com/hashicorp/terraform-provider-aws/internal/service/vpclattice" + "github.com/hashicorp/terraform-provider-aws/internal/service/waf" + "github.com/hashicorp/terraform-provider-aws/internal/service/wafregional" + "github.com/hashicorp/terraform-provider-aws/internal/service/wafv2" + "github.com/hashicorp/terraform-provider-aws/internal/service/worklink" + "github.com/hashicorp/terraform-provider-aws/internal/service/workspaces" + "github.com/hashicorp/terraform-provider-aws/internal/service/xray" "golang.org/x/exp/slices" ) func servicePackages(ctx context.Context) []conns.ServicePackage { - v := []conns.ServicePackage{} + v := []conns.ServicePackage{ + accessanalyzer.ServicePackage(ctx), + account.ServicePackage(ctx), + acm.ServicePackage(ctx), + acmpca.ServicePackage(ctx), + amp.ServicePackage(ctx), + amplify.ServicePackage(ctx), + apigateway.ServicePackage(ctx), + apigatewayv2.ServicePackage(ctx), + appautoscaling.ServicePackage(ctx), + appconfig.ServicePackage(ctx), + appflow.ServicePackage(ctx), + appintegrations.ServicePackage(ctx), + applicationinsights.ServicePackage(ctx), + appmesh.ServicePackage(ctx), + apprunner.ServicePackage(ctx), + appstream.ServicePackage(ctx), + appsync.ServicePackage(ctx), + athena.ServicePackage(ctx), + auditmanager.ServicePackage(ctx), + autoscaling.ServicePackage(ctx), + autoscalingplans.ServicePackage(ctx), + backup.ServicePackage(ctx), + batch.ServicePackage(ctx), + bedrock.ServicePackage(ctx), + budgets.ServicePackage(ctx), + ce.ServicePackage(ctx), + chime.ServicePackage(ctx), + chimesdkmediapipelines.ServicePackage(ctx), + chimesdkvoice.ServicePackage(ctx), + cleanrooms.ServicePackage(ctx), + cloud9.ServicePackage(ctx), + cloudcontrol.ServicePackage(ctx), + cloudformation.ServicePackage(ctx), + cloudfront.ServicePackage(ctx), + cloudhsmv2.ServicePackage(ctx), + cloudsearch.ServicePackage(ctx), + cloudtrail.ServicePackage(ctx), + cloudwatch.ServicePackage(ctx), + codeartifact.ServicePackage(ctx), + codebuild.ServicePackage(ctx), + codecatalyst.ServicePackage(ctx), + codecommit.ServicePackage(ctx), + codegurureviewer.ServicePackage(ctx), + codepipeline.ServicePackage(ctx), + codestarconnections.ServicePackage(ctx), + codestarnotifications.ServicePackage(ctx), + cognitoidentity.ServicePackage(ctx), + cognitoidp.ServicePackage(ctx), + comprehend.ServicePackage(ctx), + computeoptimizer.ServicePackage(ctx), + configservice.ServicePackage(ctx), + connect.ServicePackage(ctx), + controltower.ServicePackage(ctx), + cur.ServicePackage(ctx), + dataexchange.ServicePackage(ctx), + datapipeline.ServicePackage(ctx), + datasync.ServicePackage(ctx), + dax.ServicePackage(ctx), + deploy.ServicePackage(ctx), + detective.ServicePackage(ctx), + devicefarm.ServicePackage(ctx), + directconnect.ServicePackage(ctx), + dlm.ServicePackage(ctx), + dms.ServicePackage(ctx), + docdb.ServicePackage(ctx), + docdbelastic.ServicePackage(ctx), + ds.ServicePackage(ctx), + dynamodb.ServicePackage(ctx), + ec2.ServicePackage(ctx), + ecr.ServicePackage(ctx), + ecrpublic.ServicePackage(ctx), + ecs.ServicePackage(ctx), + efs.ServicePackage(ctx), + eks.ServicePackage(ctx), + elasticache.ServicePackage(ctx), + elasticbeanstalk.ServicePackage(ctx), + elasticsearch.ServicePackage(ctx), + elastictranscoder.ServicePackage(ctx), + elb.ServicePackage(ctx), + elbv2.ServicePackage(ctx), + emr.ServicePackage(ctx), + emrcontainers.ServicePackage(ctx), + emrserverless.ServicePackage(ctx), + events.ServicePackage(ctx), + evidently.ServicePackage(ctx), + finspace.ServicePackage(ctx), + firehose.ServicePackage(ctx), + fis.ServicePackage(ctx), + fms.ServicePackage(ctx), + fsx.ServicePackage(ctx), + gamelift.ServicePackage(ctx), + glacier.ServicePackage(ctx), + globalaccelerator.ServicePackage(ctx), + glue.ServicePackage(ctx), + grafana.ServicePackage(ctx), + greengrass.ServicePackage(ctx), + guardduty.ServicePackage(ctx), + healthlake.ServicePackage(ctx), + iam.ServicePackage(ctx), + identitystore.ServicePackage(ctx), + imagebuilder.ServicePackage(ctx), + inspector.ServicePackage(ctx), + inspector2.ServicePackage(ctx), + internetmonitor.ServicePackage(ctx), + iot.ServicePackage(ctx), + iotanalytics.ServicePackage(ctx), + iotevents.ServicePackage(ctx), + ivs.ServicePackage(ctx), + ivschat.ServicePackage(ctx), + kafka.ServicePackage(ctx), + kafkaconnect.ServicePackage(ctx), + kendra.ServicePackage(ctx), + keyspaces.ServicePackage(ctx), + kinesis.ServicePackage(ctx), + kinesisanalytics.ServicePackage(ctx), + kinesisanalyticsv2.ServicePackage(ctx), + kinesisvideo.ServicePackage(ctx), + kms.ServicePackage(ctx), + lakeformation.ServicePackage(ctx), + lambda.ServicePackage(ctx), + lexmodels.ServicePackage(ctx), + lexv2models.ServicePackage(ctx), + licensemanager.ServicePackage(ctx), + lightsail.ServicePackage(ctx), + location.ServicePackage(ctx), + logs.ServicePackage(ctx), + macie2.ServicePackage(ctx), + mediaconnect.ServicePackage(ctx), + mediaconvert.ServicePackage(ctx), + medialive.ServicePackage(ctx), + mediapackage.ServicePackage(ctx), + mediastore.ServicePackage(ctx), + memorydb.ServicePackage(ctx), + meta.ServicePackage(ctx), + mq.ServicePackage(ctx), + mwaa.ServicePackage(ctx), + neptune.ServicePackage(ctx), + networkfirewall.ServicePackage(ctx), + networkmanager.ServicePackage(ctx), + oam.ServicePackage(ctx), + opensearch.ServicePackage(ctx), + opensearchserverless.ServicePackage(ctx), + opsworks.ServicePackage(ctx), + organizations.ServicePackage(ctx), + outposts.ServicePackage(ctx), + pinpoint.ServicePackage(ctx), + pipes.ServicePackage(ctx), + pricing.ServicePackage(ctx), + qldb.ServicePackage(ctx), + quicksight.ServicePackage(ctx), + ram.ServicePackage(ctx), + rbin.ServicePackage(ctx), + rds.ServicePackage(ctx), + redshift.ServicePackage(ctx), + redshiftdata.ServicePackage(ctx), + redshiftserverless.ServicePackage(ctx), + resourceexplorer2.ServicePackage(ctx), + resourcegroups.ServicePackage(ctx), + resourcegroupstaggingapi.ServicePackage(ctx), + rolesanywhere.ServicePackage(ctx), + route53.ServicePackage(ctx), + route53domains.ServicePackage(ctx), + route53recoverycontrolconfig.ServicePackage(ctx), + route53recoveryreadiness.ServicePackage(ctx), + route53resolver.ServicePackage(ctx), + rum.ServicePackage(ctx), + s3.ServicePackage(ctx), + s3control.ServicePackage(ctx), + s3outposts.ServicePackage(ctx), + sagemaker.ServicePackage(ctx), + scheduler.ServicePackage(ctx), + schemas.ServicePackage(ctx), + secretsmanager.ServicePackage(ctx), + securityhub.ServicePackage(ctx), + securitylake.ServicePackage(ctx), + serverlessrepo.ServicePackage(ctx), + servicecatalog.ServicePackage(ctx), + servicediscovery.ServicePackage(ctx), + servicequotas.ServicePackage(ctx), + ses.ServicePackage(ctx), + sesv2.ServicePackage(ctx), + sfn.ServicePackage(ctx), + shield.ServicePackage(ctx), + signer.ServicePackage(ctx), + simpledb.ServicePackage(ctx), + sns.ServicePackage(ctx), + sqs.ServicePackage(ctx), + ssm.ServicePackage(ctx), + ssmcontacts.ServicePackage(ctx), + ssmincidents.ServicePackage(ctx), + ssoadmin.ServicePackage(ctx), + storagegateway.ServicePackage(ctx), + sts.ServicePackage(ctx), + swf.ServicePackage(ctx), + synthetics.ServicePackage(ctx), + timestreamwrite.ServicePackage(ctx), + transcribe.ServicePackage(ctx), + transfer.ServicePackage(ctx), + verifiedpermissions.ServicePackage(ctx), + vpclattice.ServicePackage(ctx), + waf.ServicePackage(ctx), + wafregional.ServicePackage(ctx), + wafv2.ServicePackage(ctx), + worklink.ServicePackage(ctx), + workspaces.ServicePackage(ctx), + xray.ServicePackage(ctx), + } return slices.Clone(v) } diff --git a/names/names_data.csv b/names/names_data.csv index 16475550ef7..7b9593bdf2d 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -98,7 +98,7 @@ connectparticipant,connectparticipant,connectparticipant,connectparticipant,,con voice-id,voiceid,voiceid,voiceid,,voiceid,,,VoiceID,VoiceID,,1,,,aws_voiceid_,,voiceid_,Connect Voice ID,Amazon,,x,,,,, wisdom,wisdom,connectwisdomservice,wisdom,,wisdom,,connectwisdomservice,Wisdom,ConnectWisdomService,,1,,,aws_wisdom_,,wisdom_,Connect Wisdom,Amazon,,x,,,,, ,,,,,,,,,,,,,,,,,Console Mobile Application,AWS,x,,,,,,No SDK support -controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,,2,aws_controltower_,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, +controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,,2,,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, cur,cur,costandusagereportservice,costandusagereportservice,,cur,,costandusagereportservice,CUR,CostandUsageReportService,,1,,,aws_cur_,,cur_,Cost and Usage Report,AWS,,,,,,, ,,,,,,,,,,,,,,,,,Crypto Tools,AWS,x,,,,,,No SDK support ,,,,,,,,,,,,,,,,,Cryptographic Services Overview,AWS,x,,,,,,No SDK support From 2d999a8a63acc8045843b123df5d1fd8e9f4e7eb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 28 Nov 2023 08:12:19 -0500 Subject: [PATCH 10/12] r/aws_controltower_control: Use resource ID functions in 'flex'. --- internal/service/controltower/control.go | 38 ++++++------------- internal/service/controltower/control_test.go | 19 +--------- .../controltower/service_package_gen.go | 1 + 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index e3ebba7feab..80262d2c5ab 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -6,9 +6,7 @@ package controltower import ( "context" "errors" - "fmt" "log" - "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -19,11 +17,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKResource("aws_controltower_control") +// @SDKResource("aws_controltower_control", name="Control") func ResourceControl() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceControlCreate, @@ -61,7 +61,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int controlIdentifier := d.Get("control_identifier").(string) targetIdentifier := d.Get("target_identifier").(string) - id := ControlCreateResourceID(targetIdentifier, controlIdentifier) + id := errs.Must(flex.FlattenResourceId([]string{targetIdentifier, controlIdentifier}, controlResourceIDPartCount, false)) input := &controltower.EnableControlInput{ ControlIdentifier: aws.String(controlIdentifier), TargetIdentifier: aws.String(targetIdentifier), @@ -85,12 +85,12 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) - targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) - + parts, err := flex.ExpandResourceId(d.Id(), controlResourceIDPartCount, false) if err != nil { return diag.FromErr(err) } + targetIdentifier, controlIdentifier := parts[0], parts[1] output, err := FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -112,12 +112,13 @@ func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) - targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) - + parts, err := flex.ExpandResourceId(d.Id(), controlResourceIDPartCount, false) if err != nil { return diag.FromErr(err) } + targetIdentifier, controlIdentifier := parts[0], parts[1] + log.Printf("[DEBUG] Deleting ControlTower Control: %s", d.Id()) output, err := conn.DisableControl(ctx, &controltower.DisableControlInput{ ControlIdentifier: aws.String(controlIdentifier), @@ -135,24 +136,9 @@ func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta int return nil } -const controlResourceIDSeparator = "," - -func ControlCreateResourceID(targetIdentifier, controlIdentifier string) string { - parts := []string{targetIdentifier, controlIdentifier} - id := strings.Join(parts, controlResourceIDSeparator) - - return id -} - -func ControlParseResourceID(id string) (string, string, error) { - parts := strings.Split(id, controlResourceIDSeparator) - - if len(parts) == 2 && parts[0] != "" && parts[1] != "" { - return parts[0], parts[1], nil - } - - return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected TargetIdentifier%[2]sControlIdentifier", id, controlResourceIDSeparator) -} +const ( + controlResourceIDPartCount = 2 +) func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { var nextToken string diff --git a/internal/service/controltower/control_test.go b/internal/service/controltower/control_test.go index c37a04e9079..60843a9b507 100644 --- a/internal/service/controltower/control_test.go +++ b/internal/service/controltower/control_test.go @@ -94,19 +94,10 @@ func testAccCheckControlExists(ctx context.Context, n string, v *types.EnabledCo if !ok { return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ControlTower Control ID is set") - } - - targetIdentifier, controlIdentifier, err := tfcontroltower.ControlParseResourceID(rs.Primary.ID) - - if err != nil { - return err - } conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerClient(ctx) - output, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + output, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, rs.Primary.Attributes["target_identifier"], rs.Primary.Attributes["control_identifier"]) if err != nil { return err @@ -127,13 +118,7 @@ func testAccCheckControlDestroy(ctx context.Context) resource.TestCheckFunc { continue } - targetIdentifier, controlIdentifier, err := tfcontroltower.ControlParseResourceID(rs.Primary.ID) - - if err != nil { - return err - } - - _, err = tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + _, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, rs.Primary.Attributes["target_identifier"], rs.Primary.Attributes["control_identifier"]) if tfresource.NotFound(err) { continue diff --git a/internal/service/controltower/service_package_gen.go b/internal/service/controltower/service_package_gen.go index b208587f2da..a2b069f7c0c 100644 --- a/internal/service/controltower/service_package_gen.go +++ b/internal/service/controltower/service_package_gen.go @@ -36,6 +36,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceControl, TypeName: "aws_controltower_control", + Name: "Control", }, } } From b68842e1d3506b4de877c60668c8d7d08c06dba8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 28 Nov 2023 08:24:18 -0500 Subject: [PATCH 11/12] r/aws_controltower_control: Use AWS SDK for Go v2 paginator. --- internal/service/controltower/control.go | 65 ++++++++++++------- internal/service/controltower/exports_test.go | 11 ++++ .../controltower/service_package_gen.go | 2 +- 3 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 internal/service/controltower/exports_test.go diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index 80262d2c5ab..2be63120ad0 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -11,7 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/controltower" - types "github.com/aws/aws-sdk-go-v2/service/controltower/types" + "github.com/aws/aws-sdk-go-v2/service/controltower/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -19,12 +19,13 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/flex" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) // @SDKResource("aws_controltower_control", name="Control") -func ResourceControl() *schema.Resource { +func resourceControl() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceControlCreate, ReadWithoutTimeout: resourceControlRead, @@ -91,7 +92,7 @@ func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta inter } targetIdentifier, controlIdentifier := parts[0], parts[1] - output, err := FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + output, err := findEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ControlTower Control %s not found, removing from state", d.Id()) @@ -140,35 +141,53 @@ const ( controlResourceIDPartCount = 2 ) -func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { - var nextToken string - for { - input := &controltower.ListEnabledControlsInput{ - TargetIdentifier: aws.String(targetIdentifier), - } - if nextToken != "" { - input.NextToken = aws.String(nextToken) +func findEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { + input := &controltower.ListEnabledControlsInput{ + TargetIdentifier: aws.String(targetIdentifier), + } + + return findEnabledControl(ctx, conn, input, func(v *types.EnabledControlSummary) bool { + return aws.ToString(v.ControlIdentifier) == controlIdentifier + }) +} + +func findEnabledControl(ctx context.Context, conn *controltower.Client, input *controltower.ListEnabledControlsInput, filter tfslices.Predicate[*types.EnabledControlSummary]) (*types.EnabledControlSummary, error) { + output, err := findEnabledControls(ctx, conn, input, filter) + + if err != nil { + return nil, err + } + + return tfresource.AssertSinglePtrResult(output) +} + +func findEnabledControls(ctx context.Context, conn *controltower.Client, input *controltower.ListEnabledControlsInput, filter tfslices.Predicate[*types.EnabledControlSummary]) ([]*types.EnabledControlSummary, error) { + var output []*types.EnabledControlSummary + + pages := controltower.NewListEnabledControlsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } } - out, err := conn.ListEnabledControls(ctx, input) if err != nil { return nil, err } - for _, control := range out.EnabledControls { - if aws.ToString(control.ControlIdentifier) == controlIdentifier { - return &control, nil + for _, v := range page.EnabledControls { + v := v + if v := &v; filter(v) { + output = append(output, v) } } - - if out.NextToken == nil { - break - } - - nextToken = aws.ToString(out.NextToken) } - return nil, nil + return output, nil } func findControlOperationByID(ctx context.Context, conn *controltower.Client, id string) (*types.ControlOperation, error) { @@ -178,7 +197,7 @@ func findControlOperationByID(ctx context.Context, conn *controltower.Client, id output, err := conn.GetControlOperation(ctx, input) - if tfresource.NotFound(err) { + if errs.IsA[*types.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/controltower/exports_test.go b/internal/service/controltower/exports_test.go new file mode 100644 index 00000000000..f5a047b800c --- /dev/null +++ b/internal/service/controltower/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package controltower + +// Exports for use in tests only. +var ( + ResourceControl = resourceControl + + FindEnabledControlByTwoPartKey = findEnabledControlByTwoPartKey +) diff --git a/internal/service/controltower/service_package_gen.go b/internal/service/controltower/service_package_gen.go index a2b069f7c0c..17cc536b772 100644 --- a/internal/service/controltower/service_package_gen.go +++ b/internal/service/controltower/service_package_gen.go @@ -34,7 +34,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceControl, + Factory: resourceControl, TypeName: "aws_controltower_control", Name: "Control", }, From b0d22186f92fde3b47bc93256358ef820ca4ada9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 28 Nov 2023 08:28:28 -0500 Subject: [PATCH 12/12] d/aws_controltower_controls: Use AWS SDK for Go v2 paginator. --- .../controltower/controls_data_source.go | 40 ++++++------------- .../controltower/service_package_gen.go | 3 +- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/internal/service/controltower/controls_data_source.go b/internal/service/controltower/controls_data_source.go index 3bd320a1d84..0b2e44a6fe5 100644 --- a/internal/service/controltower/controls_data_source.go +++ b/internal/service/controltower/controls_data_source.go @@ -8,14 +8,16 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/controltower" + "github.com/aws/aws-sdk-go-v2/service/controltower/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKDataSource("aws_controltower_controls") -func DataSourceControls() *schema.Resource { +// @SDKDataSource("aws_controltower_controls", name="Control") +func dataSourceControls() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: DataSourceControlsRead, @@ -38,36 +40,20 @@ func DataSourceControlsRead(ctx context.Context, d *schema.ResourceData, meta in conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier := d.Get("target_identifier").(string) + input := &controltower.ListEnabledControlsInput{ + TargetIdentifier: aws.String(targetIdentifier), + } - var controls []string - var nextToken string - - for { - input := &controltower.ListEnabledControlsInput{ - TargetIdentifier: aws.String(targetIdentifier), - } - if nextToken != "" { - input.NextToken = aws.String(nextToken) - } - - out, err := conn.ListEnabledControls(ctx, input) - if err != nil { - return diag.FromErr(err) - } - - for _, control := range out.EnabledControls { - controls = append(controls, aws.ToString(control.ControlIdentifier)) - } - - if out.NextToken == nil { - break - } + controls, err := findEnabledControls(ctx, conn, input, tfslices.PredicateTrue[*types.EnabledControlSummary]()) - nextToken = aws.ToString(out.NextToken) + if err != nil { + return diag.Errorf("reading ControlTower Controls (%s): %s", targetIdentifier, err) } d.SetId(targetIdentifier) - d.Set("enabled_controls", controls) + d.Set("enabled_controls", tfslices.ApplyToAll(controls, func(v *types.EnabledControlSummary) string { + return aws.ToString(v.ControlIdentifier) + })) return nil } diff --git a/internal/service/controltower/service_package_gen.go b/internal/service/controltower/service_package_gen.go index 17cc536b772..f9c58694ff9 100644 --- a/internal/service/controltower/service_package_gen.go +++ b/internal/service/controltower/service_package_gen.go @@ -25,8 +25,9 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceControls, + Factory: dataSourceControls, TypeName: "aws_controltower_controls", + Name: "Control", }, } }