AWS CodeArtifact Repository

This page shows how to write Terraform and CloudFormation for CodeArtifact Repository and write them securely.

aws_codeartifact_repository (Terraform)

The Repository in CodeArtifact can be configured in Terraform with the resource name aws_codeartifact_repository. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub
resource "aws_codeartifact_repository" "my_repo_1" {
  repository = "my-repo-1"
  domain = aws_codeartifact_domain.my_domain.domain

resource "aws_codeartifact_repository" "my_repo_2" {
resource "aws_codeartifact_repository" "codeartifact_upstream" {
  repository = var.codeartifact_upstream
  domain     = aws_codeartifact_domain.codeartifact_domain.domain

  external_connections {
    external_connection_name = "public:nuget-org"
resource "aws_codeartifact_repository" "repositories" {
  for_each = var.repositories
  depends_on = [resource.aws_codeartifact_domain.domain]

  domain     = aws_codeartifact_domain.domain.domain
  repository = lookup(each.value, "name", each.key)
resource "aws_codeartifact_repository" "codeartifact-repo" {
  provider = aws.primary
  repository = var.codeartifact_repo
  domain     = aws_codeartifact_domain.codeartifact-domain.domain
resource "aws_codeartifact_repository" "examplea" {
  repository = var.repository
  domain     = aws_codeartifact_domain.examplea.domain
  tags       = var.common_tags

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).


Explanation in Terraform Registry

Provides a CodeArtifact Repository Resource.

AWS::CodeArtifact::Repository (CloudFormation)

The Repository in CodeArtifact can be configured in CloudFormation with the resource name AWS::CodeArtifact::Repository. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.


Explanation in CloudFormation Registry

The AWS::CodeArtifact::Repository resource creates an AWS CodeArtifact repository. CodeArtifact repositories contain a set of package versions. For more information about repositories, see the Repository concepts information in the CodeArtifact User Guide. For more information about the CreateRepository API, see CreateRepository in the CodeArtifact API Reference.

Frequently asked questions

What is AWS CodeArtifact Repository?

AWS CodeArtifact Repository is a resource for CodeArtifact of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS CodeArtifact Repository?

For Terraform, the aws-samples/codeartifact-retention-policy, knagu/terraform-eks-main and shepherd44/terraform-aws-codeartifact source code examples are useful. See the Terraform Example section for further details.