generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add module to fetch primary_metadata_region #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamar7
wants to merge
49
commits into
main
Choose a base branch
from
16324-pmr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
54f8846
add get primary metadata region
a43b8ac
update DA
b301550
update main
8fac738
resolve comments
122c9e5
resolve pc and update description
0fd4610
update script
f548b68
Merge branch 'main' of https://github.com/terraform-ibm-modules/terra…
ba89546
update script to handle custome endpoint
d453c4c
update readme
348010d
resolve comments
a3ddb62
Merge branch 'main' into 16324-pmr
iamar7 5393d26
Merge branch 'main' of https://github.com/terraform-ibm-modules/terra…
1afd1e3
Merge branch '16324-pmr' of https://github.com/terraform-ibm-modules/…
25c0686
update readme
27bc9a2
update tests
cf97a21
update test
d5042cf
update test
518cc8c
Merge branch 'main' of https://github.com/terraform-ibm-modules/terra…
8d7357d
SKIP UPGRADE TEST
872ac2b
resolve comments
fe253f2
Merge branch 'main' of https://github.com/terraform-ibm-modules/terra…
c1ac16a
resolve comments
0216d12
update script and resolve pc
4d987dd
update script and add cda
0bd87d6
update cdev
deddcef
update script and tests
iamar7 a6491c8
update script
d7e5965
remove commented code
dcbce81
resolve pc
iamar7 db446f3
add debug logs
6399cf4
Merge branch '16324-pmr' of https://github.com/terraform-ibm-modules/…
00f101d
update script
f7c9d65
update script
69ae786
update script
145dbb7
update script
dab2dfc
Merge branch 'main' of https://github.com/terraform-ibm-modules/terra…
de2a40b
remove debugger
e42b25a
run pc
iamar7 c98e038
resolved comments
057719b
Merge branch '16324-pmr' of https://github.com/terraform-ibm-modules/…
f592025
updated get function
3fe7c24
remove twice logging
368ba04
resolve pc
iamar7 6ab14c3
resolve comments
43f4b6a
Merge branch '16324-pmr' of https://github.com/terraform-ibm-modules/…
754e957
update IAM permission
2fef70f
test IAM permission
abaeea1
resolve comments and remove testing code
c5cce23
resolve pc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Submodule common-dev-assets
updated
2 files
| +1 −1 | commonRenovateConfig.json | |
| +63 −18 | module-assets/ci/install-deps.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Metrics Router module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ######################################################################## | ||
| # IBM Cloud Metric Routing | ||
| ######################################################################### | ||
|
|
||
| resource "time_sleep" "wait_iam_token" { | ||
| create_duration = "5s" | ||
| } | ||
|
|
||
| data "external" "get_primary_metadata_region" { | ||
| depends_on = [time_sleep.wait_iam_token] | ||
| program = ["bash", "${path.module}/scripts/get_primary_metadata_region.sh"] | ||
|
|
||
| query = { | ||
| IBM_API_KEY = var.ibmcloud_api_key | ||
iamar7 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| region = var.region | ||
| use_private_endpoint = var.use_private_endpoint | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ######################################################################## | ||
| # Metric Routing Account Settings | ||
| ######################################################################### | ||
|
|
||
| output "primary_metadata_region" { | ||
| value = nonsensitive(data.external.get_primary_metadata_region.result.primary_metadata_region) | ||
| description = "Primary metadata region for IBM Cloud Metrics Router" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| provider "ibm" { | ||
| ibmcloud_api_key = var.ibmcloud_api_key | ||
| region = var.region | ||
iamar7 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
59 changes: 59 additions & 0 deletions
59
modules/get_primary_metadata_region/scripts/get_primary_metadata_region.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| input=$(cat) | ||
| IBM_API_KEY=$(echo "$input" | jq -r '.IBM_API_KEY') | ||
| REGION=$(echo "$input" | jq -r '.region') | ||
| USE_PRIVATE_ENDPOINT=$(echo "$input" | jq -r '.use_private_endpoint') | ||
|
|
||
|
|
||
| if [[ -z "$IBM_API_KEY" || "$IBM_API_KEY" == "null" ]]; then | ||
| echo "Error: IBM_API_KEY is missing" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "$REGION" || "$REGION" == "null" ]]; then | ||
| echo "Error: region is missing" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| IAM_TOKEN=$(curl -s -X POST "https://iam.cloud.ibm.com/identity/token" \ | ||
| -H "Content-Type: application/x-www-form-urlencoded" \ | ||
| -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=${IBM_API_KEY}" \ | ||
| | jq -r '.access_token') | ||
|
|
||
| if [[ -z "$IAM_TOKEN" || "$IAM_TOKEN" == "null" ]]; then | ||
| echo "Error: Failed to obtain IAM token" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "$USE_PRIVATE_ENDPOINT" == "true" ]]; then | ||
| BASE_URL="https://${REGION}.metrics-router.private.cloud.ibm.com" | ||
| else | ||
| BASE_URL="https://${REGION}.metrics-router.cloud.ibm.com" | ||
| fi | ||
|
|
||
| URL="${BASE_URL}/api/v3/settings" | ||
|
|
||
| max_retries=5 | ||
| retry_delay=3 | ||
|
|
||
| for ((i=1; i<=max_retries; i++)); do | ||
| response=$(curl -s -X GET "$URL" -H "Authorization: Bearer ${IAM_TOKEN}" || true) | ||
| if echo "$response" | jq -e '.primary_metadata_region' >/dev/null; then | ||
| break | ||
| fi | ||
| echo "Attempt $i failed, retrying in ${retry_delay}s..." >&2 | ||
| sleep "$retry_delay" | ||
| done | ||
|
|
||
| # Extract region value | ||
| primary_region=$(echo "$response" | jq -r '.primary_metadata_region // empty') | ||
|
|
||
| if [[ -z "$primary_region" ]]; then | ||
| echo "Error: primary_metadata_region not found in response" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Output valid JSON for Terraform | ||
| jq -n --arg primary_region "$primary_region" '{primary_metadata_region: $primary_region}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ############################################################################## | ||
| # Input Variables | ||
| ############################################################################## | ||
|
|
||
| variable "ibmcloud_api_key" { | ||
| description = "The IBM Cloud API Key." | ||
| type = string | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "region" { | ||
| description = "The IBM Cloud region." | ||
iamar7 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type = string | ||
| default = "us-south" | ||
| } | ||
|
|
||
| variable "use_private_endpoint" { | ||
| type = bool | ||
| description = "Make true to hit the private endpoint." | ||
| default = false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| terraform { | ||
| required_version = ">= 1.9.0" | ||
| required_providers { | ||
| time = { | ||
| source = "hashicorp/time" | ||
| version = ">= 0.9.1, < 1.0.0" | ||
| } | ||
| external = { | ||
| source = "hashicorp/external" | ||
| version = "2.3.5" | ||
iamar7 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ibm = { | ||
| source = "ibm-cloud/ibm" | ||
| version = ">= 1.78.2, < 2.0.0" | ||
| } | ||
| null = { | ||
| source = "hashicorp/null" | ||
| version = ">= 3.2.1, < 4.0.0" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.