diff --git a/.terraform-docs.yaml b/.terraform-docs.yaml index 281dfee..1b69e08 100644 --- a/.terraform-docs.yaml +++ b/.terraform-docs.yaml @@ -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 }} diff --git a/codeartifact-repo/README.md b/codeartifact-repo/README.md index cc8cb65..593e98d 100644 --- a/codeartifact-repo/README.md +++ b/codeartifact-repo/README.md @@ -15,8 +15,8 @@ This module is intended to configure AWS CodeArtifact domains and repositories. | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | => 1.14.0 | -| [aws](#requirement\_aws) | => 6.21.0 | +| [terraform](#requirement\_terraform) | >= 1.14.0 | +| [aws](#requirement\_aws) | >= 6.21.0 | ## Providers @@ -63,7 +63,7 @@ This module is intended to configure AWS CodeArtifact domains and repositories. | [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 | | [publisher\_principals](#input\_publisher\_principals) | List of AWS principal ARNS thet should have permissions to publish packages | `list(string)` | `[]` | no | | [reader\_principals](#input\_reader\_principals) | List of AWS principals ARNs that should have read access to domain and repositories | `list(string)` | `[]` | no | -| [repo\_region](#input\_repo\_region) | Region in which repository will be managed. If not specified, defaults to region configured for provider | `string` | `null` | no | +| [repo\_region](#input\_repo\_region) | Region in which repositories will be managed. If not specified, defaults to region configured for provider | `string` | `null` | no | | [repositories](#input\_repositories) | List of repositories within Codeartifact domain |
list(object({
repository_name = string
description = optional(string, "")
region = optional(string, null)
domain_owner = optional(string, null)
upstream = optional(string, null)
external_connection = optional(string, null)
policy_document_path = optional(string, null)
})) | `[]` | no |
| [tags](#input\_tags) | Tags to be applied to resources | `map(string)` | `{}` | no |
| [use\_default\_ecnryption\_key](#input\_use\_default\_ecnryption\_key) | Whether to use default Codeartifact KMS key (defaults to true) | `bool` | `true` | no |
@@ -72,10 +72,9 @@ This module is intended to configure AWS CodeArtifact domains and repositories.
| Name | Description |
|------|-------------|
-| [created\_repositories](#output\_created\_repositories) | A list of names of the created repositories. |
| [domain](#output\_domain) | Name of the CodeArtifact domain |
| [domain\_owner](#output\_domain\_owner) | Owner account of the CodeArtifact domain |
-| [policy\_documents](#output\_policy\_documents) | A map of repository names to their applied policy documents (if any). |
+| [repo\_urls](#output\_repo\_urls) | A map of repository names to their repository endpoints. |
## Examples
@@ -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
+}
+
```
\ No newline at end of file
diff --git a/codeartifact-repo/docs/examples.md b/codeartifact-repo/docs/examples.md
index 0176a80..ff774fa 100644
--- a/codeartifact-repo/docs/examples.md
+++ b/codeartifact-repo/docs/examples.md
@@ -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
+}
+
```
\ No newline at end of file
diff --git a/codeartifact-repo/main.tf b/codeartifact-repo/main.tf
index 3e6bdcb..d14e247 100644
--- a/codeartifact-repo/main.tf
+++ b/codeartifact-repo/main.tf
@@ -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
}
diff --git a/codeartifact-repo/outputs.tf b/codeartifact-repo/outputs.tf
index 9ea557c..204a2e5 100644
--- a/codeartifact-repo/outputs.tf
+++ b/codeartifact-repo/outputs.tf
@@ -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" }
+}
\ No newline at end of file
diff --git a/codeartifact-repo/tests/outputs.tftest.hcl b/codeartifact-repo/tests/outputs.tftest.hcl
new file mode 100644
index 0000000..b2a9d32
--- /dev/null
+++ b/codeartifact-repo/tests/outputs.tftest.hcl
@@ -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."
+ }
+}
\ No newline at end of file
diff --git a/codeartifact-repo/tests/repository.tftest.hcl b/codeartifact-repo/tests/repository.tftest.hcl
index e713ee1..e2dbb34 100644
--- a/codeartifact-repo/tests/repository.tftest.hcl
+++ b/codeartifact-repo/tests/repository.tftest.hcl
@@ -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
diff --git a/codeartifact-repo/variables.tf b/codeartifact-repo/variables.tf
index 4992fc5..e1d98e5 100644
--- a/codeartifact-repo/variables.tf
+++ b/codeartifact-repo/variables.tf
@@ -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" {