From d0f9e8bf9b5e654e1812ff693f5ba8a57fe72062 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 13:58:54 -0500 Subject: [PATCH 01/15] add autogenerated files --- .ci/.semgrep-service-name0.yml | 117 +++++++++--------- .ci/.semgrep-service-name1.yml | 87 ++++++++----- .ci/.semgrep-service-name2.yml | 56 ++++----- .ci/.semgrep-service-name3.yml | 28 +++++ .../components/generated/services_all.kt | 1 + internal/provider/service_packages_gen.go | 2 + internal/sweep/sweep_test.go | 1 + 7 files changed, 177 insertions(+), 115 deletions(-) diff --git a/.ci/.semgrep-service-name0.yml b/.ci/.semgrep-service-name0.yml index 41541420f1e..4aed7d51792 100644 --- a/.ci/.semgrep-service-name0.yml +++ b/.ci/.semgrep-service-name0.yml @@ -2709,6 +2709,64 @@ rules: patterns: - pattern-regex: "(?i)codedeploy" severity: WARNING + - id: codegurureviewer-in-func-name + languages: + - go + message: Do not use "CodeGuruReviewer" in func name inside codegurureviewer package + paths: + include: + - internal/service/codegurureviewer + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)CodeGuruReviewer" + - pattern-not-regex: ^TestAcc.* + severity: WARNING + - id: codegurureviewer-in-test-name + languages: + - go + message: Include "CodeGuruReviewer" in test name + paths: + include: + - internal/service/codegurureviewer/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccCodeGuruReviewer" + - pattern-regex: ^TestAcc.* + severity: WARNING + - id: codegurureviewer-in-const-name + languages: + - go + message: Do not use "CodeGuruReviewer" in const name inside codegurureviewer package + paths: + include: + - internal/service/codegurureviewer + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)CodeGuruReviewer" + severity: WARNING + - id: codegurureviewer-in-var-name + languages: + - go + message: Do not use "CodeGuruReviewer" in var name inside codegurureviewer package + paths: + include: + - internal/service/codegurureviewer + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)CodeGuruReviewer" + severity: WARNING - id: codepipeline-in-func-name languages: - go @@ -3173,62 +3231,3 @@ rules: - pattern-regex: "(?i)ConfigService" - pattern-not-regex: ^TestAcc.* severity: WARNING - - id: configservice-in-test-name - languages: - - go - message: Include "ConfigService" in test name - paths: - include: - - internal/service/configservice/*_test.go - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-not-regex: "^TestAccConfigService" - - pattern-regex: ^TestAcc.* - severity: WARNING - - id: configservice-in-const-name - languages: - - go - message: Do not use "ConfigService" in const name inside configservice package - paths: - include: - - internal/service/configservice - patterns: - - pattern: const $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)ConfigService" - severity: WARNING - - id: configservice-in-var-name - languages: - - go - message: Do not use "ConfigService" in var name inside configservice package - paths: - include: - - internal/service/configservice - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)ConfigService" - severity: WARNING - - id: connect-in-func-name - languages: - - go - message: Do not use "Connect" in func name inside connect package - paths: - include: - - internal/service/connect - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Connect" - - pattern-not-regex: .*uickConnect.* - - pattern-not-regex: ^TestAcc.* - severity: WARNING diff --git a/.ci/.semgrep-service-name1.yml b/.ci/.semgrep-service-name1.yml index 5f01f282482..f0cd86ff259 100644 --- a/.ci/.semgrep-service-name1.yml +++ b/.ci/.semgrep-service-name1.yml @@ -1,5 +1,64 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: configservice-in-test-name + languages: + - go + message: Include "ConfigService" in test name + paths: + include: + - internal/service/configservice/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccConfigService" + - pattern-regex: ^TestAcc.* + severity: WARNING + - id: configservice-in-const-name + languages: + - go + message: Do not use "ConfigService" in const name inside configservice package + paths: + include: + - internal/service/configservice + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)ConfigService" + severity: WARNING + - id: configservice-in-var-name + languages: + - go + message: Do not use "ConfigService" in var name inside configservice package + paths: + include: + - internal/service/configservice + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)ConfigService" + severity: WARNING + - id: connect-in-func-name + languages: + - go + message: Do not use "Connect" in func name inside connect package + paths: + include: + - internal/service/connect + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Connect" + - pattern-not-regex: .*uickConnect.* + - pattern-not-regex: ^TestAcc.* + severity: WARNING - id: connect-in-test-name languages: - go @@ -3176,31 +3235,3 @@ rules: - pattern-not-regex: "^TestAccInspector2" - pattern-regex: ^TestAcc.* severity: WARNING - - id: inspector2-in-const-name - languages: - - go - message: Do not use "Inspector2" in const name inside inspector2 package - paths: - include: - - internal/service/inspector2 - patterns: - - pattern: const $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Inspector2" - severity: WARNING - - id: inspector2-in-var-name - languages: - - go - message: Do not use "Inspector2" in var name inside inspector2 package - paths: - include: - - internal/service/inspector2 - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Inspector2" - severity: WARNING diff --git a/.ci/.semgrep-service-name2.yml b/.ci/.semgrep-service-name2.yml index 1156593d468..189345c40e1 100644 --- a/.ci/.semgrep-service-name2.yml +++ b/.ci/.semgrep-service-name2.yml @@ -1,5 +1,33 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: inspector2-in-const-name + languages: + - go + message: Do not use "Inspector2" in const name inside inspector2 package + paths: + include: + - internal/service/inspector2 + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Inspector2" + severity: WARNING + - id: inspector2-in-var-name + languages: + - go + message: Do not use "Inspector2" in var name inside inspector2 package + paths: + include: + - internal/service/inspector2 + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Inspector2" + severity: WARNING - id: inspectorv2-in-func-name languages: - go @@ -3202,31 +3230,3 @@ rules: - pattern-not-regex: "^TestAccRDS" - pattern-regex: ^TestAcc.* severity: WARNING - - id: rds-in-const-name - languages: - - go - message: Do not use "RDS" in const name inside rds package - paths: - include: - - internal/service/rds - patterns: - - pattern: const $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)RDS" - severity: WARNING - - id: rds-in-var-name - languages: - - go - message: Do not use "RDS" in var name inside rds package - paths: - include: - - internal/service/rds - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)RDS" - severity: WARNING diff --git a/.ci/.semgrep-service-name3.yml b/.ci/.semgrep-service-name3.yml index 9a70513e088..2ceac17e863 100644 --- a/.ci/.semgrep-service-name3.yml +++ b/.ci/.semgrep-service-name3.yml @@ -1,5 +1,33 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: rds-in-const-name + languages: + - go + message: Do not use "RDS" in const name inside rds package + paths: + include: + - internal/service/rds + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)RDS" + severity: WARNING + - id: rds-in-var-name + languages: + - go + message: Do not use "RDS" in var name inside rds package + paths: + include: + - internal/service/rds + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)RDS" + severity: WARNING - id: redshift-in-func-name languages: - go diff --git a/.teamcity/components/generated/services_all.kt b/.teamcity/components/generated/services_all.kt index a1f1448c0f4..351c4cbbf61 100644 --- a/.teamcity/components/generated/services_all.kt +++ b/.teamcity/components/generated/services_all.kt @@ -38,6 +38,7 @@ val services = mapOf( "codeartifact" to ServiceSpec("CodeArtifact"), "codebuild" to ServiceSpec("CodeBuild"), "codecommit" to ServiceSpec("CodeCommit"), + "codegurureviewer" to ServiceSpec("CodeGuru Reviewer"), "codepipeline" to ServiceSpec("CodePipeline"), "codestarconnections" to ServiceSpec("CodeStar Connections"), "codestarnotifications" to ServiceSpec("CodeStar Notifications"), diff --git a/internal/provider/service_packages_gen.go b/internal/provider/service_packages_gen.go index 5553cb845f2..022f366142c 100644 --- a/internal/provider/service_packages_gen.go +++ b/internal/provider/service_packages_gen.go @@ -43,6 +43,7 @@ import ( "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/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" @@ -238,6 +239,7 @@ func servicePackages(context.Context) []conns.ServicePackage { codeartifact.ServicePackage, codebuild.ServicePackage, codecommit.ServicePackage, + codegurureviewer.ServicePackage, codepipeline.ServicePackage, codestarconnections.ServicePackage, codestarnotifications.ServicePackage, diff --git a/internal/sweep/sweep_test.go b/internal/sweep/sweep_test.go index e8405bee805..141d8a5879a 100644 --- a/internal/sweep/sweep_test.go +++ b/internal/sweep/sweep_test.go @@ -34,6 +34,7 @@ import ( _ "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/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/cognitoidp" From 8f477f5f1847062a1efa9874fffcec796ac61089 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 13:59:31 -0500 Subject: [PATCH 02/15] update provider.go aws_codegurureviewer_repository_association resource --- internal/provider/provider.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 1c2fcaada92..6c25c24b610 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -52,6 +52,7 @@ import ( "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/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" @@ -1163,6 +1164,8 @@ func New(ctx context.Context) (*schema.Provider, error) { "aws_codedeploy_deployment_config": deploy.ResourceDeploymentConfig(), "aws_codedeploy_deployment_group": deploy.ResourceDeploymentGroup(), + "aws_codegurureviewer_repository_association": codegurureviewer.ResourceRepositoryAssociation(), + "aws_codepipeline": codepipeline.ResourcePipeline(), "aws_codepipeline_custom_action_type": codepipeline.ResourceCustomActionType(), "aws_codepipeline_webhook": codepipeline.ResourceWebhook(), From 7cb3e7fd2a641a264f99ccc9138c8243d2bd4a27 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:00:35 -0500 Subject: [PATCH 03/15] add generate.go for codegurureviewer service --- internal/service/codegurureviewer/generate.go | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 internal/service/codegurureviewer/generate.go diff --git a/internal/service/codegurureviewer/generate.go b/internal/service/codegurureviewer/generate.go new file mode 100644 index 00000000000..43ee60105dc --- /dev/null +++ b/internal/service/codegurureviewer/generate.go @@ -0,0 +1,4 @@ +//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsMap -UpdateTags -ContextOnly +// ONLY generate directives and package declaration! Do not add anything else to this file. + +package codegurureviewer From 42052ed37f5d60bf4b40c20160026064c8b37b51 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:01:05 -0500 Subject: [PATCH 04/15] add service_package_gen.go for codegurureviewer service --- .../codegurureviewer/service_package_gen.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/service/codegurureviewer/service_package_gen.go diff --git a/internal/service/codegurureviewer/service_package_gen.go b/internal/service/codegurureviewer/service_package_gen.go new file mode 100644 index 00000000000..208c78d4dc1 --- /dev/null +++ b/internal/service/codegurureviewer/service_package_gen.go @@ -0,0 +1,36 @@ +// Code generated by internal/generate/servicepackages/main.go; DO NOT EDIT. + +package codegurureviewer + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/names" +) + +type servicePackage struct{} + +func (p *servicePackage) FrameworkDataSources(ctx context.Context) []func(context.Context) (datasource.DataSourceWithConfigure, error) { + return []func(context.Context) (datasource.DataSourceWithConfigure, error){} +} + +func (p *servicePackage) FrameworkResources(ctx context.Context) []func(context.Context) (resource.ResourceWithConfigure, error) { + return []func(context.Context) (resource.ResourceWithConfigure, error){} +} + +func (p *servicePackage) SDKDataSources(ctx context.Context) map[string]func() *schema.Resource { + return map[string]func() *schema.Resource{} +} + +func (p *servicePackage) SDKResources(ctx context.Context) map[string]func() *schema.Resource { + return map[string]func() *schema.Resource{} +} + +func (p *servicePackage) ServicePackageName() string { + return names.CodeGuruReviewer +} + +var ServicePackage = &servicePackage{} From 7dd4d6de6585003ef2b79f136f0adcd4a5ad751d Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:01:23 -0500 Subject: [PATCH 05/15] tags_gen.go for codegurureviewer service --- internal/service/codegurureviewer/tags_gen.go | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 internal/service/codegurureviewer/tags_gen.go diff --git a/internal/service/codegurureviewer/tags_gen.go b/internal/service/codegurureviewer/tags_gen.go new file mode 100644 index 00000000000..6b7c67089e8 --- /dev/null +++ b/internal/service/codegurureviewer/tags_gen.go @@ -0,0 +1,77 @@ +// Code generated by internal/generate/tags/main.go; DO NOT EDIT. +package codegurureviewer + +import ( + "context" + "fmt" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codegurureviewer" + "github.com/aws/aws-sdk-go/service/codegurureviewer/codegururevieweriface" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" +) + +// ListTags lists codegurureviewer service tags. +// The identifier is typically the Amazon Resource Name (ARN), although +// it may also be a different identifier depending on the service. +func ListTags(ctx context.Context, conn codegururevieweriface.CodeGuruReviewerAPI, identifier string) (tftags.KeyValueTags, error) { + input := &codegurureviewer.ListTagsForResourceInput{ + ResourceArn: aws.String(identifier), + } + + output, err := conn.ListTagsForResourceWithContext(ctx, input) + + if err != nil { + return tftags.New(ctx, nil), err + } + + return KeyValueTags(ctx, output.Tags), nil +} + +// map[string]*string handling + +// Tags returns codegurureviewer service tags. +func Tags(tags tftags.KeyValueTags) map[string]*string { + return aws.StringMap(tags.Map()) +} + +// KeyValueTags creates KeyValueTags from codegurureviewer service tags. +func KeyValueTags(ctx context.Context, tags map[string]*string) tftags.KeyValueTags { + return tftags.New(ctx, tags) +} + +// UpdateTags updates codegurureviewer service tags. +// The identifier is typically the Amazon Resource Name (ARN), although +// it may also be a different identifier depending on the service. +func UpdateTags(ctx context.Context, conn codegururevieweriface.CodeGuruReviewerAPI, identifier string, oldTagsMap interface{}, newTagsMap interface{}) error { + oldTags := tftags.New(ctx, oldTagsMap) + newTags := tftags.New(ctx, newTagsMap) + + if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 { + input := &codegurureviewer.UntagResourceInput{ + ResourceArn: aws.String(identifier), + TagKeys: aws.StringSlice(removedTags.IgnoreAWS().Keys()), + } + + _, err := conn.UntagResourceWithContext(ctx, input) + + if err != nil { + return fmt.Errorf("untagging resource (%s): %w", identifier, err) + } + } + + if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 { + input := &codegurureviewer.TagResourceInput{ + ResourceArn: aws.String(identifier), + Tags: Tags(updatedTags.IgnoreAWS()), + } + + _, err := conn.TagResourceWithContext(ctx, input) + + if err != nil { + return fmt.Errorf("tagging resource (%s): %w", identifier, err) + } + } + + return nil +} From b3c5cf67ffb32281185a158f63e7004a70faa6e6 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:01:43 -0500 Subject: [PATCH 06/15] add sweep.go for codegurureviewer service --- internal/service/codegurureviewer/sweep.go | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 internal/service/codegurureviewer/sweep.go diff --git a/internal/service/codegurureviewer/sweep.go b/internal/service/codegurureviewer/sweep.go new file mode 100644 index 00000000000..a802ea54c85 --- /dev/null +++ b/internal/service/codegurureviewer/sweep.go @@ -0,0 +1,68 @@ +//go:build sweep +// +build sweep + +package codegurureviewer + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codegurureviewer" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/sweep" +) + +func init() { + resource.AddTestSweepers("aws_codegurureviewer", &resource.Sweeper{ + Name: "aws_codegurureviewer", + F: sweepAssociations, + }) +} + +func sweepAssociations(region string) error { + ctx := sweep.Context(region) + client, err := sweep.SharedRegionalSweepClient(region) + if err != nil { + return fmt.Errorf("error getting client: %w", err) + } + input := &codegurureviewer.ListRepositoryAssociationsInput{} + conn := client.(*conns.AWSClient).CodeGuruReviewerConn() + + sweepResources := make([]sweep.Sweepable, 0) + + err = conn.ListRepositoryAssociationsPagesWithContext(ctx, input, func(page *codegurureviewer.ListRepositoryAssociationsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + for _, v := range page.Associations { + r := ResourceAssociation() + d := r.Data(nil) + + d.SetId(aws.StringValue(v.Name)) + + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + } + + return !lastPage + }) + + if sweep.SkipSweepError(err) { + log.Printf("[WARN] Skipping CodeGuruReviewer Association sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing CodeGuruReviewer Associations (%s): %w", region, err) + } + + err = sweep.SweepOrchestratorWithContext(ctx, sweepResources) + + if err != nil { + return fmt.Errorf("error sweeping CodeGuruReviewer Associations (%s): %w", region, err) + } + + return nil +} From d1c3c2abd900e3b31eafe553602bbef63b2c7bce Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:02:16 -0500 Subject: [PATCH 07/15] add resource for codegurureviewer_repository_association --- .../repository_association.go | 644 ++++++++++++++++++ 1 file changed, 644 insertions(+) create mode 100644 internal/service/codegurureviewer/repository_association.go diff --git a/internal/service/codegurureviewer/repository_association.go b/internal/service/codegurureviewer/repository_association.go new file mode 100644 index 00000000000..96ffcdfaa56 --- /dev/null +++ b/internal/service/codegurureviewer/repository_association.go @@ -0,0 +1,644 @@ +package codegurureviewer + +import ( + "context" + "errors" + "log" + "regexp" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codegurureviewer" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func ResourceRepositoryAssociation() *schema.Resource { + return &schema.Resource{ + + CreateWithoutTimeout: resourceRepositoryAssociationCreate, + ReadWithoutTimeout: resourceRepositoryAssociationRead, + UpdateWithoutTimeout: resourceRepositoryAssociationUpdate, + DeleteWithoutTimeout: resourceRepositoryAssociationDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "association_id": { + Type: schema.TypeString, + Computed: true, + }, + "connection_arn": { + Type: schema.TypeString, + Computed: true, + }, + "kms_key_details": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Show difference for new resources + if d.Id() == "" { + return false + } + // Show difference if existing state reflects different default type + _, defaultEncryptionOption := d.GetChange("kms_key_details.0.encryption_option") + if defaultEncryptionOption.(string) != codegurureviewer.EncryptionOptionAwsOwnedCmk { + return defaultEncryptionOption.(string) == codegurureviewer.EncryptionOptionAwsOwnedCmk + } + return true + }, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "encryption_option": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + ValidateFunc: validation.StringInSlice(codegurureviewer.EncryptionOption_Values(), false), + }, + "kms_key_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 2048), + validation.StringMatch(regexp.MustCompile(`[a-zA-Z0-9-]+`), ""), + ), + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "provider_type": { + Type: schema.TypeString, + Computed: true, + }, + "repository": { + Type: schema.TypeList, + Required: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bitbucket": { + Type: schema.TypeList, + ForceNew: true, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "connection_arn": { + Type: schema.TypeString, + Required: true, + ValidateFunc: verify.ValidARN, + }, + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S[\w.-]*$`), ""), + ), + }, + "owner": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S(.*\S)?$`), ""), + ), + }, + }, + }, + }, + "codecommit": { + Type: schema.TypeList, + ForceNew: true, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S[\w.-]*$`), ""), + ), + }, + }, + }, + }, + "github_enterprise_server": { + Type: schema.TypeList, + ForceNew: true, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "connection_arn": { + Type: schema.TypeString, + Required: true, + ValidateFunc: verify.ValidARN, + }, + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S[\w.-]*$`), ""), + ), + }, + "owner": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S(.*\S)?$`), ""), + ), + }, + }, + }, + }, + "s3_bucket": { + Type: schema.TypeList, + ForceNew: true, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 63), + validation.StringMatch(regexp.MustCompile(`^\S(.*\S)?$`), ""), + ), + }, + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 100), + validation.StringMatch(regexp.MustCompile(`^\S[\w.-]*$`), ""), + ), + }, + }, + }, + }, + }, + }, + }, + "s3_repository_details": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Computed: true, + }, + "code_artifacts": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "build_artifacts_object_key": { + Type: schema.TypeString, + Computed: true, + }, + "source_code_artifacts_object_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "state_reason": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + }, + CustomizeDiff: customdiff.Sequence( + verify.SetTagsDiff, + ), + } +} + +const ( + ResNameRepositoryAssociation = "RepositoryAssociation" +) + +func resourceRepositoryAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() + + in := &codegurureviewer.AssociateRepositoryInput{} + + in.KMSKeyDetails = expandKMSKeyDetails(d.Get("kms_key_details").([]interface{})) + + if v, ok := d.GetOk("repository"); ok { + in.Repository = expandRepository(v.([]interface{})) + } + + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) + + if len(tags) > 0 { + in.Tags = Tags(tags.IgnoreAWS()) + } + + out, err := conn.AssociateRepositoryWithContext(ctx, in) + + if err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionCreating, ResNameRepositoryAssociation, d.Get("name").(string), err) + } + + if out == nil || out.RepositoryAssociation == nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionCreating, ResNameRepositoryAssociation, d.Get("name").(string), errors.New("empty output")) + } + + d.SetId(aws.StringValue(out.RepositoryAssociation.AssociationArn)) + + if _, err := waitRepositoryAssociationCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionWaitingForCreation, ResNameRepositoryAssociation, d.Id(), err) + } + + return resourceRepositoryAssociationRead(ctx, d, meta) +} + +func resourceRepositoryAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + + conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() + + out, err := findRepositoryAssociationByID(ctx, conn, d.Id()) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] CodeGuruReviewer RepositoryAssociation (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + if err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionReading, ResNameRepositoryAssociation, d.Id(), err) + } + + d.Set("arn", out.AssociationArn) + d.Set("association_id", out.AssociationId) + d.Set("connection_arn", out.ConnectionArn) + + if err := d.Set("kms_key_details", flattenKMSKeyDetails(out.KMSKeyDetails)); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionSetting, ResNameRepositoryAssociation, d.Id(), err) + } + + d.Set("name", out.Name) + d.Set("owner", out.Owner) + d.Set("provider_type", out.ProviderType) + + if err := d.Set("s3_repository_details", flattenS3RepositoryDetails(out.S3RepositoryDetails)); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionSetting, ResNameRepositoryAssociation, d.Id(), err) + } + + d.Set("state", out.State) + d.Set("state_reason", out.StateReason) + + tags, err := ListTags(ctx, conn, d.Id()) + if err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionReading, ResNameRepositoryAssociation, d.Id(), err) + } + + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) + + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionSetting, ResNameRepositoryAssociation, d.Id(), err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionSetting, ResNameRepositoryAssociation, d.Id(), err) + } + + return nil +} + +func resourceRepositoryAssociationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + arn := d.Get("arn").(string) + + if err := UpdateTags(ctx, conn, arn, o, n); err != nil { + return sdkdiag.AppendErrorf(diags, "updating CodeGuru Repository RepositoryAssociation (%s) tags: %s", d.Get("id").(string), err) + } + } + + return append(diags, resourceRepositoryAssociationRead(ctx, d, meta)...) +} + +func resourceRepositoryAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + + conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() + + log.Printf("[INFO] Deleting CodeGuruReviewer RepositoryAssociation %s", d.Id()) + + _, err := conn.DisassociateRepositoryWithContext(ctx, &codegurureviewer.DisassociateRepositoryInput{ + AssociationArn: aws.String(d.Id()), + }) + + if tfawserr.ErrCodeEquals(err, codegurureviewer.ErrCodeNotFoundException) { + return nil + } + + if err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionDeleting, ResNameRepositoryAssociation, d.Id(), err) + } + + if _, err := waitRepositoryAssociationDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + return create.DiagError(names.CodeGuruReviewer, create.ErrActionWaitingForDeletion, ResNameRepositoryAssociation, d.Id(), err) + } + + return nil +} + +func waitRepositoryAssociationCreated(ctx context.Context, conn *codegurureviewer.CodeGuruReviewer, id string, timeout time.Duration) (*codegurureviewer.RepositoryAssociation, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{codegurureviewer.RepositoryAssociationStateAssociating}, + Target: []string{codegurureviewer.RepositoryAssociationStateAssociated}, + Refresh: statusRepositoryAssociation(ctx, conn, id), + Timeout: timeout, + NotFoundChecks: 20, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + if out, ok := outputRaw.(*codegurureviewer.RepositoryAssociation); ok { + return out, err + } + + return nil, err +} + +func waitRepositoryAssociationDeleted(ctx context.Context, conn *codegurureviewer.CodeGuruReviewer, id string, timeout time.Duration) (*codegurureviewer.RepositoryAssociation, error) { + stateConf := &resource.StateChangeConf{ + Pending: []string{codegurureviewer.RepositoryAssociationStateDisassociating, codegurureviewer.RepositoryAssociationStateAssociated}, + Target: []string{}, + Refresh: statusRepositoryAssociation(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + if out, ok := outputRaw.(*codegurureviewer.RepositoryAssociation); ok { + return out, err + } + + return nil, err +} + +func statusRepositoryAssociation(ctx context.Context, conn *codegurureviewer.CodeGuruReviewer, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + out, err := findRepositoryAssociationByID(ctx, conn, id) + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return out, aws.StringValue(out.State), nil + } +} + +func findRepositoryAssociationByID(ctx context.Context, conn *codegurureviewer.CodeGuruReviewer, id string) (*codegurureviewer.RepositoryAssociation, error) { + in := &codegurureviewer.DescribeRepositoryAssociationInput{ + AssociationArn: aws.String(id), + } + out, err := conn.DescribeRepositoryAssociationWithContext(ctx, in) + if tfawserr.ErrCodeEquals(err, codegurureviewer.ErrCodeNotFoundException) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if err != nil { + return nil, err + } + + if out == nil || out.RepositoryAssociation == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out.RepositoryAssociation, nil +} + +func flattenKMSKeyDetails(kmsKeyDetails *codegurureviewer.KMSKeyDetails) []interface{} { + if kmsKeyDetails == nil { + return nil + } + + values := map[string]interface{}{} + + if v := kmsKeyDetails.EncryptionOption; v != nil { + values["encryption_option"] = aws.StringValue(v) + } + + if v := kmsKeyDetails.KMSKeyId; v != nil { + values["kms_key_id"] = aws.StringValue(v) + } + + return []interface{}{values} +} + +func flattenS3RepositoryDetails(s3RepositoryDetails *codegurureviewer.S3RepositoryDetails) []interface{} { + if s3RepositoryDetails == nil { + return nil + } + + values := map[string]interface{}{} + + if v := s3RepositoryDetails.BucketName; v != nil { + values["bucket_name"] = aws.StringValue(v) + } + + if v := s3RepositoryDetails.CodeArtifacts; v != nil { + values["code_artifacts"] = flattenCodeArtifacts(v) + } + + return []interface{}{values} +} + +func flattenCodeArtifacts(apiObject *codegurureviewer.CodeArtifacts) map[string]interface{} { + if apiObject == nil { + return nil + } + + m := map[string]interface{}{} + + if v := apiObject.BuildArtifactsObjectKey; v != nil { + m["build_artifacts_object_key"] = aws.StringValue(v) + } + + if v := apiObject.SourceCodeArtifactsObjectKey; v != nil { + m["source_code_artifacts_object_key"] = aws.StringValue(v) + } + + return m +} + +func expandKMSKeyDetails(kmsKeyDetails []interface{}) *codegurureviewer.KMSKeyDetails { + if len(kmsKeyDetails) == 0 || kmsKeyDetails[0] == nil { + return nil + } + + tfMap, ok := kmsKeyDetails[0].(map[string]interface{}) + if !ok { + return nil + } + + result := &codegurureviewer.KMSKeyDetails{} + + if v, ok := tfMap["encryption_option"].(string); ok && v != "" { + result.EncryptionOption = aws.String(v) + } + + if v, ok := tfMap["kms_key_id"].(string); ok && v != "" { + result.KMSKeyId = aws.String(v) + } + + return result +} + +func expandCodeCommitRepository(repository []interface{}) *codegurureviewer.CodeCommitRepository { + if len(repository) == 0 || repository[0] == nil { + return nil + } + + tfMap, ok := repository[0].(map[string]interface{}) + if !ok { + return nil + } + + result := &codegurureviewer.CodeCommitRepository{} + + if v, ok := tfMap["name"].(string); ok && v != "" { + result.Name = aws.String(v) + } + + return result +} + +func expandRepository(repository []interface{}) *codegurureviewer.Repository { + if len(repository) == 0 || repository[0] == nil { + return nil + } + + tfMap, ok := repository[0].(map[string]interface{}) + if !ok { + return nil + } + + result := &codegurureviewer.Repository{} + + if v, ok := tfMap["bitbucket"]; ok { + result.Bitbucket = expandThirdPartySourceRepository(v.([]interface{})) + } + if v, ok := tfMap["codecommit"]; ok { + result.CodeCommit = expandCodeCommitRepository(v.([]interface{})) + } + if v, ok := tfMap["github_enterprise_server"]; ok { + result.GitHubEnterpriseServer = expandThirdPartySourceRepository(v.([]interface{})) + } + if v, ok := tfMap["s3_bucket"]; ok { + result.S3Bucket = expandS3Repository(v.([]interface{})) + } + + return result +} + +func expandS3Repository(repository []interface{}) *codegurureviewer.S3Repository { + if len(repository) == 0 || repository[0] == nil { + return nil + } + + tfMap, ok := repository[0].(map[string]interface{}) + if !ok { + return nil + } + + result := &codegurureviewer.S3Repository{} + + if v, ok := tfMap["bucket_name"].(string); ok && v != "" { + result.BucketName = aws.String(v) + } + + if v, ok := tfMap["name"].(string); ok && v != "" { + result.Name = aws.String(v) + } + + return result +} + +func expandThirdPartySourceRepository(repository []interface{}) *codegurureviewer.ThirdPartySourceRepository { + if len(repository) == 0 || repository[0] == nil { + return nil + } + + tfMap, ok := repository[0].(map[string]interface{}) + if !ok { + return nil + } + + result := &codegurureviewer.ThirdPartySourceRepository{} + + if v, ok := tfMap["connection_arn"].(string); ok && v != "" { + result.ConnectionArn = aws.String(v) + } + + if v, ok := tfMap["name"].(string); ok && v != "" { + result.Name = aws.String(v) + } + + if v, ok := tfMap["owner"].(string); ok && v != "" { + result.Owner = aws.String(v) + } + + return result +} From 67f7a166e7da16a6a913d36c62a42823cd53d957 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:02:28 -0500 Subject: [PATCH 08/15] add tests for codegurureviewer_repository_association --- .../repository_association_test.go | 399 ++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 internal/service/codegurureviewer/repository_association_test.go diff --git a/internal/service/codegurureviewer/repository_association_test.go b/internal/service/codegurureviewer/repository_association_test.go new file mode 100644 index 00000000000..2f1be83e901 --- /dev/null +++ b/internal/service/codegurureviewer/repository_association_test.go @@ -0,0 +1,399 @@ +package codegurureviewer_test + +import ( + "context" + "errors" + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codegurureviewer" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/names" + + tfcodegurureviewer "github.com/hashicorp/terraform-provider-aws/internal/service/codegurureviewer" +) + +// Repository types of "BitBucket and GitHubEnterpriseServer cannot be tested, as they require their CodeStar Connection to be in "AVAILABLE" status vs "PENDING", requiring console interaction +// However, this has been manually tested succesfully +func TestAccCodeGuruReviewerRepositoryAssociation_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + ctx := acctest.Context(t) + var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codegurureviewer_repository_association.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRepositoryAssociationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRepositoryAssociationConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + acctest.MatchResourceAttrRegionalARN(resourceName, "id", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + resource.TestCheckResourceAttr(resourceName, "repository.0.bitbucket.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.codecommit.#", "1"), + resource.TestCheckResourceAttr(resourceName, "repository.0.github_enterprise_server.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.s3_bucket.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.codecommit.0.name", rName), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.#", "1"), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.0.encryption_option", "AWS_OWNED_CMK"), + ), + }, + }, + }) +} + +func TestAccCodeGuruReviewerRepositoryAssociation_KMSKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + ctx := acctest.Context(t) + var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codegurureviewer_repository_association.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRepositoryAssociationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRepositoryAssociationConfig_kms_key(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + acctest.MatchResourceAttrRegionalARN(resourceName, "id", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + resource.TestCheckResourceAttr(resourceName, "repository.0.bitbucket.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.codecommit.#", "1"), + resource.TestCheckResourceAttr(resourceName, "repository.0.github_enterprise_server.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.s3_bucket.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.codecommit.0.name", rName), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.#", "1"), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.0.encryption_option", "CUSTOMER_MANAGED_CMK"), + ), + }, + }, + }) +} + +func TestAccCodeGuruReviewerRepositoryAssociation_S3Repository(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + ctx := acctest.Context(t) + var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput + rName := "codeguru-reviewer-" + sdkacctest.RandString(10) + resourceName := "aws_codegurureviewer_repository_association.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRepositoryAssociationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRepositoryAssociationConfig_s3_repository(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + acctest.MatchResourceAttrRegionalARN(resourceName, "id", "codeguru-reviewer", regexp.MustCompile(`association:+.`)), + resource.TestCheckResourceAttr(resourceName, "repository.0.bitbucket.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.codecommit.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.github_enterprise_server.#", "0"), + resource.TestCheckResourceAttr(resourceName, "repository.0.s3_bucket.#", "1"), + resource.TestCheckResourceAttr(resourceName, "repository.0.s3_bucket.0.bucket_name", rName), + resource.TestCheckResourceAttr(resourceName, "repository.0.s3_bucket.0.name", "test"), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.#", "1"), + resource.TestCheckResourceAttr(resourceName, "kms_key_details.0.encryption_option", "AWS_OWNED_CMK"), + ), + }, + }, + }) +} + +func TestAccCodeGuruReviewerRepositoryAssociation_tags(t *testing.T) { + ctx := acctest.Context(t) + var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput + resourceName := "aws_codegurureviewer_repository_association.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRepositoryAssociationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRepositoryAssociationConfig_tags_1(rName, "key1", "value1"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + Config: testAccRepositoryAssociationConfig_tags_2(rName, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccRepositoryAssociationConfig_tags_1(rName, "key2", "value2"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func TestAccCodeGuruReviewerRepositoryAssociation_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + ctx := acctest.Context(t) + var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_codegurureviewer_repository_association.test" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRepositoryAssociationDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRepositoryAssociationConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckRepositoryAssociationExists(ctx, resourceName, &repositoryassociation), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfcodegurureviewer.ResourceRepositoryAssociation(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckRepositoryAssociationDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruReviewerConn() + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codegurureviewer_repository_association" { + continue + } + + input := &codegurureviewer.DescribeRepositoryAssociationInput{ + AssociationArn: aws.String(rs.Primary.ID), + } + _, err := conn.DescribeRepositoryAssociationWithContext(ctx, input) + if err != nil { + if tfawserr.ErrCodeEquals(err, codegurureviewer.ErrCodeNotFoundException) { + return nil + } + return err + } + + return fmt.Errorf("CodeGuru Reviewer Association Connection %s still exists", rs.Primary.ID) + } + + return nil + } +} + +func testAccCheckRepositoryAssociationExists(ctx context.Context, name string, repositoryassociation *codegurureviewer.DescribeRepositoryAssociationOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.CodeGuruReviewer, create.ErrActionCheckingExistence, tfcodegurureviewer.ResNameRepositoryAssociation, name, errors.New("not found")) + } + + if rs.Primary.ID == "" { + return create.Error(names.CodeGuruReviewer, create.ErrActionCheckingExistence, tfcodegurureviewer.ResNameRepositoryAssociation, name, errors.New("not set")) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruReviewerConn() + resp, err := conn.DescribeRepositoryAssociationWithContext(ctx, &codegurureviewer.DescribeRepositoryAssociationInput{ + AssociationArn: aws.String(rs.Primary.ID), + }) + + if err != nil { + return create.Error(names.CodeGuruReviewer, create.ErrActionCheckingExistence, tfcodegurureviewer.ResNameRepositoryAssociation, rs.Primary.ID, err) + } + + *repositoryassociation = *resp + + return nil + } +} + +func testAccPreCheck(t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruReviewerConn() + ctx := context.Background() + + input := &codegurureviewer.ListRepositoryAssociationsInput{} + _, err := conn.ListRepositoryAssociationsWithContext(ctx, input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} + +func testAccCheckRepositoryAssociationNotRecreated(before, after *codegurureviewer.DescribeRepositoryAssociationOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + if before, after := aws.StringValue(before.RepositoryAssociation.AssociationArn), aws.StringValue(after.RepositoryAssociation.AssociationArn); before != after { + return create.Error(names.CodeGuruReviewer, create.ErrActionCheckingNotRecreated, tfcodegurureviewer.ResNameRepositoryAssociation, before, errors.New("recreated")) + } + + return nil + } +} + +func testAccRepositoryAssociationConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccRepositoryAssociation_codecommit_repository(rName), ` +resource "aws_codegurureviewer_repository_association" "test" { + repository { + codecommit { + name = aws_codecommit_repository.test.repository_name + } + } +} +`) +} + +func testAccRepositoryAssociationConfig_kms_key(rName string) string { + return acctest.ConfigCompose(testAccRepositoryAssociation_codecommit_repository(rName), testAccRepositoryAssociation_kms_key(), ` +resource "aws_codegurureviewer_repository_association" "test" { + repository { + codecommit { + name = aws_codecommit_repository.test.repository_name + } + } + + kms_key_details { + encryption_option = "CUSTOMER_MANAGED_CMK" + kms_key_id = aws_kms_key.test.key_id + } +} +`) +} + +func testAccRepositoryAssociationConfig_tags_1(rName, tagKey1, tagValue1 string) string { + return acctest.ConfigCompose(testAccRepositoryAssociation_codecommit_repository(rName), fmt.Sprintf(` +resource "aws_codegurureviewer_repository_association" "test" { + repository { + codecommit { + name = aws_codecommit_repository.test.repository_name + } + } + tags = { + %[1]q = %[2]q + } +} +`, tagKey1, tagValue1)) +} + +func testAccRepositoryAssociationConfig_tags_2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return acctest.ConfigCompose(testAccRepositoryAssociation_codecommit_repository(rName), fmt.Sprintf(` +resource "aws_codegurureviewer_repository_association" "test" { + repository { + codecommit { + name = aws_codecommit_repository.test.repository_name + } + } + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} +`, tagKey1, tagValue1, tagKey2, tagValue2)) +} + +func testAccRepositoryAssociationConfig_s3_repository(rName string) string { + return acctest.ConfigCompose(testAccRepositoryAssociation_s3_repository(rName), ` +resource "aws_codegurureviewer_repository_association" "test" { + repository { + s3_bucket { + bucket_name = aws_s3_bucket.test.id + name = "test" + } + } +} +`) +} + +func testAccRepositoryAssociation_codecommit_repository(rName string) string { + return fmt.Sprintf(` +resource "aws_codecommit_repository" "test" { + repository_name = %[1]q + description = "This is a test description" + lifecycle { + ignore_changes = [ + tags["codeguru-reviewer"] + ] + } +} +`, rName) +} + +func testAccRepositoryAssociation_s3_repository(rName string) string { + return fmt.Sprintf(` + +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} +`, rName) +} + +func testAccRepositoryAssociation_kms_key() string { + return fmt.Sprint(` + + +resource "aws_kms_key" "test" { + deletion_window_in_days = 7 +} +`) +} From 49221c8ad24d214c7761b2e49d9ea1566c293b17 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:02:43 -0500 Subject: [PATCH 09/15] add documentation for codegurureviewer_repository_association --- ...iewer_repository_association.html.markdown | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 website/docs/r/codegurureviewer_repository_association.html.markdown diff --git a/website/docs/r/codegurureviewer_repository_association.html.markdown b/website/docs/r/codegurureviewer_repository_association.html.markdown new file mode 100644 index 00000000000..3e94142d826 --- /dev/null +++ b/website/docs/r/codegurureviewer_repository_association.html.markdown @@ -0,0 +1,103 @@ +--- +subcategory: "CodeGuru Reviewer" +layout: "aws" +page_title: "AWS: aws_codegurureviewer_repository_association" +description: |- + Terraform resource for managing an AWS CodeGuru Reviewer Repository Association. +--- + +# Resource: aws_codegurureviewer_repository_association + +Terraform resource for managing an AWS CodeGuru Reviewer Repository Association. + +## Example Usage + +```terraform +resource "aws_kms_key" "example" {} + +resource "aws_codecommit_repository" "example" { + repository_name = "example-repo" + + # ignore tag added by CodeGuru service upon association + lifecycle { + ignore_changes = [ + tags["codeguru-reviewer"] + ] + } +} + +resource "aws_codegurureviewer_repository_association" "example" { + repository { + codecommit { + name = aws_codecommit_repository.example.repository_name + } + } + kms_key_details { + encryption_option = "CUSTOMER_MANAGED_CMK" + kms_key_id = aws_kms_key.example.key_id + } +} + +``` + +## Argument Reference + +The following arguments are required: + +* `repository` - (Required) An object describing the repository to associate. Valid values: `bitbucket`, `codecommit`, `github_enterprise_server`, or `s3_bucket`. Block is documented below. Note: for repositories that leverage CodeStar connections (ex. `bitbucket`, `github_enterprise_server`) the connection must be in `Available` status prior to creating this resource. + +The following arguments are optional: + +* `kms_key_details` - (Optional) An object describing the KMS key to asssociate. Block is documented below. + +## repository +This configuration block supports the following: + +### bitbucket + +* `connection_arn` - (Required) The Amazon Resource Name (ARN) of an AWS CodeStar Connections connection. +* `name` - (Required) The name of the third party source repository. +* `owner` - (Required) The username for the account that owns the repository. + +### codecommit + +* `name` - (Required) The name of the AWS CodeCommit repository. + +### github_enterprise_server + +* `connection_arn` - (Required) The Amazon Resource Name (ARN) of an AWS CodeStar Connections connection. +* `name` - (Required) The name of the third party source repository. +* `owner` - (Required) The username for the account that owns the repository. + +### s3_bucket + +* `bucket_name` - (Required) The name of the S3 bucket used for associating a new S3 repository. Note: The name must begin with `codeguru-reviewer-`. +* `name` - (Required) The name of the repository in the S3 bucket. + +## kms_key_details +This configuration block supports the following: + +* `encryption_option` - (Optional) The encryption option for a repository association. It is either owned by AWS Key Management Service (KMS) (`AWS_OWNED_CMK`) or customer managed (`CUSTOMER_MANAGED_CMK`). +* `kms_key_id` - (Optional) The ID of the AWS KMS key that is associated with a repository association. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - The Amazon Resource Name (ARN) identifying the repository association. +* `association_id` - The ID of the repository association. +* `connection_arn` - The Amazon Resource Name (ARN) of an AWS CodeStar Connections connection. +* `id` - The Amazon Resource Name (ARN) identifying the repository association. +* `name` - The name of the repository. +* `owner` - The owner of the repository. +* `provider_type` - The provider type of the repository association. +* `state` - The state of the repository association. +* `state_reason` - A description of why the repository association is in the current state. + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `60m`) +* `update` - (Default `180m`) +* `delete` - (Default `90m`) From ee57dbbfff4cbba2529bd05af73395b2fe41f7d2 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:04:04 -0500 Subject: [PATCH 10/15] add changelog --- .changelog/29656.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/29656.txt diff --git a/.changelog/29656.txt b/.changelog/29656.txt new file mode 100644 index 00000000000..0612ee96a86 --- /dev/null +++ b/.changelog/29656.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +codegurureviewer_repository_association +``` \ No newline at end of file From 7b6ffcec05f9ccad7df15d43e1062fa6fd5b2aa6 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:15:16 -0500 Subject: [PATCH 11/15] fix imports --- .../service/codegurureviewer/repository_association_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/codegurureviewer/repository_association_test.go b/internal/service/codegurureviewer/repository_association_test.go index 2f1be83e901..2b07e74f44c 100644 --- a/internal/service/codegurureviewer/repository_association_test.go +++ b/internal/service/codegurureviewer/repository_association_test.go @@ -16,9 +16,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" - "github.com/hashicorp/terraform-provider-aws/names" - tfcodegurureviewer "github.com/hashicorp/terraform-provider-aws/internal/service/codegurureviewer" + "github.com/hashicorp/terraform-provider-aws/names" ) // Repository types of "BitBucket and GitHubEnterpriseServer cannot be tested, as they require their CodeStar Connection to be in "AVAILABLE" status vs "PENDING", requiring console interaction From 1e84504cb7a24414619124b3f65e9bcc28249e80 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Sat, 25 Feb 2023 14:31:15 -0500 Subject: [PATCH 12/15] fix issues found in ci --- .../codegurureviewer/repository_association.go | 2 -- .../repository_association_test.go | 18 +++--------------- internal/service/codegurureviewer/sweep.go | 4 ++-- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/internal/service/codegurureviewer/repository_association.go b/internal/service/codegurureviewer/repository_association.go index 96ffcdfaa56..640c2dbac37 100644 --- a/internal/service/codegurureviewer/repository_association.go +++ b/internal/service/codegurureviewer/repository_association.go @@ -303,7 +303,6 @@ func resourceRepositoryAssociationCreate(ctx context.Context, d *schema.Resource } func resourceRepositoryAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() out, err := findRepositoryAssociationByID(ctx, conn, d.Id()) @@ -373,7 +372,6 @@ func resourceRepositoryAssociationUpdate(ctx context.Context, d *schema.Resource } func resourceRepositoryAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).CodeGuruReviewerConn() log.Printf("[INFO] Deleting CodeGuruReviewer RepositoryAssociation %s", d.Id()) diff --git a/internal/service/codegurureviewer/repository_association_test.go b/internal/service/codegurureviewer/repository_association_test.go index 2b07e74f44c..038b9789b7f 100644 --- a/internal/service/codegurureviewer/repository_association_test.go +++ b/internal/service/codegurureviewer/repository_association_test.go @@ -21,7 +21,7 @@ import ( ) // Repository types of "BitBucket and GitHubEnterpriseServer cannot be tested, as they require their CodeStar Connection to be in "AVAILABLE" status vs "PENDING", requiring console interaction -// However, this has been manually tested succesfully +// However, this has been manually tested successfully func TestAccCodeGuruReviewerRepositoryAssociation_basic(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -281,16 +281,6 @@ func testAccPreCheck(t *testing.T) { } } -func testAccCheckRepositoryAssociationNotRecreated(before, after *codegurureviewer.DescribeRepositoryAssociationOutput) resource.TestCheckFunc { - return func(s *terraform.State) error { - if before, after := aws.StringValue(before.RepositoryAssociation.AssociationArn), aws.StringValue(after.RepositoryAssociation.AssociationArn); before != after { - return create.Error(names.CodeGuruReviewer, create.ErrActionCheckingNotRecreated, tfcodegurureviewer.ResNameRepositoryAssociation, before, errors.New("recreated")) - } - - return nil - } -} - func testAccRepositoryAssociationConfig_basic(rName string) string { return acctest.ConfigCompose(testAccRepositoryAssociation_codecommit_repository(rName), ` resource "aws_codegurureviewer_repository_association" "test" { @@ -388,11 +378,9 @@ resource "aws_s3_bucket" "test" { } func testAccRepositoryAssociation_kms_key() string { - return fmt.Sprint(` - - + return ` resource "aws_kms_key" "test" { deletion_window_in_days = 7 } -`) +` } diff --git a/internal/service/codegurureviewer/sweep.go b/internal/service/codegurureviewer/sweep.go index a802ea54c85..1becaa2747f 100644 --- a/internal/service/codegurureviewer/sweep.go +++ b/internal/service/codegurureviewer/sweep.go @@ -37,8 +37,8 @@ func sweepAssociations(region string) error { return !lastPage } - for _, v := range page.Associations { - r := ResourceAssociation() + for _, v := range page.RepositoryAssociationSummaries { + r := ResourceRepositoryAssociation() d := r.Data(nil) d.SetId(aws.StringValue(v.Name)) From efc8600568f54cb61a6fa2a9db0fb420da3d75a7 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Wed, 1 Mar 2023 07:48:10 -0500 Subject: [PATCH 13/15] update resource for self-registration --- .ci/.semgrep-service-name0.yml | 15 ++++ .ci/.semgrep-service-name1.yml | 73 +++++++++++-------- .ci/.semgrep-service-name2.yml | 43 +++++++---- .ci/.semgrep-service-name3.yml | 14 ---- .../repository_association.go | 1 + .../codegurureviewer/service_package_gen.go | 4 +- 6 files changed, 92 insertions(+), 58 deletions(-) diff --git a/.ci/.semgrep-service-name0.yml b/.ci/.semgrep-service-name0.yml index 4aed7d51792..bad6833f629 100644 --- a/.ci/.semgrep-service-name0.yml +++ b/.ci/.semgrep-service-name0.yml @@ -3231,3 +3231,18 @@ rules: - pattern-regex: "(?i)ConfigService" - pattern-not-regex: ^TestAcc.* severity: WARNING + - id: configservice-in-test-name + languages: + - go + message: Include "ConfigService" in test name + paths: + include: + - internal/service/configservice/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccConfigService" + - pattern-regex: ^TestAcc.* + severity: WARNING diff --git a/.ci/.semgrep-service-name1.yml b/.ci/.semgrep-service-name1.yml index 163c352f671..bc3b92402a5 100644 --- a/.ci/.semgrep-service-name1.yml +++ b/.ci/.semgrep-service-name1.yml @@ -1,5 +1,49 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: configservice-in-const-name + languages: + - go + message: Do not use "ConfigService" in const name inside configservice package + paths: + include: + - internal/service/configservice + patterns: + - pattern: const $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)ConfigService" + severity: WARNING + - id: configservice-in-var-name + languages: + - go + message: Do not use "ConfigService" in var name inside configservice package + paths: + include: + - internal/service/configservice + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)ConfigService" + severity: WARNING + - id: connect-in-func-name + languages: + - go + message: Do not use "Connect" in func name inside connect package + paths: + include: + - internal/service/connect + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Connect" + - pattern-not-regex: .*uickConnect.* + - pattern-not-regex: ^TestAcc.* + severity: WARNING - id: connect-in-test-name languages: - go @@ -3190,32 +3234,3 @@ rules: patterns: - pattern-regex: "(?i)Inspector2" severity: WARNING - - id: inspector2-in-var-name - languages: - - go - message: Do not use "Inspector2" in var name inside inspector2 package - paths: - include: - - internal/service/inspector2 - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Inspector2" - severity: WARNING - - id: inspectorv2-in-func-name - languages: - - go - message: Do not use "inspectorv2" in func name inside inspector2 package - paths: - include: - - internal/service/inspector2 - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)inspectorv2" - - pattern-not-regex: ^TestAcc.* - severity: WARNING diff --git a/.ci/.semgrep-service-name2.yml b/.ci/.semgrep-service-name2.yml index 33afded1556..57b2e087ff5 100644 --- a/.ci/.semgrep-service-name2.yml +++ b/.ci/.semgrep-service-name2.yml @@ -1,5 +1,34 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: + - id: inspector2-in-var-name + languages: + - go + message: Do not use "Inspector2" in var name inside inspector2 package + paths: + include: + - internal/service/inspector2 + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Inspector2" + severity: WARNING + - id: inspectorv2-in-func-name + languages: + - go + message: Do not use "inspectorv2" in func name inside inspector2 package + paths: + include: + - internal/service/inspector2 + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)inspectorv2" + - pattern-not-regex: ^TestAcc.* + severity: WARNING - id: inspectorv2-in-const-name languages: - go @@ -3201,17 +3230,3 @@ rules: patterns: - pattern-regex: "(?i)RDS" severity: WARNING - - id: rds-in-var-name - languages: - - go - message: Do not use "RDS" in var name inside rds package - paths: - include: - - internal/service/rds - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)RDS" - severity: WARNING diff --git a/.ci/.semgrep-service-name3.yml b/.ci/.semgrep-service-name3.yml index 5c6daecba19..a8da3978a5d 100644 --- a/.ci/.semgrep-service-name3.yml +++ b/.ci/.semgrep-service-name3.yml @@ -1,19 +1,5 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: - - id: rds-in-const-name - languages: - - go - message: Do not use "RDS" in const name inside rds package - paths: - include: - - internal/service/rds - patterns: - - pattern: const $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)RDS" - severity: WARNING - id: rds-in-var-name languages: - go diff --git a/internal/service/codegurureviewer/repository_association.go b/internal/service/codegurureviewer/repository_association.go index 640c2dbac37..68d3301b31a 100644 --- a/internal/service/codegurureviewer/repository_association.go +++ b/internal/service/codegurureviewer/repository_association.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +// @SDKResource("aws_codegurureviewer_repository_association") func ResourceRepositoryAssociation() *schema.Resource { return &schema.Resource{ diff --git a/internal/service/codegurureviewer/service_package_gen.go b/internal/service/codegurureviewer/service_package_gen.go index 208c78d4dc1..9c878e78698 100644 --- a/internal/service/codegurureviewer/service_package_gen.go +++ b/internal/service/codegurureviewer/service_package_gen.go @@ -26,7 +26,9 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) map[string]func() * } func (p *servicePackage) SDKResources(ctx context.Context) map[string]func() *schema.Resource { - return map[string]func() *schema.Resource{} + return map[string]func() *schema.Resource{ + "aws_codegurureviewer_repository_association": ResourceRepositoryAssociation, + } } func (p *servicePackage) ServicePackageName() string { From f4a20e5ddc8ce4dc6d467b100c414fdc6aa3bd92 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Thu, 2 Mar 2023 09:17:57 -0500 Subject: [PATCH 14/15] remove testing.short logic, as it is not needed --- .../codegurureviewer/repository_association_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/internal/service/codegurureviewer/repository_association_test.go b/internal/service/codegurureviewer/repository_association_test.go index 038b9789b7f..a08acfbed0e 100644 --- a/internal/service/codegurureviewer/repository_association_test.go +++ b/internal/service/codegurureviewer/repository_association_test.go @@ -23,9 +23,6 @@ import ( // Repository types of "BitBucket and GitHubEnterpriseServer cannot be tested, as they require their CodeStar Connection to be in "AVAILABLE" status vs "PENDING", requiring console interaction // However, this has been manually tested successfully func TestAccCodeGuruReviewerRepositoryAssociation_basic(t *testing.T) { - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } ctx := acctest.Context(t) var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -61,9 +58,6 @@ func TestAccCodeGuruReviewerRepositoryAssociation_basic(t *testing.T) { } func TestAccCodeGuruReviewerRepositoryAssociation_KMSKey(t *testing.T) { - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } ctx := acctest.Context(t) var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -99,9 +93,6 @@ func TestAccCodeGuruReviewerRepositoryAssociation_KMSKey(t *testing.T) { } func TestAccCodeGuruReviewerRepositoryAssociation_S3Repository(t *testing.T) { - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } ctx := acctest.Context(t) var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput rName := "codeguru-reviewer-" + sdkacctest.RandString(10) @@ -183,9 +174,6 @@ func TestAccCodeGuruReviewerRepositoryAssociation_tags(t *testing.T) { } func TestAccCodeGuruReviewerRepositoryAssociation_disappears(t *testing.T) { - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } ctx := acctest.Context(t) var repositoryassociation codegurureviewer.DescribeRepositoryAssociationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) From 52a897c12fef61793ec6bb4dc7732853d2489051 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 12 Mar 2023 15:21:02 -0400 Subject: [PATCH 15/15] r/aws_codegurureviewer_repository_association: Cosmetics. --- .../repository_association_test.go | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/internal/service/codegurureviewer/repository_association_test.go b/internal/service/codegurureviewer/repository_association_test.go index a08acfbed0e..a1a4dbd94af 100644 --- a/internal/service/codegurureviewer/repository_association_test.go +++ b/internal/service/codegurureviewer/repository_association_test.go @@ -32,7 +32,7 @@ func TestAccCodeGuruReviewerRepositoryAssociation_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) - testAccPreCheck(t) + testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -67,7 +67,7 @@ func TestAccCodeGuruReviewerRepositoryAssociation_KMSKey(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) - testAccPreCheck(t) + testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -102,7 +102,7 @@ func TestAccCodeGuruReviewerRepositoryAssociation_S3Repository(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) - testAccPreCheck(t) + testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -138,7 +138,7 @@ func TestAccCodeGuruReviewerRepositoryAssociation_tags(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) - testAccPreCheck(t) + testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -182,7 +182,7 @@ func TestAccCodeGuruReviewerRepositoryAssociation_disappears(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(t, codegurureviewer.EndpointsID) - testAccPreCheck(t) + testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, codegurureviewer.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -253,9 +253,8 @@ func testAccCheckRepositoryAssociationExists(ctx context.Context, name string, r } } -func testAccPreCheck(t *testing.T) { +func testAccPreCheck(ctx context.Context, t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).CodeGuruReviewerConn() - ctx := context.Background() input := &codegurureviewer.ListRepositoryAssociationsInput{} _, err := conn.ListRepositoryAssociationsWithContext(ctx, input) @@ -330,7 +329,11 @@ resource "aws_codegurureviewer_repository_association" "test" { } func testAccRepositoryAssociationConfig_s3_repository(rName string) string { - return acctest.ConfigCompose(testAccRepositoryAssociation_s3_repository(rName), ` + return fmt.Sprintf(` +resource "aws_s3_bucket" "test" { + bucket = %[1]q +} + resource "aws_codegurureviewer_repository_association" "test" { repository { s3_bucket { @@ -339,7 +342,7 @@ resource "aws_codegurureviewer_repository_association" "test" { } } } -`) +`, rName) } func testAccRepositoryAssociation_codecommit_repository(rName string) string { @@ -356,15 +359,6 @@ resource "aws_codecommit_repository" "test" { `, rName) } -func testAccRepositoryAssociation_s3_repository(rName string) string { - return fmt.Sprintf(` - -resource "aws_s3_bucket" "test" { - bucket = %[1]q -} -`, rName) -} - func testAccRepositoryAssociation_kms_key() string { return ` resource "aws_kms_key" "test" {