From 7fcd8d1673d8f10582fc7d766649cdd8651ae2af Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 29 Mar 2020 17:26:01 +0300 Subject: [PATCH 01/12] support initial report group --- aws/provider.go | 1 + aws/resource_aws_codebuild_report_groups.go | 273 ++++++++++++++++++ ...source_aws_codebuild_report_groups_test.go | 159 ++++++++++ 3 files changed, 433 insertions(+) create mode 100644 aws/resource_aws_codebuild_report_groups.go create mode 100644 aws/resource_aws_codebuild_report_groups_test.go diff --git a/aws/provider.go b/aws/provider.go index e8e439536f5..8c9c688dd27 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -479,6 +479,7 @@ func Provider() *schema.Provider { "aws_codecommit_repository": resourceAwsCodeCommitRepository(), "aws_codecommit_trigger": resourceAwsCodeCommitTrigger(), "aws_codebuild_project": resourceAwsCodeBuildProject(), + "aws_codebuild_report_groups": resourceAwsCodeBuildReportGroups(), "aws_codebuild_source_credential": resourceAwsCodeBuildSourceCredential(), "aws_codebuild_webhook": resourceAwsCodeBuildWebhook(), "aws_codepipeline": resourceAwsCodePipeline(), diff --git a/aws/resource_aws_codebuild_report_groups.go b/aws/resource_aws_codebuild_report_groups.go new file mode 100644 index 00000000000..cdafaff3683 --- /dev/null +++ b/aws/resource_aws_codebuild_report_groups.go @@ -0,0 +1,273 @@ +package aws + +import ( + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codebuild" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceAwsCodeBuildReportGroups() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsCodeBuildReportGroupsCreate, + Read: resourceAwsCodeBuildReportGroupsRead, + Update: resourceAwsCodeBuildReportGroupsUpdate, + Delete: resourceAwsCodeBuildReportGroupsDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(2, 128), + }, + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + codebuild.ReportTypeTest, + }, false), + }, + "export_config": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + codebuild.ReportExportConfigTypeNoExport, + codebuild.ReportExportConfigTypeS3, + }, false), + }, + "s3_destination": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket": { + Type: schema.TypeString, + Required: true, + }, + "encryption_disabled": { + Type: schema.TypeBool, + Optional: true, + }, + "encryption_key": { + Type: schema.TypeString, + Required: true, + }, + "packaging": { + Type: schema.TypeString, + Optional: true, + Default: codebuild.ReportPackagingTypeNone, + ValidateFunc: validation.StringInSlice([]string{ + codebuild.ReportPackagingTypeNone, + codebuild.ReportPackagingTypeZip, + }, false), + }, + "path": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + "created": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceAwsCodeBuildReportGroupsCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).codebuildconn + createOpts := &codebuild.CreateReportGroupInput{ + Name: aws.String(d.Get("name").(string)), + Type: aws.String(d.Get("type").(string)), + ExportConfig: expandAwsCodeBuildReportGroupsExportConfig(d.Get("export_config").([]interface{})), + } + + resp, err := conn.CreateReportGroup(createOpts) + if err != nil { + return fmt.Errorf("Error creating CodeBuild Report Groups: %s", err) + } + + d.SetId(aws.StringValue(resp.ReportGroup.Arn)) + + return resourceAwsCodeBuildReportGroupsRead(d, meta) +} + +func resourceAwsCodeBuildReportGroupsRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).codebuildconn + + resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ + ReportGroupArns: aws.StringSlice([]string{d.Id()}), + }) + if err != nil { + return fmt.Errorf("Error Listing CodeBuild Report Groups: %s", err) + } + + if len(resp.ReportGroups) == 0 { + return fmt.Errorf("no matches found for CodeBuild Report Groups: %s", d.Id()) + } + + if len(resp.ReportGroups) > 1 { + return fmt.Errorf("multiple matches found for CodeBuild Report Groups: %s", d.Id()) + } + + reportGroups := resp.ReportGroups[0] + + if reportGroups == nil { + log.Printf("[WARN] CodeBuild Report Groups (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + d.Set("arn", reportGroups.Arn) + d.Set("type", reportGroups.Type) + d.Set("name", reportGroups.Name) + + if err := d.Set("created", reportGroups.Created.Format(time.RFC3339)); err != nil { + return fmt.Errorf("error setting created: %s", err) + } + + if err := d.Set("export_config", flattenAwsCodeBuildReportGroupsExportConfig(reportGroups.ExportConfig)); err != nil { + return fmt.Errorf("error setting export config: %s", err) + } + + return nil +} + +func resourceAwsCodeBuildReportGroupsUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).codebuildconn + + if d.HasChange("export_config") { + input := &codebuild.UpdateReportGroupInput{ + Arn: aws.String(d.Id()), + ExportConfig: expandAwsCodeBuildReportGroupsExportConfig(d.Get("export_config").([]interface{})), + } + + _, err := conn.UpdateReportGroup(input) + if err != nil { + return fmt.Errorf("Error updating CodeBuild Report Groups: %s", err) + } + } + + return resourceAwsCodeBuildReportGroupsRead(d, meta) +} + +func resourceAwsCodeBuildReportGroupsDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).codebuildconn + + deleteOpts := &codebuild.DeleteReportGroupInput{ + Arn: aws.String(d.Id()), + } + + if _, err := conn.DeleteReportGroup(deleteOpts); err != nil { + return fmt.Errorf("Error deleting CodeBuild Report Groups(%s): %s", d.Id(), err) + } + + return nil +} + +func expandAwsCodeBuildReportGroupsExportConfig(config []interface{}) *codebuild.ReportExportConfig { + if len(config) == 0 { + return nil + } + + s := config[0].(map[string]interface{}) + exportConfig := &codebuild.ReportExportConfig{} + + if v, ok := s["type"]; ok { + exportConfig.ExportConfigType = aws.String(v.(string)) + } + + if v, ok := s["s3_destination"]; ok { + exportConfig.S3Destination = expandAwsCodeBuildReportGroupsS3ReportExportConfig(v.([]interface{})) + } + + return exportConfig +} + +func flattenAwsCodeBuildReportGroupsExportConfig(config *codebuild.ReportExportConfig) []map[string]interface{} { + settings := make(map[string]interface{}) + + if config == nil { + return nil + } + + settings["s3_destination"] = flattenAwsCodeBuildReportGroupsS3ReportExportConfig(config.S3Destination) + settings["type"] = aws.StringValue(config.ExportConfigType) + + return []map[string]interface{}{settings} +} + +func expandAwsCodeBuildReportGroupsS3ReportExportConfig(config []interface{}) *codebuild.S3ReportExportConfig { + if len(config) == 0 { + return nil + } + + s := config[0].(map[string]interface{}) + s3ReportExportConfig := &codebuild.S3ReportExportConfig{} + + if v, ok := s["bucket"]; ok { + s3ReportExportConfig.Bucket = aws.String(v.(string)) + } + if v, ok := s["encryption_disabled"]; ok { + s3ReportExportConfig.EncryptionDisabled = aws.Bool(v.(bool)) + } + + if v, ok := s["encryption_key"]; ok { + s3ReportExportConfig.EncryptionKey = aws.String(v.(string)) + } + + if v, ok := s["packaging"]; ok { + s3ReportExportConfig.Packaging = aws.String(v.(string)) + } + + if v, ok := s["path"]; ok { + s3ReportExportConfig.Path = aws.String(v.(string)) + } + + return s3ReportExportConfig +} + +func flattenAwsCodeBuildReportGroupsS3ReportExportConfig(config *codebuild.S3ReportExportConfig) []map[string]interface{} { + settings := make(map[string]interface{}) + + if config == nil { + return nil + } + + settings["path"] = aws.StringValue(config.Path) + settings["bucket"] = aws.StringValue(config.Bucket) + settings["packaging"] = aws.StringValue(config.Packaging) + settings["encryption_disabled"] = aws.BoolValue(config.EncryptionDisabled) + + if config.EncryptionKey != nil { + settings["encryption_key"] = aws.StringValue(config.EncryptionKey) + } + + return []map[string]interface{}{settings} +} diff --git a/aws/resource_aws_codebuild_report_groups_test.go b/aws/resource_aws_codebuild_report_groups_test.go new file mode 100644 index 00000000000..965741e3a22 --- /dev/null +++ b/aws/resource_aws_codebuild_report_groups_test.go @@ -0,0 +1,159 @@ +package aws + +import ( + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codebuild" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccAWSCodeBuildReportGroups_Basic(t *testing.T) { + var reportGroup codebuild.ReportGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_report_groups.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildReportGroupsBasicConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckAWSCodeBuildReportGroupsDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codebuild_report_groups" { + continue + } + + resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ + ReportGroupArns: aws.StringSlice([]string{rs.Primary.ID}), + }) + if err != nil { + return err + } + + if len(resp.ReportGroups) == 0 { + return nil + } + + for _, reportGroup := range resp.ReportGroups { + if rs.Primary.ID == aws.StringValue(reportGroup.Arn) { + return fmt.Errorf("Found Report Groups %s", rs.Primary.ID) + } + } + } + return nil +} + +func testAccCheckAWSCodeBuildReportGroupsExists(name string, ReportGroups *codebuild.ReportGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ + ReportGroupArns: aws.StringSlice([]string{rs.Primary.ID}), + }) + if err != nil { + return err + } + + if len(resp.ReportGroups) == 0 { + return fmt.Errorf("Source Credential %s not found", rs.Primary.ID) + } + + for _, reportGroup := range resp.ReportGroups { + if rs.Primary.ID == aws.StringValue(reportGroup.Arn) { + *ReportGroups = *reportGroup + return nil + } + } + + return fmt.Errorf("Report Groups %s not found", rs.Primary.ID) + } +} + +func testAccAWSCodeBuildReportGroupsBasicConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 + + policy = < Date: Sun, 29 Mar 2020 18:16:27 +0300 Subject: [PATCH 02/12] add more tests --- ...=> resource_aws_codebuild_report_group.go} | 40 +-- ...esource_aws_codebuild_report_group_test.go | 246 ++++++++++++++++++ ...source_aws_codebuild_report_groups_test.go | 159 ----------- 3 files changed, 266 insertions(+), 179 deletions(-) rename aws/{resource_aws_codebuild_report_groups.go => resource_aws_codebuild_report_group.go} (78%) create mode 100644 aws/resource_aws_codebuild_report_group_test.go delete mode 100644 aws/resource_aws_codebuild_report_groups_test.go diff --git a/aws/resource_aws_codebuild_report_groups.go b/aws/resource_aws_codebuild_report_group.go similarity index 78% rename from aws/resource_aws_codebuild_report_groups.go rename to aws/resource_aws_codebuild_report_group.go index cdafaff3683..989e29be0b0 100644 --- a/aws/resource_aws_codebuild_report_groups.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -11,12 +11,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -func resourceAwsCodeBuildReportGroups() *schema.Resource { +func resourceAwsCodeBuildReportGroup() *schema.Resource { return &schema.Resource{ - Create: resourceAwsCodeBuildReportGroupsCreate, - Read: resourceAwsCodeBuildReportGroupsRead, - Update: resourceAwsCodeBuildReportGroupsUpdate, - Delete: resourceAwsCodeBuildReportGroupsDelete, + Create: resourceAwsCodeBuildReportGroupCreate, + Read: resourceAwsCodeBuildReportGroupRead, + Update: resourceAwsCodeBuildReportGroupUpdate, + Delete: resourceAwsCodeBuildReportGroupDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -100,12 +100,12 @@ func resourceAwsCodeBuildReportGroups() *schema.Resource { } } -func resourceAwsCodeBuildReportGroupsCreate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsCodeBuildReportGroupCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn createOpts := &codebuild.CreateReportGroupInput{ Name: aws.String(d.Get("name").(string)), Type: aws.String(d.Get("type").(string)), - ExportConfig: expandAwsCodeBuildReportGroupsExportConfig(d.Get("export_config").([]interface{})), + ExportConfig: expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})), } resp, err := conn.CreateReportGroup(createOpts) @@ -115,10 +115,10 @@ func resourceAwsCodeBuildReportGroupsCreate(d *schema.ResourceData, meta interfa d.SetId(aws.StringValue(resp.ReportGroup.Arn)) - return resourceAwsCodeBuildReportGroupsRead(d, meta) + return resourceAwsCodeBuildReportGroupRead(d, meta) } -func resourceAwsCodeBuildReportGroupsRead(d *schema.ResourceData, meta interface{}) error { +func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ @@ -152,20 +152,20 @@ func resourceAwsCodeBuildReportGroupsRead(d *schema.ResourceData, meta interface return fmt.Errorf("error setting created: %s", err) } - if err := d.Set("export_config", flattenAwsCodeBuildReportGroupsExportConfig(reportGroups.ExportConfig)); err != nil { + if err := d.Set("export_config", flattenAwsCodeBuildReportGroupExportConfig(reportGroups.ExportConfig)); err != nil { return fmt.Errorf("error setting export config: %s", err) } return nil } -func resourceAwsCodeBuildReportGroupsUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsCodeBuildReportGroupUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn if d.HasChange("export_config") { input := &codebuild.UpdateReportGroupInput{ Arn: aws.String(d.Id()), - ExportConfig: expandAwsCodeBuildReportGroupsExportConfig(d.Get("export_config").([]interface{})), + ExportConfig: expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})), } _, err := conn.UpdateReportGroup(input) @@ -174,10 +174,10 @@ func resourceAwsCodeBuildReportGroupsUpdate(d *schema.ResourceData, meta interfa } } - return resourceAwsCodeBuildReportGroupsRead(d, meta) + return resourceAwsCodeBuildReportGroupRead(d, meta) } -func resourceAwsCodeBuildReportGroupsDelete(d *schema.ResourceData, meta interface{}) error { +func resourceAwsCodeBuildReportGroupDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn deleteOpts := &codebuild.DeleteReportGroupInput{ @@ -191,7 +191,7 @@ func resourceAwsCodeBuildReportGroupsDelete(d *schema.ResourceData, meta interfa return nil } -func expandAwsCodeBuildReportGroupsExportConfig(config []interface{}) *codebuild.ReportExportConfig { +func expandAwsCodeBuildReportGroupExportConfig(config []interface{}) *codebuild.ReportExportConfig { if len(config) == 0 { return nil } @@ -204,26 +204,26 @@ func expandAwsCodeBuildReportGroupsExportConfig(config []interface{}) *codebuild } if v, ok := s["s3_destination"]; ok { - exportConfig.S3Destination = expandAwsCodeBuildReportGroupsS3ReportExportConfig(v.([]interface{})) + exportConfig.S3Destination = expandAwsCodeBuildReportGroupS3ReportExportConfig(v.([]interface{})) } return exportConfig } -func flattenAwsCodeBuildReportGroupsExportConfig(config *codebuild.ReportExportConfig) []map[string]interface{} { +func flattenAwsCodeBuildReportGroupExportConfig(config *codebuild.ReportExportConfig) []map[string]interface{} { settings := make(map[string]interface{}) if config == nil { return nil } - settings["s3_destination"] = flattenAwsCodeBuildReportGroupsS3ReportExportConfig(config.S3Destination) + settings["s3_destination"] = flattenAwsCodeBuildReportGroupS3ReportExportConfig(config.S3Destination) settings["type"] = aws.StringValue(config.ExportConfigType) return []map[string]interface{}{settings} } -func expandAwsCodeBuildReportGroupsS3ReportExportConfig(config []interface{}) *codebuild.S3ReportExportConfig { +func expandAwsCodeBuildReportGroupS3ReportExportConfig(config []interface{}) *codebuild.S3ReportExportConfig { if len(config) == 0 { return nil } @@ -253,7 +253,7 @@ func expandAwsCodeBuildReportGroupsS3ReportExportConfig(config []interface{}) *c return s3ReportExportConfig } -func flattenAwsCodeBuildReportGroupsS3ReportExportConfig(config *codebuild.S3ReportExportConfig) []map[string]interface{} { +func flattenAwsCodeBuildReportGroupS3ReportExportConfig(config *codebuild.S3ReportExportConfig) []map[string]interface{} { settings := make(map[string]interface{}) if config == nil { diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go new file mode 100644 index 00000000000..68795c96d62 --- /dev/null +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -0,0 +1,246 @@ +package aws + +import ( + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/codebuild" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccAWSCodeBuildReportGroups_basic(t *testing.T) { + var reportGroup codebuild.ReportGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_report_groups.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildReportGroupsBasicConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSCodeBuildReportGroups_updated(t *testing.T) { + var reportGroup codebuild.ReportGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_report_groups.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildReportGroupsFullConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some"), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildReportGroupsUpdatedConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "ZIP"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "true"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some2"), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + ), + }, + }, + }) +} + +func testAccCheckAWSCodeBuildReportGroupsDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codebuild_report_groups" { + continue + } + + resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ + ReportGroupArns: aws.StringSlice([]string{rs.Primary.ID}), + }) + if err != nil { + return err + } + + if len(resp.ReportGroups) == 0 { + return nil + } + + for _, reportGroup := range resp.ReportGroups { + if rs.Primary.ID == aws.StringValue(reportGroup.Arn) { + return fmt.Errorf("Found Report Groups %s", rs.Primary.ID) + } + } + } + return nil +} + +func testAccCheckAWSCodeBuildReportGroupsExists(name string, ReportGroups *codebuild.ReportGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ + ReportGroupArns: aws.StringSlice([]string{rs.Primary.ID}), + }) + if err != nil { + return err + } + + if len(resp.ReportGroups) == 0 { + return fmt.Errorf("Source Credential %s not found", rs.Primary.ID) + } + + for _, reportGroup := range resp.ReportGroups { + if rs.Primary.ID == aws.StringValue(reportGroup.Arn) { + *ReportGroups = *reportGroup + return nil + } + } + + return fmt.Errorf("Report Groups %s not found", rs.Primary.ID) + } +} + +func testAccAWSCodeBuildReportGroupsBasicConfigBase(rName string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 + + policy = < Date: Sun, 29 Mar 2020 18:17:56 +0300 Subject: [PATCH 03/12] rename provider name --- aws/provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/provider.go b/aws/provider.go index 8c9c688dd27..bc49427d325 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -479,7 +479,7 @@ func Provider() *schema.Provider { "aws_codecommit_repository": resourceAwsCodeCommitRepository(), "aws_codecommit_trigger": resourceAwsCodeCommitTrigger(), "aws_codebuild_project": resourceAwsCodeBuildProject(), - "aws_codebuild_report_groups": resourceAwsCodeBuildReportGroups(), + "aws_codebuild_report_group": resourceAwsCodeBuildReportGroup(), "aws_codebuild_source_credential": resourceAwsCodeBuildSourceCredential(), "aws_codebuild_webhook": resourceAwsCodeBuildWebhook(), "aws_codepipeline": resourceAwsCodePipeline(), From 46000d4533ce54a7d39f1db5f572065a549668c7 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 29 Mar 2020 19:23:18 +0300 Subject: [PATCH 04/12] add disappears test --- aws/resource_aws_codebuild_report_group.go | 18 +-- ...esource_aws_codebuild_report_group_test.go | 104 +++++++++++------- 2 files changed, 77 insertions(+), 45 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index 989e29be0b0..eef282ae752 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -129,30 +129,32 @@ func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{ } if len(resp.ReportGroups) == 0 { - return fmt.Errorf("no matches found for CodeBuild Report Groups: %s", d.Id()) + log.Printf("[WARN] CodeBuild Report Groups (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil } if len(resp.ReportGroups) > 1 { return fmt.Errorf("multiple matches found for CodeBuild Report Groups: %s", d.Id()) } - reportGroups := resp.ReportGroups[0] + reportGroup := resp.ReportGroups[0] - if reportGroups == nil { + if reportGroup == nil { log.Printf("[WARN] CodeBuild Report Groups (%s) not found, removing from state", d.Id()) d.SetId("") return nil } - d.Set("arn", reportGroups.Arn) - d.Set("type", reportGroups.Type) - d.Set("name", reportGroups.Name) + d.Set("arn", reportGroup.Arn) + d.Set("type", reportGroup.Type) + d.Set("name", reportGroup.Name) - if err := d.Set("created", reportGroups.Created.Format(time.RFC3339)); err != nil { + if err := d.Set("created", reportGroup.Created.Format(time.RFC3339)); err != nil { return fmt.Errorf("error setting created: %s", err) } - if err := d.Set("export_config", flattenAwsCodeBuildReportGroupExportConfig(reportGroups.ExportConfig)); err != nil { + if err := d.Set("export_config", flattenAwsCodeBuildReportGroupExportConfig(reportGroup.ExportConfig)); err != nil { return fmt.Errorf("error setting export config: %s", err) } diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go index 68795c96d62..4e36daf7e9f 100644 --- a/aws/resource_aws_codebuild_report_group_test.go +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -13,27 +13,27 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccAWSCodeBuildReportGroups_basic(t *testing.T) { +func TestAccAWSCodeBuildReportGroup_basic(t *testing.T) { var reportGroup codebuild.ReportGroup rName := acctest.RandomWithPrefix("tf-acc-test") - resourceName := "aws_codebuild_report_groups.test" + resourceName := "aws_codebuild_report_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckAWSCodeBuildReportGroupsDestroy, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildReportGroupsBasicConfig(rName), + Config: testAccAWSCodeBuildReportGroupBasicConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), ), }, { @@ -45,20 +45,20 @@ func TestAccAWSCodeBuildReportGroups_basic(t *testing.T) { }) } -func TestAccAWSCodeBuildReportGroups_updated(t *testing.T) { +func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { var reportGroup codebuild.ReportGroup rName := acctest.RandomWithPrefix("tf-acc-test") - resourceName := "aws_codebuild_report_groups.test" + resourceName := "aws_codebuild_report_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckAWSCodeBuildReportGroupsDestroy, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildReportGroupsFullConfig(rName), + Config: testAccAWSCodeBuildReportGroupFullConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), @@ -66,7 +66,7 @@ func TestAccAWSCodeBuildReportGroups_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), ), }, { @@ -75,9 +75,9 @@ func TestAccAWSCodeBuildReportGroups_updated(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodeBuildReportGroupsUpdatedConfig(rName), + Config: testAccAWSCodeBuildReportGroupUpdatedConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSCodeBuildReportGroupsExists(resourceName, &reportGroup), + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), @@ -85,18 +85,40 @@ func TestAccAWSCodeBuildReportGroups_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "ZIP"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "true"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some2"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/`)), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), ), }, }, }) } -func testAccCheckAWSCodeBuildReportGroupsDestroy(s *terraform.State) error { +func TestAccAWSCodeBuildReportGroup_disappears(t *testing.T) { + var reportGroup codebuild.ReportGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_report_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildReportGroupBasicConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), + testAccCheckAWSCodeBuildReportGroupDisappears(&reportGroup), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckAWSCodeBuildReportGroupDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).codebuildconn for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_codebuild_report_groups" { + if rs.Type != "aws_codebuild_report_group" { continue } @@ -120,7 +142,7 @@ func testAccCheckAWSCodeBuildReportGroupsDestroy(s *terraform.State) error { return nil } -func testAccCheckAWSCodeBuildReportGroupsExists(name string, ReportGroups *codebuild.ReportGroup) resource.TestCheckFunc { +func testAccCheckAWSCodeBuildReportGroupExists(name string, reportGroup *codebuild.ReportGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -136,22 +158,30 @@ func testAccCheckAWSCodeBuildReportGroupsExists(name string, ReportGroups *codeb return err } - if len(resp.ReportGroups) == 0 { - return fmt.Errorf("Source Credential %s not found", rs.Primary.ID) + if len(resp.ReportGroups) != 1 || + aws.StringValue(resp.ReportGroups[0].Arn) != rs.Primary.ID { + return fmt.Errorf("Report Group %s not found", rs.Primary.ID) } - for _, reportGroup := range resp.ReportGroups { - if rs.Primary.ID == aws.StringValue(reportGroup.Arn) { - *ReportGroups = *reportGroup - return nil - } - } + *reportGroup = *resp.ReportGroups[0] + + return nil + } +} + +func testAccCheckAWSCodeBuildReportGroupDisappears(reportGroup *codebuild.ReportGroup) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + _, err := conn.DeleteReportGroup(&codebuild.DeleteReportGroupInput{ + Arn: reportGroup.Arn, + }) - return fmt.Errorf("Report Groups %s not found", rs.Primary.ID) + return err } } -func testAccAWSCodeBuildReportGroupsBasicConfigBase(rName string) string { +func testAccAWSCodeBuildReportGroupBasicConfigBase(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { description = %[1]q @@ -182,10 +212,10 @@ resource "aws_s3_bucket" "test" { `, rName) } -func testAccAWSCodeBuildReportGroupsBasicConfig(rName string) string { - return testAccAWSCodeBuildReportGroupsBasicConfigBase(rName) + +func testAccAWSCodeBuildReportGroupBasicConfig(rName string) string { + return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + fmt.Sprintf(` -resource "aws_codebuild_report_groups" "test" { +resource "aws_codebuild_report_group" "test" { name = %[1]q type = "TEST" @@ -201,10 +231,10 @@ resource "aws_codebuild_report_groups" "test" { `, rName) } -func testAccAWSCodeBuildReportGroupsFullConfig(rName string) string { - return testAccAWSCodeBuildReportGroupsBasicConfigBase(rName) + +func testAccAWSCodeBuildReportGroupFullConfig(rName string) string { + return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + fmt.Sprintf(` -resource "aws_codebuild_report_groups" "test" { +resource "aws_codebuild_report_group" "test" { name = %[1]q type = "TEST" @@ -223,10 +253,10 @@ resource "aws_codebuild_report_groups" "test" { `, rName) } -func testAccAWSCodeBuildReportGroupsUpdatedConfig(rName string) string { - return testAccAWSCodeBuildReportGroupsBasicConfigBase(rName) + +func testAccAWSCodeBuildReportGroupUpdatedConfig(rName string) string { + return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + fmt.Sprintf(` -resource "aws_codebuild_report_groups" "test" { +resource "aws_codebuild_report_group" "test" { name = %[1]q type = "TEST" From 92b25bc015456bfc579e1358533b8cdf97887ef9 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 29 Mar 2020 19:39:49 +0300 Subject: [PATCH 05/12] add docs --- .../r/codebuild_report_group.html.markdown | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 website/docs/r/codebuild_report_group.html.markdown diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown new file mode 100644 index 00000000000..3997ca71d55 --- /dev/null +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -0,0 +1,98 @@ +--- +subcategory: "CodeBuild" +layout: "aws" +page_title: "AWS: aws_codebuild_report_group" +description: |- + Provides a CodeBuild Report Group resource. +--- + +# Resource: aws_codebuild_report_group + +Provides a CodeBuild Report Groups Resource. + +## Example Usage + +```hcl +resource "aws_kms_key" "example" { + description = "my test kms key" + deletion_window_in_days = 7 + + policy = < Date: Fri, 10 Jul 2020 19:59:45 +0300 Subject: [PATCH 06/12] add tagging support change disappears test --- aws/resource_aws_codebuild_report_group.go | 31 +++-- ...esource_aws_codebuild_report_group_test.go | 106 +++++++++++++++--- .../r/codebuild_report_group.html.markdown | 3 +- 3 files changed, 117 insertions(+), 23 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index eef282ae752..e3f51606387 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/service/codebuild" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) func resourceAwsCodeBuildReportGroup() *schema.Resource { @@ -96,6 +97,7 @@ func resourceAwsCodeBuildReportGroup() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "tags": tagsSchema(), }, } } @@ -106,6 +108,7 @@ func resourceAwsCodeBuildReportGroupCreate(d *schema.ResourceData, meta interfac Name: aws.String(d.Get("name").(string)), Type: aws.String(d.Get("type").(string)), ExportConfig: expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})), + Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().CodebuildTags(), } resp, err := conn.CreateReportGroup(createOpts) @@ -120,6 +123,7 @@ func resourceAwsCodeBuildReportGroupCreate(d *schema.ResourceData, meta interfac func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig resp, err := conn.BatchGetReportGroups(&codebuild.BatchGetReportGroupsInput{ ReportGroupArns: aws.StringSlice([]string{d.Id()}), @@ -134,10 +138,6 @@ func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{ return nil } - if len(resp.ReportGroups) > 1 { - return fmt.Errorf("multiple matches found for CodeBuild Report Groups: %s", d.Id()) - } - reportGroup := resp.ReportGroups[0] if reportGroup == nil { @@ -158,18 +158,33 @@ func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("error setting export config: %s", err) } + if err := d.Set("tags", keyvaluetags.CodebuildKeyValueTags(reportGroup.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + return nil } func resourceAwsCodeBuildReportGroupUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).codebuildconn + input := &codebuild.UpdateReportGroupInput{ + Arn: aws.String(d.Id()), + } + + updateNeeded := false + if d.HasChange("export_config") { - input := &codebuild.UpdateReportGroupInput{ - Arn: aws.String(d.Id()), - ExportConfig: expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})), - } + input.ExportConfig = expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})) + updateNeeded = true + } + + if d.HasChange("tags") { + input.Tags = keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().CodebuildTags() + updateNeeded = true + } + if updateNeeded { _, err := conn.UpdateReportGroup(input) if err != nil { return fmt.Errorf("Error updating CodeBuild Report Groups: %s", err) diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go index 4e36daf7e9f..cab225c2fca 100644 --- a/aws/resource_aws_codebuild_report_group_test.go +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -34,6 +34,7 @@ func TestAccAWSCodeBuildReportGroup_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, { @@ -92,6 +93,50 @@ func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { }) } +func TestAccAWSCodeBuildReportGroup_tags(t *testing.T) { + var reportGroup codebuild.ReportGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_report_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildReportGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildReportGroupConfigTags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildReportGroupConfigTags2(rName, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAWSCodeBuildReportGroupConfigTags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildReportGroup_disappears(t *testing.T) { var reportGroup codebuild.ReportGroup rName := acctest.RandomWithPrefix("tf-acc-test") @@ -106,7 +151,7 @@ func TestAccAWSCodeBuildReportGroup_disappears(t *testing.T) { Config: testAccAWSCodeBuildReportGroupBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), - testAccCheckAWSCodeBuildReportGroupDisappears(&reportGroup), + testAccCheckResourceDisappears(testAccProvider, resourceAwsCodeBuildReportGroup(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -169,18 +214,6 @@ func testAccCheckAWSCodeBuildReportGroupExists(name string, reportGroup *codebui } } -func testAccCheckAWSCodeBuildReportGroupDisappears(reportGroup *codebuild.ReportGroup) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).codebuildconn - - _, err := conn.DeleteReportGroup(&codebuild.DeleteReportGroupInput{ - Arn: reportGroup.Arn, - }) - - return err - } -} - func testAccAWSCodeBuildReportGroupBasicConfigBase(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { @@ -274,3 +307,50 @@ resource "aws_codebuild_report_group" "test" { } `, rName) } + +func testAccAWSCodeBuildReportGroupConfigTags1(rName, tagKey1, tagValue1 string) string { + return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + + fmt.Sprintf(` +resource "aws_codebuild_report_group" "test" { + name = %[1]q + type = "TEST" + + export_config { + type = "S3" + + s3_destination { + bucket = "${aws_s3_bucket.test.id}" + encryption_key = "${aws_kms_key.test.arn}" + } + } + + tags = { + %[2]q = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccAWSCodeBuildReportGroupConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + + fmt.Sprintf(` +resource "aws_codebuild_report_group" "test" { + name = %[1]q + type = "TEST" + + export_config { + type = "S3" + + s3_destination { + bucket = "${aws_s3_bucket.test.id}" + encryption_key = "${aws_kms_key.test.arn}" + } + } + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +} diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown index 3997ca71d55..a693ca6d89d 100644 --- a/website/docs/r/codebuild_report_group.html.markdown +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -65,6 +65,7 @@ The following arguments are supported: * `name` - (Required) The name of a Report Group. * `type` - (Required) The type of the Report Group. The one valid value is `TEST`. * `export_config` - (Required) Information about the destination where the raw data of this Report Group is exported. see [Export Config](#export-config) documented below. +* `tags` - (Optional) Key-value mapping of resource tags ### Export Config @@ -79,8 +80,6 @@ The following arguments are supported: * `packaging` - (Optional) The type of build output artifact to create. Valid values are: `NONE` (default) and `ZIP`. * `path` - (Optional) The path to the exported report's raw data results. - - ## Attributes Reference In addition to all arguments above, the following attributes are exported: From e627619b6d14be6bf0bdcf6cd11fc81afb865225 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 11 Jul 2020 13:49:33 +0300 Subject: [PATCH 07/12] refactor error refactor tests add comment about encryption --- aws/resource_aws_codebuild_report_group.go | 14 +-- ...esource_aws_codebuild_report_group_test.go | 85 +++++++------------ .../r/codebuild_report_group.html.markdown | 1 + 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index e3f51606387..9bca05ca46a 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -113,7 +113,7 @@ func resourceAwsCodeBuildReportGroupCreate(d *schema.ResourceData, meta interfac resp, err := conn.CreateReportGroup(createOpts) if err != nil { - return fmt.Errorf("Error creating CodeBuild Report Groups: %s", err) + return fmt.Errorf("error creating CodeBuild Report Groups: %w", err) } d.SetId(aws.StringValue(resp.ReportGroup.Arn)) @@ -129,7 +129,7 @@ func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{ ReportGroupArns: aws.StringSlice([]string{d.Id()}), }) if err != nil { - return fmt.Errorf("Error Listing CodeBuild Report Groups: %s", err) + return fmt.Errorf("error Listing CodeBuild Report Groups: %w", err) } if len(resp.ReportGroups) == 0 { @@ -151,15 +151,15 @@ func resourceAwsCodeBuildReportGroupRead(d *schema.ResourceData, meta interface{ d.Set("name", reportGroup.Name) if err := d.Set("created", reportGroup.Created.Format(time.RFC3339)); err != nil { - return fmt.Errorf("error setting created: %s", err) + return fmt.Errorf("error setting created: %w", err) } if err := d.Set("export_config", flattenAwsCodeBuildReportGroupExportConfig(reportGroup.ExportConfig)); err != nil { - return fmt.Errorf("error setting export config: %s", err) + return fmt.Errorf("error setting export config: %w", err) } if err := d.Set("tags", keyvaluetags.CodebuildKeyValueTags(reportGroup.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return fmt.Errorf("error setting tags: %w", err) } return nil @@ -187,7 +187,7 @@ func resourceAwsCodeBuildReportGroupUpdate(d *schema.ResourceData, meta interfac if updateNeeded { _, err := conn.UpdateReportGroup(input) if err != nil { - return fmt.Errorf("Error updating CodeBuild Report Groups: %s", err) + return fmt.Errorf("error updating CodeBuild Report Groups: %w", err) } } @@ -202,7 +202,7 @@ func resourceAwsCodeBuildReportGroupDelete(d *schema.ResourceData, meta interfac } if _, err := conn.DeleteReportGroup(deleteOpts); err != nil { - return fmt.Errorf("Error deleting CodeBuild Report Groups(%s): %s", d.Id(), err) + return fmt.Errorf("error deleting CodeBuild Report Groups(%s): %w", d.Id(), err) } return nil diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go index cab225c2fca..609879ef219 100644 --- a/aws/resource_aws_codebuild_report_group_test.go +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "regexp" "testing" "github.com/aws/aws-sdk-go/aws" @@ -29,11 +28,8 @@ func TestAccAWSCodeBuildReportGroup_basic(t *testing.T) { testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "export_config.#", "1"), - resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), - resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), - resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), - resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), + resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "NO_EXPORT"), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "codebuild", fmt.Sprintf("report-group/%s", rName)), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, @@ -46,7 +42,7 @@ func TestAccAWSCodeBuildReportGroup_basic(t *testing.T) { }) } -func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { +func TestAccAWSCodeBuildReportGroup_export_s3(t *testing.T) { var reportGroup codebuild.ReportGroup rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_codebuild_report_group.test" @@ -57,7 +53,7 @@ func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildReportGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildReportGroupFullConfig(rName), + Config: testAccAWSCodeBuildReportGroupS3ExportConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -67,7 +63,8 @@ func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "NONE"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), + resource.TestCheckResourceAttrPair(resourceName, "export_config.0.s3_destination.0.encryption_key", "aws_kms_key.test", "arn"), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "codebuild", fmt.Sprintf("report-group/%s", rName)), ), }, { @@ -76,7 +73,7 @@ func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodeBuildReportGroupUpdatedConfig(rName), + Config: testAccAWSCodeBuildReportGroupS3ExportUpdatedConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildReportGroupExists(resourceName, &reportGroup), resource.TestCheckResourceAttr(resourceName, "name", rName), @@ -84,9 +81,9 @@ func TestAccAWSCodeBuildReportGroup_updated(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "export_config.0.type", "S3"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.#", "1"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.packaging", "ZIP"), - resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "true"), + resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.encryption_disabled", "false"), resource.TestCheckResourceAttr(resourceName, "export_config.0.s3_destination.0.path", "/some2"), - testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codebuild", regexp.MustCompile(`report-group/.+`)), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "codebuild", fmt.Sprintf("report-group/%s", rName)), ), }, }, @@ -214,7 +211,20 @@ func testAccCheckAWSCodeBuildReportGroupExists(name string, reportGroup *codebui } } -func testAccAWSCodeBuildReportGroupBasicConfigBase(rName string) string { +func testAccAWSCodeBuildReportGroupBasicConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_codebuild_report_group" "test" { + name = %[1]q + type = "TEST" + + export_config { + type = "NO_EXPORT" + } +} +`, rName) +} + +func testAccAWSCodeBuildReportGroupBasicConfigS3ExportBase(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "test" { description = %[1]q @@ -245,27 +255,8 @@ resource "aws_s3_bucket" "test" { `, rName) } -func testAccAWSCodeBuildReportGroupBasicConfig(rName string) string { - return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + - fmt.Sprintf(` -resource "aws_codebuild_report_group" "test" { - name = %[1]q - type = "TEST" - - export_config { - type = "S3" - - s3_destination { - bucket = "${aws_s3_bucket.test.id}" - encryption_key = "${aws_kms_key.test.arn}" - } - } -} -`, rName) -} - -func testAccAWSCodeBuildReportGroupFullConfig(rName string) string { - return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + +func testAccAWSCodeBuildReportGroupS3ExportConfig(rName string) string { + return testAccAWSCodeBuildReportGroupBasicConfigS3ExportBase(rName) + fmt.Sprintf(` resource "aws_codebuild_report_group" "test" { name = %[1]q @@ -286,8 +277,8 @@ resource "aws_codebuild_report_group" "test" { `, rName) } -func testAccAWSCodeBuildReportGroupUpdatedConfig(rName string) string { - return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + +func testAccAWSCodeBuildReportGroupS3ExportUpdatedConfig(rName string) string { + return testAccAWSCodeBuildReportGroupBasicConfigS3ExportBase(rName) + fmt.Sprintf(` resource "aws_codebuild_report_group" "test" { name = %[1]q @@ -298,8 +289,8 @@ resource "aws_codebuild_report_group" "test" { s3_destination { bucket = "${aws_s3_bucket.test.id}" - encryption_disabled = true encryption_key = "${aws_kms_key.test.arn}" + encryption_disabled = false packaging = "ZIP" path = "/some2" } @@ -309,19 +300,13 @@ resource "aws_codebuild_report_group" "test" { } func testAccAWSCodeBuildReportGroupConfigTags1(rName, tagKey1, tagValue1 string) string { - return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + - fmt.Sprintf(` + return fmt.Sprintf(` resource "aws_codebuild_report_group" "test" { name = %[1]q type = "TEST" export_config { - type = "S3" - - s3_destination { - bucket = "${aws_s3_bucket.test.id}" - encryption_key = "${aws_kms_key.test.arn}" - } + type = "NO_EXPORT" } tags = { @@ -332,19 +317,13 @@ resource "aws_codebuild_report_group" "test" { } func testAccAWSCodeBuildReportGroupConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return testAccAWSCodeBuildReportGroupBasicConfigBase(rName) + - fmt.Sprintf(` + return fmt.Sprintf(` resource "aws_codebuild_report_group" "test" { name = %[1]q type = "TEST" export_config { - type = "S3" - - s3_destination { - bucket = "${aws_s3_bucket.test.id}" - encryption_key = "${aws_kms_key.test.arn}" - } + type = "NO_EXPORT" } tags = { diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown index a693ca6d89d..a1a3a2e185e 100644 --- a/website/docs/r/codebuild_report_group.html.markdown +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -77,6 +77,7 @@ The following arguments are supported: * `bucket`- (Required) The name of the S3 bucket where the raw data of a report are exported. * `encryption_key` - (Required) The encryption key for the report's encrypted raw data. * `encryption_disabled`- (Optional) A boolean value that specifies if the results of a report are encrypted. + **Note: the API does not currently allow setting encryption as disabled** * `packaging` - (Optional) The type of build output artifact to create. Valid values are: `NONE` (default) and `ZIP`. * `path` - (Optional) The path to the exported report's raw data results. From c45dd90d9bbcdb9693780d2bcf1098e9db16ece5 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 28 Aug 2020 13:41:52 +0300 Subject: [PATCH 08/12] use v2 and enum slices --- aws/resource_aws_codebuild_report_group.go | 34 +++++++------------ ...esource_aws_codebuild_report_group_test.go | 6 ++-- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index 9bca05ca46a..9e85fea3fc0 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -7,8 +7,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/codebuild" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) @@ -35,12 +35,10 @@ func resourceAwsCodeBuildReportGroup() *schema.Resource { ValidateFunc: validation.StringLenBetween(2, 128), }, "type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - codebuild.ReportTypeTest, - }, false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(codebuild.ReportType_Values(), false), }, "export_config": { Type: schema.TypeList, @@ -49,12 +47,9 @@ func resourceAwsCodeBuildReportGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - codebuild.ReportExportConfigTypeNoExport, - codebuild.ReportExportConfigTypeS3, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(codebuild.ReportExportConfigType_Values(), false), }, "s3_destination": { Type: schema.TypeList, @@ -75,13 +70,10 @@ func resourceAwsCodeBuildReportGroup() *schema.Resource { Required: true, }, "packaging": { - Type: schema.TypeString, - Optional: true, - Default: codebuild.ReportPackagingTypeNone, - ValidateFunc: validation.StringInSlice([]string{ - codebuild.ReportPackagingTypeNone, - codebuild.ReportPackagingTypeZip, - }, false), + Type: schema.TypeString, + Optional: true, + Default: codebuild.ReportPackagingTypeNone, + ValidateFunc: validation.StringInSlice(codebuild.ReportPackagingType_Values(), false), }, "path": { Type: schema.TypeString, diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go index 609879ef219..4299e416d67 100644 --- a/aws/resource_aws_codebuild_report_group_test.go +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -7,9 +7,9 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/codebuild" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "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" ) func TestAccAWSCodeBuildReportGroup_basic(t *testing.T) { From 60b19b52ff51c967d29d3f0f7026ea6599fd1d9e Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 28 Aug 2020 13:43:12 +0300 Subject: [PATCH 09/12] tf 12 syntax --- aws/resource_aws_codebuild_report_group_test.go | 8 ++++---- website/docs/r/codebuild_report_group.html.markdown | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group_test.go b/aws/resource_aws_codebuild_report_group_test.go index 4299e416d67..c888712d55b 100644 --- a/aws/resource_aws_codebuild_report_group_test.go +++ b/aws/resource_aws_codebuild_report_group_test.go @@ -266,9 +266,9 @@ resource "aws_codebuild_report_group" "test" { type = "S3" s3_destination { - bucket = "${aws_s3_bucket.test.id}" + bucket = aws_s3_bucket.test.id encryption_disabled = false - encryption_key = "${aws_kms_key.test.arn}" + encryption_key = aws_kms_key.test.arn packaging = "NONE" path = "/some" } @@ -288,8 +288,8 @@ resource "aws_codebuild_report_group" "test" { type = "S3" s3_destination { - bucket = "${aws_s3_bucket.test.id}" - encryption_key = "${aws_kms_key.test.arn}" + bucket = aws_s3_bucket.test.id + encryption_key = aws_kms_key.test.arn encryption_disabled = false packaging = "ZIP" path = "/some2" diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown index a1a3a2e185e..c3ac24261ca 100644 --- a/website/docs/r/codebuild_report_group.html.markdown +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -48,9 +48,9 @@ resource "aws_codebuild_report_group" "example" { type = "S3" s3_destination { - bucket = "${aws_s3_bucket.example.id}" + bucket = aws_s3_bucket.example.id encryption_disabled = false - encryption_key = "${aws_kms_key.example.arn}" + encryption_key = aws_kms_key.example.arn packaging = "NONE" path = "/some" } From d2747214684db41c3f5aa94b13f0853e8e60290d Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 28 Aug 2020 13:44:39 +0300 Subject: [PATCH 10/12] update docs --- website/docs/r/codebuild_report_group.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown index c3ac24261ca..877047d8f79 100644 --- a/website/docs/r/codebuild_report_group.html.markdown +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -63,7 +63,7 @@ resource "aws_codebuild_report_group" "example" { The following arguments are supported: * `name` - (Required) The name of a Report Group. -* `type` - (Required) The type of the Report Group. The one valid value is `TEST`. +* `type` - (Required) The type of the Report Group. Valid value are `TEST` and `CODE_COVERAGE`. * `export_config` - (Required) Information about the destination where the raw data of this Report Group is exported. see [Export Config](#export-config) documented below. * `tags` - (Optional) Key-value mapping of resource tags From b51a1b4bd827ad905d757ba8f059dfbe718db93c Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 28 Aug 2020 13:49:43 +0300 Subject: [PATCH 11/12] validate for kms arn and update docs --- aws/resource_aws_codebuild_report_group.go | 5 +++-- website/docs/r/codebuild_report_group.html.markdown | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index 9e85fea3fc0..84a98951564 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -66,8 +66,9 @@ func resourceAwsCodeBuildReportGroup() *schema.Resource { Optional: true, }, "encryption_key": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, }, "packaging": { Type: schema.TypeString, diff --git a/website/docs/r/codebuild_report_group.html.markdown b/website/docs/r/codebuild_report_group.html.markdown index 877047d8f79..6c120fc5410 100644 --- a/website/docs/r/codebuild_report_group.html.markdown +++ b/website/docs/r/codebuild_report_group.html.markdown @@ -75,7 +75,7 @@ The following arguments are supported: #### S3 Destination * `bucket`- (Required) The name of the S3 bucket where the raw data of a report are exported. -* `encryption_key` - (Required) The encryption key for the report's encrypted raw data. +* `encryption_key` - (Required) The encryption key for the report's encrypted raw data. The KMS key ARN. * `encryption_disabled`- (Optional) A boolean value that specifies if the results of a report are encrypted. **Note: the API does not currently allow setting encryption as disabled** * `packaging` - (Optional) The type of build output artifact to create. Valid values are: `NONE` (default) and `ZIP`. From e5610034e17764b3070f244547bf1f301d2de569 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 28 Aug 2020 22:12:01 +0300 Subject: [PATCH 12/12] remove updateNeeded --- aws/resource_aws_codebuild_report_group.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_codebuild_report_group.go b/aws/resource_aws_codebuild_report_group.go index 84a98951564..0d86b56170c 100644 --- a/aws/resource_aws_codebuild_report_group.go +++ b/aws/resource_aws_codebuild_report_group.go @@ -165,23 +165,17 @@ func resourceAwsCodeBuildReportGroupUpdate(d *schema.ResourceData, meta interfac Arn: aws.String(d.Id()), } - updateNeeded := false - if d.HasChange("export_config") { input.ExportConfig = expandAwsCodeBuildReportGroupExportConfig(d.Get("export_config").([]interface{})) - updateNeeded = true } if d.HasChange("tags") { input.Tags = keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().CodebuildTags() - updateNeeded = true } - if updateNeeded { - _, err := conn.UpdateReportGroup(input) - if err != nil { - return fmt.Errorf("error updating CodeBuild Report Groups: %w", err) - } + _, err := conn.UpdateReportGroup(input) + if err != nil { + return fmt.Errorf("error updating CodeBuild Report Groups: %w", err) } return resourceAwsCodeBuildReportGroupRead(d, meta)