diff --git a/modules/artifact-registry/README.md b/modules/artifact-registry/README.md index fcadbe8df..f01076527 100644 --- a/modules/artifact-registry/README.md +++ b/modules/artifact-registry/README.md @@ -314,13 +314,14 @@ module "additive_iam" { | [iam_by_principals](variables-iam.tf#L73) | Authoritative IAM binding in {PRINCIPAL => [ROLES]} format. Principals need to be statically defined to avoid cycle errors. Merged internally with the `iam` variable. | map(list(string)) | | {} | | [labels](variables.tf#L206) | Labels to be attached to the registry. | map(string) | | {} | | [tag_bindings](variables.tf#L227) | Tag bindings for this repository, in key => tag value id format. | map(string) | | {} | +| [universe](variables.tf#L234) | GCP universe where to deploy the project. The prefix will be prepended to the project id. | object({…}) | | null | ## Outputs | name | description | sensitive | |---|---|:---:| -| [id](outputs.tf#L17) | Fully qualified repository id. | | -| [name](outputs.tf#L27) | Repository name. | | -| [repository](outputs.tf#L37) | Repository object. | | -| [url](outputs.tf#L47) | Repository URL. | | +| [id](outputs.tf#L34) | Fully qualified repository id. | | +| [name](outputs.tf#L44) | Repository name. | | +| [repository](outputs.tf#L54) | Repository object. | | +| [url](outputs.tf#L64) | Repository URL. | | diff --git a/modules/artifact-registry/outputs.tf b/modules/artifact-registry/outputs.tf index b471e6dbf..f1466e8d6 100644 --- a/modules/artifact-registry/outputs.tf +++ b/modules/artifact-registry/outputs.tf @@ -14,6 +14,23 @@ * limitations under the License. */ +locals { + url = ( + var.universe == null + ? join("/", [ + "${var.location}-${local.format_string}.pkg.dev", + var.project_id, + var.name + ]) + : join("/", [ + "${local.format_string}.${var.universe.package_domain}", + var.universe.prefix, + element(split(":", var.project_id), 1), + var.name + ]) + ) +} + output "id" { description = "Fully qualified repository id." value = google_artifact_registry_repository.registry.id @@ -46,11 +63,7 @@ output "repository" { output "url" { description = "Repository URL." - value = join("/", [ - "${var.location}-${local.format_string}.pkg.dev", - var.project_id, - var.name - ]) + value = local.url depends_on = [ google_artifact_registry_repository.registry, google_artifact_registry_repository_iam_binding.authoritative, diff --git a/modules/artifact-registry/variables.tf b/modules/artifact-registry/variables.tf index 2d979eee1..fa718678e 100644 --- a/modules/artifact-registry/variables.tf +++ b/modules/artifact-registry/variables.tf @@ -230,3 +230,12 @@ variable "tag_bindings" { nullable = false default = {} } + +variable "universe" { + description = "GCP universe where to deploy the project. The prefix will be prepended to the project id." + type = object({ + package_domain = string + prefix = string + }) + default = null +} diff --git a/tests/modules/artifact_registry/tftest.yaml b/tests/modules/artifact_registry/tftest.yaml new file mode 100644 index 000000000..b3ef2cfdc --- /dev/null +++ b/tests/modules/artifact_registry/tftest.yaml @@ -0,0 +1,18 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module: modules/artifact-registry + +tests: + universe: diff --git a/tests/modules/artifact_registry/universe.tfvars b/tests/modules/artifact_registry/universe.tfvars new file mode 100644 index 000000000..417564356 --- /dev/null +++ b/tests/modules/artifact_registry/universe.tfvars @@ -0,0 +1,27 @@ +/** + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +project_id = "eu0:myproject" +location = "u-germany-northeast1" +name = "myregistry" +format = { docker = { standard = {} } } +iam = { + "roles/artifactregistry.admin" = ["group:cicd@example.com"] +} +universe = { + package_domain = "pkg-berlin-build0.goog" + prefix = "eu0" +} diff --git a/tests/modules/artifact_registry/universe.yaml b/tests/modules/artifact_registry/universe.yaml new file mode 100644 index 000000000..72cbd3e2b --- /dev/null +++ b/tests/modules/artifact_registry/universe.yaml @@ -0,0 +1,48 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# docker.pkg-berlin-build0.goog/eu0/ftpc00-prod-iac-core-0/test + +values: + google_artifact_registry_repository.registry: + cleanup_policies: [] + cleanup_policy_dry_run: null + description: Terraform-managed registry + docker_config: [] + effective_labels: + goog-terraform-provisioned: 'true' + format: DOCKER + kms_key_name: null + labels: null + location: u-germany-northeast1 + maven_config: [] + mode: STANDARD_REPOSITORY + project: eu0:myproject + remote_repository_config: [] + repository_id: myregistry + terraform_labels: + goog-terraform-provisioned: 'true' + timeouts: null + virtual_repository_config: [] + vulnerability_scanning_config: + - enablement_config: null + google_artifact_registry_repository_iam_binding.authoritative["roles/artifactregistry.admin"]: + condition: [] + location: u-germany-northeast1 + members: + - group:cicd@example.com + project: eu0:myproject + role: roles/artifactregistry.admin +outputs: + url: docker.pkg-berlin-build0.goog/eu0/myproject/myregistry