Skip to content

Commit

Permalink
resource/aws_codebuild_project: Deprecate source and secondary_source…
Browse files Browse the repository at this point in the history
…s auth blocks

Reference: https://docs.aws.amazon.com/codebuild/latest/APIReference/API_SourceAuth.html
Reference: #13450

Currently, the following consistent test failure occurs in AWSCodeBuildProject acceptance testing:

```
--- FAIL: TestAccAWSCodeBuildProject_Source_Auth (11.50s)
    testing.go:683: Step 1 error: errors during apply:

        Error: Error creating CodeBuild project: InvalidInputException: No Access token found, please visit AWS CodeBuild console to connect to GitHub
```

The API documentation now very explicitly states this underlying API type is deprecated. Here we mark the block and underlying attributes as deprecated suggesting the `aws_codebuild_source_credential` resource and removing the problematic test rather than temporarily introducing a skipping mechanism.
  • Loading branch information
bflad committed Feb 4, 2021
1 parent 11cd8e2 commit 5bbdb68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 71 deletions.
18 changes: 12 additions & 6 deletions aws/resource_aws_codebuild_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,22 @@ func resourceAwsCodeBuildProject() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
codebuild.SourceAuthTypeOauth,
}, false),
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
},
},
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
"buildspec": {
Type: schema.TypeString,
Expand Down Expand Up @@ -486,19 +489,22 @@ func resourceAwsCodeBuildProject() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
codebuild.SourceAuthTypeOauth,
}, false),
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
},
},
Deprecated: "Use the aws_codebuild_source_credential resource instead",
},
"buildspec": {
Type: schema.TypeString,
Expand Down
61 changes: 0 additions & 61 deletions aws/resource_aws_codebuild_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,38 +594,6 @@ func TestAccAWSCodeBuildProject_LogsConfig_S3Logs(t *testing.T) {
})
}

func TestAccAWSCodeBuildProject_Source_Auth(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_Auth(rName, "FAKERESOURCE1", "INVALID"),
ExpectError: regexp.MustCompile(`expected source.0.auth.0.type to be one of`),
},
{
Config: testAccAWSCodeBuildProjectConfig_Source_Auth(rName, "FAKERESOURCE1", "OAUTH"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project),
resource.TestCheckResourceAttr(resourceName, "source.0.auth.#", "1"),
resource.TestCheckResourceAttr(resourceName, "source.0.auth.0.resource", "FAKERESOURCE1"),
resource.TestCheckResourceAttr(resourceName, "source.0.auth.0.type", "OAUTH"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSCodeBuildProject_Source_GitCloneDepth(t *testing.T) {
var project codebuild.Project
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -2835,35 +2803,6 @@ resource "aws_codebuild_project" "test" {
`, rName, status, location, encryptionDisabled))
}

func testAccAWSCodeBuildProjectConfig_Source_Auth(rName, authResource, authType string) string {
return composeConfig(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 {
type = "GITHUB"
location = "https://github.com/hashicorp/packer.git"
auth {
resource = "%s"
type = "%s"
}
}
}
`, rName, authResource, authType))
}

func testAccAWSCodeBuildProjectConfig_Source_GitCloneDepth(rName string, gitCloneDepth int) string {
return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/codebuild_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ The following arguments are supported:
`source` supports the following:

* `type` - (Required) The type of repository that contains the source code to be built. Valid values for this parameter are: `CODECOMMIT`, `CODEPIPELINE`, `GITHUB`, `GITHUB_ENTERPRISE`, `BITBUCKET`, `S3` or `NO_SOURCE`.
* `auth` - (Optional) Information about the authorization settings for AWS CodeBuild to access the source code to be built. Auth blocks are documented below.
* `auth` - (Optional, **Deprecated**) Information about the authorization settings for AWS CodeBuild to access the source code to be built. This information is for the AWS CodeBuild console's use only. Use the [`aws_codebuild_source_credential` resource](codebuild_source_credential.html) instead. 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`, `GITHUB` or `GITHUB_ENTERPRISE`.
Expand All @@ -306,8 +306,8 @@ The following arguments are supported:

`auth` supports the following:

* `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.
* `type` - (Required, **Deprecated**) The authorization type to use. The only valid value is `OAUTH`. This data type is deprecated and is no longer accurate or used. Use the [`aws_codebuild_source_credential` resource](codebuild_source_credential.html) instead.
* `resource` - (Optional, **Deprecated**) The resource value that applies to the specified authorization type. Use the [`aws_codebuild_source_credential` resource](codebuild_source_credential.html) instead.

`git_submodules_config` supports the following:

Expand Down Expand Up @@ -340,7 +340,7 @@ The following arguments are supported:

* `type` - (Required) The type of repository that contains the source code to be built. Valid values for this parameter are: `CODECOMMIT`, `CODEPIPELINE`, `GITHUB`, `GITHUB_ENTERPRISE`, `BITBUCKET` or `S3`.
* `source_identifier` - (Required) The source identifier. Source data will be put inside a folder named as this parameter inside AWS CodeBuild source directory
* `auth` - (Optional) Information about the authorization settings for AWS CodeBuild to access the source code to be built. Auth blocks are documented below.
* `auth` - (Optional, **Deprecated**) Information about the authorization settings for AWS CodeBuild to access the source code to be built. This information is for the AWS CodeBuild console's use only. Use the [`aws_codebuild_source_credential` resource](codebuild_source_credential.html) instead. Auth blocks are documented above.
* `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`, `GITHUB` or `GITHUB_ENTERPRISE`.
Expand Down

0 comments on commit 5bbdb68

Please sign in to comment.