Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .terraform-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ content: |-
{{- if or $isResource $isDataResource }}
{{- $fullspec := ternary .URL (printf "[%s](%s)" .Spec .URL) .Spec }}
| {{ $fullspec }} | {{ .GetMode }} |
{{- if .Description }}
|**Description:** {{ tostring .Description | sanitizeMarkdownTbl }} ||
{{- end }}
|**Description:** {{ if .Description }}{{ tostring .Description | sanitizeMarkdownTbl }}{{ end }} ||
{{- end }}
{{- end }}

Expand Down
25 changes: 19 additions & 6 deletions codeartifact-repo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ This module is intended to configure AWS CodeArtifact domains and repositories.

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | => 1.14.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | => 6.21.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.14.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.21.0 |

## Providers

Expand Down Expand Up @@ -63,7 +63,7 @@ This module is intended to configure AWS CodeArtifact domains and repositories.
| <a name="input_encryption_key_arn"></a> [encryption\_key\_arn](#input\_encryption\_key\_arn) | ARN of KMS key used for repository encryption. If not specified, and use\_default\_ecnryption\_key is false, creates new KMS key | `string` | `null` | no |
| <a name="input_publisher_principals"></a> [publisher\_principals](#input\_publisher\_principals) | List of AWS principal ARNS thet should have permissions to publish packages | `list(string)` | `[]` | no |
| <a name="input_reader_principals"></a> [reader\_principals](#input\_reader\_principals) | List of AWS principals ARNs that should have read access to domain and repositories | `list(string)` | `[]` | no |
| <a name="input_repo_region"></a> [repo\_region](#input\_repo\_region) | Region in which repository will be managed. If not specified, defaults to region configured for provider | `string` | `null` | no |
| <a name="input_repo_region"></a> [repo\_region](#input\_repo\_region) | Region in which repositories will be managed. If not specified, defaults to region configured for provider | `string` | `null` | no |
| <a name="input_repositories"></a> [repositories](#input\_repositories) | List of repositories within Codeartifact domain | <pre>list(object({<br/> repository_name = string<br/> description = optional(string, "")<br/> region = optional(string, null)<br/> domain_owner = optional(string, null)<br/> upstream = optional(string, null)<br/> external_connection = optional(string, null)<br/> policy_document_path = optional(string, null)<br/> }))</pre> | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to resources | `map(string)` | `{}` | no |
| <a name="input_use_default_ecnryption_key"></a> [use\_default\_ecnryption\_key](#input\_use\_default\_ecnryption\_key) | Whether to use default Codeartifact KMS key (defaults to true) | `bool` | `true` | no |
Expand All @@ -72,10 +72,9 @@ This module is intended to configure AWS CodeArtifact domains and repositories.

| Name | Description |
|------|-------------|
| <a name="output_created_repositories"></a> [created\_repositories](#output\_created\_repositories) | A list of names of the created repositories. |
| <a name="output_domain"></a> [domain](#output\_domain) | Name of the CodeArtifact domain |
| <a name="output_domain_owner"></a> [domain\_owner](#output\_domain\_owner) | Owner account of the CodeArtifact domain |
| <a name="output_policy_documents"></a> [policy\_documents](#output\_policy\_documents) | A map of repository names to their applied policy documents (if any). |
| <a name="output_repo_urls"></a> [repo\_urls](#output\_repo\_urls) | A map of repository names to their repository endpoints. |

## Examples

Expand Down Expand Up @@ -114,7 +113,21 @@ module "my_repo" {
}
]
}


# Access module outputs

output "repo_urls" {
value = module.codeartifact-repo.repo_urls
description = "Map of repository URLs for access"
}

output "repo_domain" {
value = module.codeartifact-repo.domain
}

output "repo_owner" {
value = module.codeartifact-repo.domain_owner
}

```
<!-- END_TF_DOCS -->
16 changes: 15 additions & 1 deletion codeartifact-repo/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ module "my_repo" {
}
]
}


# Access module outputs

output "repo_urls" {
value = module.codeartifact-repo.repo_urls
description = "Map of repository URLs for access"
}

output "repo_domain" {
value = module.codeartifact-repo.domain
}

output "repo_owner" {
value = module.codeartifact-repo.domain_owner
}

```
4 changes: 3 additions & 1 deletion codeartifact-repo/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

locals {
should_create_kms_key = (!var.use_default_ecnryption_key && var.encryption_key_arn == null) ? true : false
resolved_region = var.repo_region != null ? var.repo_region : data.aws_region.current_region.region
}

data "aws_caller_identity" "current" {}
data "aws_region" "current_region" {}

# CodeArtifact domain acting as a container for repositories
resource "aws_codeartifact_domain" "repo_domain" {
domain = var.domain_name
region = var.repo_region != null ? var.repo_region : null
region = local.resolved_region
encryption_key = var.use_default_ecnryption_key ? null : var.encryption_key_arn
tags = var.tags
}
Expand Down
12 changes: 4 additions & 8 deletions codeartifact-repo/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ output "domain_owner" {
value = aws_codeartifact_domain.repo_domain.owner
}

output "created_repositories" {
description = "A list of names of the created repositories."
value = tolist(keys(aws_codeartifact_repository.repository))
}

output "policy_documents" {
description = "A map of repository names to their applied policy documents (if any)."
value = { for repo_name, repo_policy in aws_codeartifact_repository_permissions_policy.repo_permissions_policy : repo_name => repo_policy.policy_document }
}
output "repo_urls" {
description = "A map of repository names to their repository endpoints."
value = { for repo_name, repo in aws_codeartifact_repository.repository : repo_name => "https://${var.domain_name}-${aws_codeartifact_domain.repo_domain.owner}.d.codeartifact.${local.resolved_region}.amazonaws.com" }
}
77 changes: 77 additions & 0 deletions codeartifact-repo/tests/outputs.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2025 Bitshift
# SPDX-License-Identifier: MPL-2.0

mock_provider "aws" {
override_resource {
target = aws_codeartifact_domain.repo_domain
values = {
arn = "arn:aws:codeartifact:us-east-1:123456789012:domain/test-domain"
owner = "123456789012"
}
}
override_data {
target = data.aws_region.current_region
values = {
region = "us-east-1"
}
}
}

run "correct_output_should_be_generated" {
command = apply

variables {
domain_name = "test-domain"
repositories = [
{
repository_name = "repo-name"
external_connection = "public:npmjs"
}
]
}

assert {
condition = output.domain == "test-domain" && output.domain_owner == aws_codeartifact_domain.repo_domain.owner && output.repo_urls["repo-name"] == "https://test-domain-123456789012.d.codeartifact.us-east-1.amazonaws.com"
error_message = "Outputs did not match expected values."
}
}

run "correct_output_with_multiple_repositories" {
command = apply

variables {
domain_name = "test-domain"
repositories = [
{
repository_name = "repo-one"
},
{
repository_name = "repo-two"
}
]
}

assert {
condition = output.domain == "test-domain" && output.domain_owner == aws_codeartifact_domain.repo_domain.owner && output.repo_urls["repo-one"] == "https://test-domain-123456789012.d.codeartifact.us-east-1.amazonaws.com" && output.repo_urls["repo-two"] == "https://test-domain-123456789012.d.codeartifact.us-east-1.amazonaws.com"
error_message = "Outputs did not match expected values for multiple repositories."
}
}

run "correct_urls_with_different_region" {
command = apply

variables {
domain_name = "test-domain"
repo_region = "us-west-2"
repositories = [
{
repository_name = "repo-name"
}
]
}

assert {
condition = output.domain == "test-domain" && output.domain_owner == aws_codeartifact_domain.repo_domain.owner && output.repo_urls["repo-name"] == "https://test-domain-123456789012.d.codeartifact.us-west-2.amazonaws.com"
error_message = "Output URLs did not match expected values for specified repository region."
}
}
19 changes: 0 additions & 19 deletions codeartifact-repo/tests/repository.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,7 @@ run "create_repository_permissions_policy_when_path_is_provided" {
}
}

run "output_should_return_created_repository_names" {
command = plan

variables {
domain_name = "test-domain"
repositories = [
{
repository_name = "repo-one"
},
{
repository_name = "repo-two"
}
]
}

assert {
condition = contains(output.created_repositories, "repo-one") && contains(output.created_repositories, "repo-two")
error_message = "The output 'created_repositories' does not contain the expected repository names."
}
}

run "validate_external_connection_value" {
command = plan
Expand Down
2 changes: 1 addition & 1 deletion codeartifact-repo/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "domain_name" {
variable "repo_region" {
type = string
default = null
description = "Region in which repository will be managed. If not specified, defaults to region configured for provider"
description = "Region in which repositories will be managed. If not specified, defaults to region configured for provider"
}

variable "use_default_ecnryption_key" {
Expand Down
Loading