The terraform-aws-codeartifact module optionally creates all resources necessary for creating an AWS CodeArtifact repository, including creating a domain and KMS key for encryption.
Additionally, this module can provision a role for use by CICD systems to upload to CodeArtifact. It includes upload access to ECR as well, as these systems are often used together.
By default, the module will create an NPM repository with the public NPM repository as an external connection.
The most basic implementation creates all necessary resources for managing an NPM repository.
module "codeartifact" {
source = "github.com/catalystcommunity/terraform-aws-codeartifact"
enable_codeartifact_domain_kms_key = true
codeartifact_domain_name = "mydomain"
}module "codeartifact" {
source = "github.com/catalystcommunity/terraform-aws-codeartifact"
enable_codeartifact_domain_kms_key = true
codeartifact_domain_name = "mydomain"
enable_cicd_role = true
cicd_role_trust_arns = ["arn:aws:iam::123456789999:user/my-cicd-user"]
}
Set enable_codeartifact_domain_permissions_policy to true and provide the
domain permissions policy as a JSON string. This example lets a role in another
account request a CodeArtifact authorization token for the domain:
module "codeartifact" {
source = "github.com/catalystcommunity/terraform-aws-codeartifact"
codeartifact_domain_name = "mydomain"
enable_codeartifact_domain_permissions_policy = true
codeartifact_domain_permissions_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::123456789012:role/codeartifact-consumer"
}
Action = ["codeartifact:GetAuthorizationToken"]
Resource = "*"
}]
})
}To read packages, the role also needs a repository permissions policy
(aws_codeartifact_repository_permissions_policy) on each repository. This
module does not create repository permissions policies.
The role's identity policy must also allow the CodeArtifact actions it uses,
including sts:GetServiceBearerToken for codeartifact.amazonaws.com. A
domain permissions policy cannot grant sts:GetServiceBearerToken.
| Name | Version |
|---|---|
| terraform | >= 1.3.0 |
| aws | ~> 5.0 |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| codeartifact_domain_name | Name of CodeArtifact domain to create or reference based on var.enable_codeartifact_domain | string |
n/a | yes |
| cicd_role_description | Description of the CICD role to create | string |
"Role assumed by CICD pipelines" |
no |
| cicd_role_name | Name of the CICD role to create | string |
"cicd" |
no |
| cicd_role_trust_arns | ARNs to trust for assume role | list(string) |
[] |
no |
| codeartifact_domain_kms_key_arn | CodeArtifact domain KMS key to use if var.enable_codeartifact_domain_kms_key is disabled | string |
null |
no |
| codeartifact_domain_kms_key_description | Description of KMS key to create if enabled | string |
"" |
no |
| codeartifact_domain_owner | Account ID that owns the CodeArtifact domain. Defaults to the current account | string |
null |
no |
| codeartifact_domain_permissions_policy | JSON policy document to apply to the CodeArtifact domain if var.enable_codeartifact_domain_permissions_policy is enabled | string |
null |
no |
| codeartifact_repositories | List of repositories to create. Defaults to NPM with public NPM external connection | list(object({ |
[ |
no |
| enable_cicd_role | Enables creation of a CICD role which grants access to Code Artifact and ECR | bool |
false |
no |
| enable_codeartifact_domain | Whether to enable creation of a CodeArtifact domain | bool |
true |
no |
| enable_codeartifact_domain_kms_key | Whether to enable creation of a KMS key for the CodeArtifact domain | bool |
false |
no |
| enable_codeartifact_domain_permissions_policy | Whether to manage a permissions policy on the CodeArtifact domain. Changing this from true to false deletes the policy | bool |
false |
no |
| tags | n/a | map(string) |
{} |
no |
No outputs.
| Name | Type |
|---|---|
| aws_codeartifact_domain.domain | resource |
| aws_codeartifact_domain_permissions_policy.domain | resource |
| aws_codeartifact_repository.repository | resource |
| aws_iam_role.cicd_role | resource |
| aws_kms_key.codeartifact_domain | resource |
| aws_iam_policy_document.cicd_assume_role_policy | data source |
| aws_iam_policy_document.cicd_codeartifact | data source |
| aws_iam_policy_document.cicd_codeartifact_sts | data source |
| aws_iam_policy_document.cicd_ecr | data source |
No modules.