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

Support AWS CodeBuild using CodeStar Connection #40191

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AP-Hunt
Copy link
Contributor

@AP-Hunt AP-Hunt commented Nov 19, 2024

Description

In August 2024, Amazon announced that AWS CodeBuild now supported using the same GitHub app to access source code in CodeBuild as is used in CodePipeline [1].

This PR adds additional configuration options to the aws_codebuild_project resource which get translated into the relevant part of the CreateProject action in the CodeBuild API [2].

It also updates the documentation for the aws_codebuild_source_credential resource to include the CODECONNECTIONS type, which the provider already supported but wasn't documented.

I haven't included any additional tests in this change because it's targeting AWS CodeStar Connections, which require a human in the loop to set up. I hope a maintainer can say whether they're happy with this decision, or can suggest a useful test to include.

Relations

Closes #39011

References

[1] https://aws.amazon.com/about-aws/whats-new/2024/08/aws-codebuild-github-apps-access-source-repositories/

[2] https://docs.aws.amazon.com/codebuild/latest/APIReference/API_ProjectSource.html#CodeBuild-Type-ProjectSource-auth

Output from Acceptance Testing

I haven't run the acceptance tests because I'm adding new, optional code branches which the acceptance tests don't cover. It shouldn't have any impact on them.

Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. service/codebuild Issues and PRs that pertain to the codebuild service. needs-triage Waiting for first response or review from a maintainer. labels Nov 19, 2024
AP-Hunt added a commit to AP-Hunt/terraform-provider-aws that referenced this pull request Nov 19, 2024
AP-Hunt added a commit to AP-Hunt/terraform-provider-aws that referenced this pull request Nov 19, 2024
@AP-Hunt AP-Hunt force-pushed the f_support-codebuild-using-codestar-connection branch from e5900a7 to 05c88f2 Compare November 19, 2024 17:01
AP-Hunt added a commit to AP-Hunt/terraform-provider-aws that referenced this pull request Nov 19, 2024
@AP-Hunt AP-Hunt force-pushed the f_support-codebuild-using-codestar-connection branch from 05c88f2 to aa149b6 Compare November 19, 2024 17:08
AP-Hunt added a commit to AP-Hunt/terraform-provider-aws that referenced this pull request Nov 19, 2024
@AP-Hunt AP-Hunt force-pushed the f_support-codebuild-using-codestar-connection branch from aa149b6 to 239ad38 Compare November 19, 2024 17:32
AP-Hunt added a commit to AP-Hunt/terraform-provider-aws that referenced this pull request Nov 20, 2024
@AP-Hunt AP-Hunt force-pushed the f_support-codebuild-using-codestar-connection branch from 239ad38 to fb1a0d5 Compare November 20, 2024 09:50
@AP-Hunt AP-Hunt marked this pull request as ready for review November 20, 2024 10:26
@AP-Hunt AP-Hunt requested a review from a team as a code owner November 20, 2024 10:26
@justinretzolk justinretzolk added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 20, 2024
@lvthillo
Copy link
Contributor

lvthillo commented Dec 10, 2024

@AP-Hunt I think you forgot to add something like below in func flattenProjectSource

tfMap["auth"] = flattenSourceAuth(apiObject.Auth)

and

func flattenSourceAuth(apiObject *types.SourceAuth) []interface{} {
	if apiObject == nil {
		return []interface{}{}
	}

	tfMap := map[string]interface{}{
		names.AttrType: apiObject.Type,
		"resource":     aws.ToString(apiObject.Resource),
	}

	return []interface{}{tfMap}
}

Now the state remains empty and re-applying will see a new change.

  "source": [
    {
      "auth": [],
   ...

@justinretzolk @ewbankkit How can we proceed with this? Especially considering that creating a CodeConnection requires manual action and is difficult to include in the acceptance tests. I'm not sure how to handle this properly. It would be very useful to see this merged soon (see also the upvotes on the original issue). Thanks in advance!

In August 2024, Amazon announced that AWS CodeBuild now supported using the
same GitHub app to access source code in CodeBuild as is used in
CodePipeline.[1]

This commit adds an optional "auth" block to "source" and "secondary_source"
blocks in the aws_codebuild_project resource.

That configuration, if present, is translated into the "auth" property of
the CreateProject API call.[2]

[1] https://aws.amazon.com/about-aws/whats-new/2024/08/aws-codebuild-github-apps-access-source-repositories/

[2] https://docs.aws.amazon.com/codebuild/latest/APIReference/API_ProjectSource.html#CodeBuild-Type-ProjectSource-auth
…credential

The code already supported this, but it wasn't documented.
@AP-Hunt AP-Hunt force-pushed the f_support-codebuild-using-codestar-connection branch from fb1a0d5 to 10a7fe7 Compare January 3, 2025 12:48
@AP-Hunt
Copy link
Contributor Author

AP-Hunt commented Jan 3, 2025

@lvthillo Good catch, thanks for that. I've added it and amended the relevant commit.

@AP-Hunt
Copy link
Contributor Author

AP-Hunt commented Jan 3, 2025

The golangci-lint Checks / 2 of 3 (pull_request) action failed with this message.

run golangci-lint
  Running [/home/runner/golangci-lint-1.63.1-linux-amd64/golangci-lint run  --config .ci/.golangci2.yml] in [/home/runner/work/terraform-provider-aws/terraform-provider-aws] ...
  Killed
  
  Error: golangci-lint exit with code 137

It doesn't appear I can re-trigger the job myself, so I think a maintainer will need to do that?

@AP-Hunt
Copy link
Contributor Author

AP-Hunt commented Feb 17, 2025

For anyone wanting to create a GitHub Actions runner in AWS CodeBuild before this PR gets merged, you can create aws_codebuild_webhook and aws_codebuild_source_credential resources in Terraform as normal, and an aws_codebuild_project resource with the source block given some placeholder config and changes ignored.

  source {
    type     = "GITHUB"
    location = "https://github.com/my/repo"
  }
  
  lifecycle {
    ignore_changes = [source]
  }

After Terraform runs, you can modify the project to use the CODECONNECTIONS source type via the CLI

source_json="$(jq \
  -rcn \
  --arg "codeconnection_arn" "${CODECONNECTION_ARN}" \
  '{"type": "GITHUB", "location": "https://github.com/my/repo", "auth": {"type": "CODECONNECTIONS", "resource": $codeconnection_arn}}'
)"

aws codebuild update-project \
    --name "codebuild_project" \
    --source "${source_json}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/codebuild Issues and PRs that pertain to the codebuild service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: AWS CodeBuild now supports using GitHub Apps to access source repositories
3 participants