Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aws codebuild source credential resource #7631

Conversation

teraken0509
Copy link
Contributor

@teraken0509 teraken0509 commented Feb 21, 2019

Closes #7025
Closes #7435

Changes proposed in this pull request:

  • Add aws_codebuild_source_credential resource

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCodeBuildSourceCredential_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSCodeBuildSourceCredential_ -timeout 120m
=== RUN   TestAccAWSCodeBuildSourceCredential_Basic
=== PAUSE TestAccAWSCodeBuildSourceCredential_Basic
=== RUN   TestAccAWSCodeBuildSourceCredential_BasicAuth
=== PAUSE TestAccAWSCodeBuildSourceCredential_BasicAuth
=== CONT  TestAccAWSCodeBuildSourceCredential_Basic
=== CONT  TestAccAWSCodeBuildSourceCredential_BasicAuth
--- PASS: TestAccAWSCodeBuildSourceCredential_Basic (49.43s)
--- PASS: TestAccAWSCodeBuildSourceCredential_BasicAuth (49.55s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	49.623s

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. service/codebuild Issues and PRs that pertain to the codebuild service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. documentation Introduces or discusses updates to documentation. labels Feb 21, 2019
@teraken0509 teraken0509 changed the title Feature/add aws codebuild source credential resource Add aws codebuild source credential resource Feb 21, 2019
@teraken0509 teraken0509 force-pushed the feature/add-aws_codebuild_source_credential-resource branch from 979bd0d to a6bf02c Compare June 17, 2019 09:05
@teraken0509
Copy link
Contributor Author

Re-run acctest.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCodeBuildSourceCredential_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSCodeBuildSourceCredential_ -timeout 120m
=== RUN   TestAccAWSCodeBuildSourceCredential_Basic
=== PAUSE TestAccAWSCodeBuildSourceCredential_Basic
=== RUN   TestAccAWSCodeBuildSourceCredential_BasicAuth
=== PAUSE TestAccAWSCodeBuildSourceCredential_BasicAuth
=== CONT  TestAccAWSCodeBuildSourceCredential_Basic
=== CONT  TestAccAWSCodeBuildSourceCredential_BasicAuth
--- PASS: TestAccAWSCodeBuildSourceCredential_Basic (53.06s)
--- PASS: TestAccAWSCodeBuildSourceCredential_BasicAuth (53.12s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	53.212s

@aeschright aeschright requested a review from a team June 26, 2019 00:48
@bflad bflad added the new-resource Introduces a new resource. label Jul 31, 2019
Copy link
Member

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kterada0509 👋 Thanks for submitting this. Just a few things and this should be good to go. Please reach out if you have any questions or do not have time to implement the feedback.

Create: resourceAwsCodeBuildSourceCredentialCreate,
Read: resourceAwsCodeBuildSourceCredentialRead,
Delete: resourceAwsCodeBuildSourceCredentialDelete,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please implement resource import support? More information on the required steps can be found in the Contributing Guide. This resource testing will likely require ImportStateVerifyIgnore: []string{"token", "user_name"} Thanks!

Suggested change
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in c13110c

Token: aws.String(d.Get("token").(string)),
}

if attr, ok := d.GetOk("user_name"); ok && attr.(string) != "" && authType == codebuild.AuthTypeBasicAuth {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.GetOk() automatically checks for zero values so the empty string check is extraneous 👍

Suggested change
if attr, ok := d.GetOk("user_name"); ok && attr.(string) != "" && authType == codebuild.AuthTypeBasicAuth {
if attr, ok := d.GetOk("user_name"); ok && authType == codebuild.AuthTypeBasicAuth {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 64959a1

}

d.SetId(aws.StringValue(resp.Arn))
d.Set("arn", resp.Arn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably the Create function should return the Read function and this d.Set() should be handled in there. 👍

Suggested change
d.Set("arn", resp.Arn)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in de6da2b

d.SetId(aws.StringValue(resp.Arn))
d.Set("arn", resp.Arn)

return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably the Create function should return the Read function.

Suggested change
return nil
return resourceAwsCodeBuildSourceCredentialRead(d, meta)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 05104d7

return nil
}

resourceNotFound := true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically we prefer to use relevant object type as the output variable when searching like this, which simplifies the logic and allows the code to read well on the left side:

var info *codebuild.SourceCredentialInfo

for _, sourceCredentialsInfo := range resp.SourceCredentialsInfos {
	if d.Id() == aws.StringValue(sourceCredentialsInfo.Arn) {
		info = sourceCredentialInfo
		break
	}
}

if info == nil {
	log.Printf("[WARN] CodeBuild Source Credential (%s) not found, removing from state", d.Id())
	d.SetId("")
	return nil
}

d.Set("arn", info.Arn)
d.Set("auth_type", info.AuthType)
d.Set("server_type", info.ServerType)

return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 588a1c3

}

if _, err := conn.DeleteSourceCredentials(deleteOpts); err != nil {
if !isAWSErr(err, codebuild.ErrCodeResourceNotFoundException, "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo 😎

Suggested change
if !isAWSErr(err, codebuild.ErrCodeResourceNotFoundException, "") {
if isAWSErr(err, codebuild.ErrCodeResourceNotFoundException, "") {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 588a1c3

Provides a CodeBuild Source Credential resource.
---

# aws_codebuild_project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy pasta 🍝 and sitewide documentation update that occurred after this PR was submitted 👍

Suggested change
# aws_codebuild_project
# Resource: aws_codebuild_source_credential

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in a938f7a

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 31, 2019
@bflad bflad self-assigned this Jul 31, 2019
@teraken0509 teraken0509 force-pushed the feature/add-aws_codebuild_source_credential-resource branch from a6bf02c to 588a1c3 Compare July 31, 2019 21:38
@teraken0509
Copy link
Contributor Author

Re-run acctest.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCodeBuildSourceCredential_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSCodeBuildSourceCredential_ -timeout 120m
=== RUN   TestAccAWSCodeBuildSourceCredential_Basic
=== PAUSE TestAccAWSCodeBuildSourceCredential_Basic
=== RUN   TestAccAWSCodeBuildSourceCredential_BasicAuth
=== PAUSE TestAccAWSCodeBuildSourceCredential_BasicAuth
=== CONT  TestAccAWSCodeBuildSourceCredential_Basic
=== CONT  TestAccAWSCodeBuildSourceCredential_BasicAuth
--- PASS: TestAccAWSCodeBuildSourceCredential_Basic (51.97s)
--- PASS: TestAccAWSCodeBuildSourceCredential_BasicAuth (52.19s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	52.268s

@bflad ready for re-review.

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jul 31, 2019
@bflad bflad added this to the v2.22.0 milestone Aug 1, 2019
Copy link
Member

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @kterada0509, thanks! 🚀 Will add to sidebar on merge and thinking it might be a good idea to mark the token attribute as Sensitive: true as well. 😄

@bflad bflad merged commit 588a1c3 into hashicorp:master Aug 1, 2019
bflad added a commit that referenced this pull request Aug 1, 2019
@ghost
Copy link

ghost commented Aug 1, 2019

This has been released in version 2.22.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Nov 2, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 2, 2019
@teraken0509 teraken0509 deleted the feature/add-aws_codebuild_source_credential-resource branch March 5, 2020 14:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/codebuild Issues and PRs that pertain to the codebuild service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_codebuild_project: support github token AWS Codebuild Import Source Credentials
2 participants