Skip to content

Commit f1e77fd

Browse files
authored
feat: add a new submodule to retrieve container registry endpoint (#319)
1 parent fb7ccc4 commit f1e77fd

File tree

7 files changed

+112
-21
lines changed

7 files changed

+112
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can use this module to provision and configure an [IBM Container Registry](h
1414
## Overview
1515
* [terraform-ibm-container-registry](#terraform-ibm-container-registry)
1616
* [Submodules](./modules)
17+
* [endpoint](./modules/endpoint)
1718
* [plan](./modules/plan)
1819
* [quotas](./modules/quotas)
1920
* [Examples](./examples)

modules/endpoint/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# IBM Container Registry endpoint
2+
3+
This submodule allows you to retrieve the IBM Container Registry endpoint for a specific region. Supported regions are listed in the [IBM Cloud Registry Overview](https://cloud.ibm.com/docs/Registry?topic=Registry-registry_overview#registry_regions).
4+
5+
### Usage
6+
7+
```hcl
8+
module "cr_endpoint" {
9+
source = "terraform-ibm-modules/container-registry/ibm//modules/endpoint"
10+
version = "X.X.X" # Replace "X.X.X" with a release version to lock into a specific release
11+
region = "us-south"
12+
}
13+
```
14+
15+
<!-- Below content is automatically populated via pre-commit hook -->
16+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
### Requirements
18+
19+
| Name | Version |
20+
|------|---------|
21+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
22+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.79.0, < 2.0.0 |
23+
24+
### Modules
25+
26+
No modules.
27+
28+
### Resources
29+
30+
No resources.
31+
32+
### Inputs
33+
34+
| Name | Description | Type | Default | Required |
35+
|------|-------------|------|---------|:--------:|
36+
| <a name="input_region"></a> [region](#input\_region) | Region used to determine the IBM Cloud Container Registry endpoint. Supported regions are listed in the IBM Cloud Registry Overview: https://cloud.ibm.com/docs/Registry?topic=Registry-registry_overview#registry_regions | `string` | n/a | yes |
37+
38+
### Outputs
39+
40+
| Name | Description |
41+
|------|-------------|
42+
| <a name="output_container_registry_endpoint"></a> [container\_registry\_endpoint](#output\_container\_registry\_endpoint) | The public IBM Cloud Container Registry endpoint for the selected region |
43+
| <a name="output_container_registry_endpoint_private"></a> [container\_registry\_endpoint\_private](#output\_container\_registry\_endpoint\_private) | The private IBM Cloud Container Registry endpoint for the selected region |
44+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/endpoint/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##############################################################################
2+
# terraform-ibm-container-registry
3+
#
4+
# Returns the IBM Cloud Container Registry Endpoint
5+
##############################################################################
6+
7+
# map endpoints found from 'ibmcloud cr region-set'
8+
locals {
9+
endpoints = {
10+
"ap-north" = "jp.icr.io"
11+
"jp-tok" = "jp.icr.io"
12+
"ap-south" = "au.icr.io"
13+
"au-syd" = "au.icr.io"
14+
"us-south" = "us.icr.io"
15+
"br-sao" = "br.icr.io"
16+
"ca-tor" = "ca.icr.io"
17+
"eu-central" = "de.icr.io"
18+
"eu-es" = "es.icr.io"
19+
"eu-fr2" = "fr2.icr.io"
20+
"jp-osa" = "jp2.icr.io"
21+
"uk-south" = "uk.icr.io"
22+
"global" = "icr.io"
23+
}
24+
}

modules/endpoint/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
output "container_registry_endpoint" {
5+
description = "The public IBM Cloud Container Registry endpoint for the selected region"
6+
value = local.endpoints[var.region]
7+
}
8+
9+
output "container_registry_endpoint_private" {
10+
description = "The private IBM Cloud Container Registry endpoint for the selected region"
11+
value = "private.${local.endpoints[var.region]}"
12+
}

modules/endpoint/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
##############################################################################
2+
# Common variables
3+
##############################################################################
4+
5+
variable "region" {
6+
description = "Region used to determine the IBM Cloud Container Registry endpoint. Supported regions are listed in the IBM Cloud Registry Overview: https://cloud.ibm.com/docs/Registry?topic=Registry-registry_overview#registry_regions"
7+
type = string
8+
9+
validation {
10+
condition = contains(keys(local.endpoints), var.region)
11+
error_message = "Invalid region. Must be one of: ${join(", ", keys(local.endpoints))}"
12+
}
13+
}

modules/endpoint/version.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_version = ">= 1.9.0"
3+
required_providers {
4+
# Use "greater than or equal to" range in modules
5+
# tflint-ignore: terraform_unused_required_providers
6+
ibm = {
7+
source = "ibm-cloud/ibm"
8+
version = ">= 1.79.0, < 2.0.0"
9+
}
10+
}
11+
}
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
# map endpoints found from 'ibmcloud cr region-set'
2-
locals {
3-
endpoints = {
4-
"ap-north" = "jp.icr.io"
5-
"jp-tok" = "jp.icr.io"
6-
"ap-south" = "au.icr.io"
7-
"au-syd" = "au.icr.io"
8-
"us-south" = "us.icr.io"
9-
"br-sao" = "br.icr.io"
10-
"ca-tor" = "ca.icr.io"
11-
"eu-central" = "de.icr.io"
12-
"eu-es" = "es.icr.io"
13-
"eu-fr2" = "fr2.icr.io"
14-
"jp-osa" = "jp2.icr.io"
15-
"uk-south" = "uk.icr.io"
16-
"global" = "icr.io"
17-
}
18-
}
19-
201
########################################################################################################################
212
# Resource group
223
########################################################################################################################
@@ -40,15 +21,20 @@ module "namespace" {
4021
retain_untagged = var.retain_untagged
4122
}
4223

24+
module "cr_endpoint" {
25+
source = "../../modules/endpoint"
26+
region = var.namespace_region
27+
}
28+
4329
module "upgrade_plan" {
4430
count = var.upgrade_to_standard_plan ? 1 : 0
4531
source = "../../modules/plan"
46-
container_registry_endpoint = var.provider_visibility == "private" ? "private.${local.endpoints[var.namespace_region]}" : local.endpoints[var.namespace_region]
32+
container_registry_endpoint = var.provider_visibility == "private" ? module.cr_endpoint.container_registry_endpoint_private : module.cr_endpoint.container_registry_endpoint
4733
}
4834

4935
module "set_quota" {
5036
source = "../../modules/quotas"
51-
container_registry_endpoint = var.provider_visibility == "private" ? "private.${local.endpoints[var.namespace_region]}" : local.endpoints[var.namespace_region]
37+
container_registry_endpoint = var.provider_visibility == "private" ? module.cr_endpoint.container_registry_endpoint_private : module.cr_endpoint.container_registry_endpoint
5238
storage_megabytes = var.storage_megabytes
5339
traffic_megabytes = var.traffic_megabytes
5440
}

0 commit comments

Comments
 (0)