gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.01k stars 971 forks source link

Add CodeCommit as a source for Modules #3053

Closed mackeyaj closed 4 months ago

mackeyaj commented 6 months ago

Describe the solution you'd like

Id like to be able to use the HTTPS(GRC) protocol to retrieve my Terragrunt Modules from CodeCommit for example

terraform {
  source = "codecommit::us-gov-west-1://AWS_PROFILE@REPO_NAME"
}

The error I get if I try to use this source is 1 error occurred:

I do not have alternatives available to me in this situation because I can only authenticate VIA SSO. Access Keys/ SSH/Git credentials are not an option due to org security requirements.

Additional context

The HTTPS(GRC) URL uses The Python git-remote-codecommit package as a wrapper to facilitate login using the AWS Profile. Some AWS Orgs do not allow IAM Users or access keys and only authenticate via SSO.

lorengordon commented 6 months ago

I've used Terragrunt with Codecommit for many years now. I'd suggest to just use the pure https schema, instead of the aws-custom "codecommit" schema (https grc in codecommit-speak).

For the pure https schema to work, you can specify the source like so:

  source = "git::https://git-codecommit.<region>.amazonaws.com/v1/repos/<repo>?ref=<ref>"

And in your .gitconfig, add an entry like so:

[credential "https://git-codecommit.*.amazonaws.com"]
        helper = !aws codecommit credential-helper $@
        UseHttpPath = true

Then git will call the aws cli to authenticate using the active profile when it clones the repo. You can export AWS_PROFILE if you need to use a specific, non-default profile.

levkohimins commented 4 months ago

Thanks @lorengordon for the suggestion. I think the issue can be marked as solved.