How to access Terraform module in AWS CodeArtifact

0

I created a Terraform module and stored the *.tar.gz file in AWS CodeArtifact. Now I want to access that module in a subsequent Terraform module like this:

module "foo" {
   source = "<some url that points to TF module stored in CodeArtifact>"
}

When I look at the entry in CodeArtifact, I don't see any URL or endpoint construct that I can use to download/access. Can I not store TF modules in CodeArtifact, using them in other TF modules? Is it only for storing upstream packages used in clients such as npm or maven? Do I need to go to something such as Artifactory or some other software package storage mechanism (I was trying to stay within the AWS ecosphere)? I am specifically looking to see if this is possible in CodeArtifact (as opposed to CodeCommit or posting this module to some S3 bucket).

asked 8 months ago554 views
1 Answer
0

CodeArtifact doesn't have native support for Terraform modules. However, you likely can store these in CodeArtifact.

Looking at the Terraform docs, Terraform can load tar.gz files from arbitrary URLs. You could push your .tar.gz to CodeArtifact as a Maven asset (see Publishing with curl), then put the CodeArtifact URL for the asset into the source = line. You would also have to arrange for Terraform to pass a CodeArtifact authentication token which is likely possible using .netrc:

If an HTTP/HTTPS URL requires authentication credentials, use a .netrc file to configure the credentials. By default, Terraform searches for the .netrc file in your HOME directory. However, you can override the default filesystem location by setting the NETRC environment variable. For information on the .netrc format, refer to the documentation for using it in curl.

Another option would be to store the .tar.gz as a generic asset, use the AWS CLI to download it before you run Terrafom, and reference it as a local module, but not sure this is any better than putting the module in S3.

I haven't tried either option, so consider these as suggestions not working solutions.

profile pictureAWS
answered 8 months ago
  • I can get the *.tar.gz file into CodeArtifact just fine as part of a CodeBuild/CodePipeline process but I cannot seem to reference that generic *.tar.gz file that sits in CodeArtifact through a URL. In this case, the *.tar.gz happens to be a zipped Terraform module but it could be anything zipped up as a *.tar.gz. But, it does not seem like you can reference packages/resources that reside in CodeArtifact through a URL. Rather than CodeArtifact, you would have to rely on S3 if you wanted to stay within the AWS Ecosphere.

  • How did you publish the .tar.gz to CodeArtifact?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions