diff --git a/aws/resource_aws_codebuild_project.go b/aws/resource_aws_codebuild_project.go index c2f6ffb3d5e..2d3696a7cd6 100644 --- a/aws/resource_aws_codebuild_project.go +++ b/aws/resource_aws_codebuild_project.go @@ -438,6 +438,19 @@ func resourceAwsCodeBuildProject() *schema.Resource { Optional: true, ValidateFunc: validation.IntAtLeast(0), }, + "git_submodules_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "fetch_submodules": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, "insecure_ssl": { Type: schema.TypeBool, Optional: true, @@ -508,6 +521,19 @@ func resourceAwsCodeBuildProject() *schema.Resource { Optional: true, ValidateFunc: validation.IntAtLeast(0), }, + "git_submodules_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "fetch_submodules": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, "insecure_ssl": { Type: schema.TypeBool, Optional: true, @@ -1000,6 +1026,21 @@ func expandProjectSourceData(data map[string]interface{}) codebuild.ProjectSourc } } + // Only valid for CODECOMMIT source types. + if sourceType == codebuild.SourceTypeCodecommit { + if v, ok := data["git_submodules_config"]; ok && len(v.([]interface{})) > 0 { + config := v.([]interface{})[0].(map[string]interface{}) + + gitSubmodulesConfig := &codebuild.GitSubmodulesConfig{} + + if v, ok := config["fetch_submodules"]; ok { + gitSubmodulesConfig.FetchSubmodules = aws.Bool(v.(bool)) + } + + projectSource.GitSubmodulesConfig = gitSubmodulesConfig + } + } + return projectSource } @@ -1366,10 +1407,11 @@ func flattenAwsCodeBuildProjectSourceData(source *codebuild.ProjectSource) inter "type": aws.StringValue(source.Type), } + m["git_submodules_config"] = flattenAwsCodebuildProjectGitSubmodulesConfig(source.GitSubmodulesConfig) + if source.Auth != nil { m["auth"] = schema.NewSet(resourceAwsCodeBuildProjectSourceAuthHash, []interface{}{sourceAuthToMap(source.Auth)}) } - if source.SourceIdentifier != nil { m["source_identifier"] = aws.StringValue(source.SourceIdentifier) } @@ -1377,6 +1419,18 @@ func flattenAwsCodeBuildProjectSourceData(source *codebuild.ProjectSource) inter return m } +func flattenAwsCodebuildProjectGitSubmodulesConfig(config *codebuild.GitSubmodulesConfig) []interface{} { + if config == nil { + return []interface{}{} + } + + values := map[string]interface{}{ + "fetch_submodules": aws.BoolValue(config.FetchSubmodules), + } + + return []interface{}{values} +} + func flattenAwsCodeBuildVpcConfig(vpcConfig *codebuild.VpcConfig) []interface{} { if vpcConfig != nil { values := map[string]interface{}{} @@ -1490,6 +1544,13 @@ func resourceAwsCodeBuildProjectSourceHash(v interface{}) int { if v, ok := m["git_clone_depth"]; ok { buf.WriteString(fmt.Sprintf("%s-", strconv.Itoa(v.(int)))) } + if v, ok := m["git_submodules_config"]; ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + m := v.([]interface{})[0].(map[string]interface{}) + + if v, ok := m["fetch_submodules"]; ok { + buf.WriteString(fmt.Sprintf("%s-", strconv.FormatBool(v.(bool)))) + } + } if v, ok := m["insecure_ssl"]; ok { buf.WriteString(fmt.Sprintf("%s-", strconv.FormatBool(v.(bool)))) } diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index df0957f26ff..1ea0d8273c5 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -551,6 +551,80 @@ func TestAccAWSCodeBuildProject_Source_GitCloneDepth(t *testing.T) { }) } +func TestAccAWSCodeBuildProject_Source_GitSubmodulesConfig(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "source.3389748318.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "source.3389748318.git_submodules_config.0.fetch_submodules", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "source.3338377709.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "source.3338377709.git_submodules_config.0.fetch_submodules", "false"), + ), + }, + }, + }) +} + +func TestAccAWSCodeBuildProject_SecondarySources_GitSubmodulesConfig(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.2336845252.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.2336845252.git_submodules_config.0.fetch_submodules", "true"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.2080741754.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.2080741754.git_submodules_config.0.fetch_submodules", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.3511868825.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.3511868825.git_submodules_config.0.fetch_submodules", "false"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.1651171204.git_submodules_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.1651171204.git_submodules_config.0.fetch_submodules", "false"), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_Source_InsecureSSL(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -1711,8 +1785,8 @@ func TestAccAWSCodeBuildProject_SecondarySources_CodeCommit(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "source.3715340088.type", "CODECOMMIT"), - resource.TestCheckResourceAttr(resourceName, "secondary_sources.3525046785.source_identifier", "secondarySource1"), - resource.TestCheckResourceAttr(resourceName, "secondary_sources.2644986630.source_identifier", "secondarySource2"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.493771744.source_identifier", "secondarySource1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.1385902896.source_identifier", "secondarySource2"), ), }, { @@ -2379,7 +2453,7 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" type = "GITHUB" } - + logs_config { cloudwatch_logs { status = %q @@ -2411,7 +2485,7 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" type = "GITHUB" } - + logs_config { s3_logs { status = %q @@ -2477,6 +2551,82 @@ resource "aws_codebuild_project" "test" { `, rName, gitCloneDepth) } +func testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig(rName string, fetchSubmodules bool) string { + return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` +resource "aws_codebuild_project" "test" { + name = "%s" + service_role = "${aws_iam_role.test.arn}" + + artifacts { + type = "NO_ARTIFACTS" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + location = "https://git-codecommit.region-id.amazonaws.com/v1/repos/repo-name" + type = "CODECOMMIT" + + git_submodules_config { + fetch_submodules = %t + } + } +} +`, rName, fetchSubmodules) +} + +func testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig(rName string, fetchSubmodules bool) string { + return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` +resource "aws_codebuild_project" "test" { + name = "%[1]s" + service_role = "${aws_iam_role.test.arn}" + + artifacts { + type = "NO_ARTIFACTS" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + location = "https://git-codecommit.region-id.amazonaws.com/v1/repos/repo-name" + type = "CODECOMMIT" + + git_submodules_config { + fetch_submodules = %[2]t + } + } + + secondary_sources { + location = "https://git-codecommit.region-id.amazonaws.com/v1/repos/second-repo-name" + type = "CODECOMMIT" + source_identifier = "secondarySource1" + + git_submodules_config { + fetch_submodules = %[2]t + } + } + + secondary_sources { + location = "https://git-codecommit.region-id.amazonaws.com/v1/repos/third-repo-name" + type = "CODECOMMIT" + source_identifier = "secondarySource2" + + git_submodules_config { + fetch_submodules = %[2]t + } + } +} +`, rName, fetchSubmodules) +} + func testAccAWSCodeBuildProjectConfig_Source_InsecureSSL(rName string, insecureSSL bool) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { diff --git a/website/docs/r/codebuild_project.html.markdown b/website/docs/r/codebuild_project.html.markdown index 9a70d27b305..1d7f8c18d33 100755 --- a/website/docs/r/codebuild_project.html.markdown +++ b/website/docs/r/codebuild_project.html.markdown @@ -150,6 +150,10 @@ resource "aws_codebuild_project" "example" { type = "GITHUB" location = "https://github.com/mitchellh/packer.git" git_clone_depth = 1 + + git_submodules_config { + fetch_submodules = true + } } vpc_config { @@ -288,6 +292,7 @@ The following arguments are supported: * `auth` - (Optional) Information about the authorization settings for AWS CodeBuild to access the source code to be built. Auth blocks are documented below. * `buildspec` - (Optional) The build spec declaration to use for this build project's related builds. This must be set when `type` is `NO_SOURCE`. * `git_clone_depth` - (Optional) Truncate git history to this many commits. +* `git_submodules_config` - (Optional) Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the `type` is `CODECOMMIT`. * `insecure_ssl` - (Optional) Ignore SSL warnings when connecting to source control. * `location` - (Optional) The location of the source code from git or s3. * `report_build_status` - (Optional) Set to `true` to report the status of a build's start and finish to your source provider. This option is only valid when the `type` is `BITBUCKET` or `GITHUB`. @@ -297,6 +302,10 @@ The following arguments are supported: * `type` - (Required) The authorization type to use. The only valid value is `OAUTH` * `resource` - (Optional) The resource value that applies to the specified authorization type. +`git_submodules_config` supports the following: + +* `fetch_submodules` - (Required) If set to true, fetches Git submodules for the AWS CodeBuild build project. + `vpc_config` supports the following: * `security_group_ids` - (Required) The security group IDs to assign to running builds. @@ -327,6 +336,7 @@ The following arguments are supported: * `auth` - (Optional) Information about the authorization settings for AWS CodeBuild to access the source code to be built. Auth blocks are documented below. * `buildspec` - (Optional) The build spec declaration to use for this build project's related builds. * `git_clone_depth` - (Optional) Truncate git history to this many commits. +* `git_submodules_config` - (Optional) Information about the Git submodules configuration for an AWS CodeBuild build project. Git submodules config blocks are documented below. This option is only valid when the `type` is `CODECOMMIT`. * `insecure_ssl` - (Optional) Ignore SSL warnings when connecting to source control. * `location` - (Optional) The location of the source code from git or s3. * `report_build_status` - (Optional) Set to `true` to report the status of a build's start and finish to your source provider. This option is only valid when your source provider is `GITHUB`, `BITBUCKET`, or `GITHUB_ENTERPRISE`.