Created
September 3, 2020 14:20
-
-
Save ksatirli/bd6bd7a2d393bd470554ecc941d03034 to your computer and use it in GitHub Desktop.
rename Terraform Cloud Organization
This file contains 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
#!/bin/sh | |
# This script sends a requests to the Terraform Cloud API and updates the | |
# organization name from "${OLD_TFC_ORG_NAME}" to "${NEW_TFC_ORG_NAME}". | |
# | |
# This script can be useful when you need to rename a TFC Organization without | |
# wanting to (or being able to) start from scratch. | |
# | |
# Use this script with care, as this request is carried out against the API, only. | |
# Check your (local) Terraform Resources for references to `OLD_TFC_ORG_NAME` and | |
# rename the values and / or use `terraform state mv` to update your Terraform state. | |
export OLD_TFC_ORG_NAME="startup" | |
export NEW_TFC_ORG_NAME="bigcorp" | |
curl \ | |
--show-error \ | |
--request "PATCH" \ | |
--header "Authorization: Bearer ${TFC_TOKEN}" \ | |
--header "Content-Type: application/vnd.api+json" \ | |
--data "{ \"data\": { \"type\": \"organizations\", \"attributes\": { \"name\": \"${NEW_TFC_ORG_NAME}\" } } }" \ | |
"https://app.terraform.io/api/v2/organizations/${OLD_TFC_ORG_NAME}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When the command completes successfully, the API returns HTTP Status
200
, and a JSON response similar to this:Take note that in the example response, the value for the
bigcorp
TFC Organization would reflect the value you used forNEW_TFC_ORG_NAME
(line 14).Similarly, the values for
data.attributes.external-id
(org-AbCdEFgHijK1L2Mn
) anddata.attributes.email
([email protected]
in the example response) would reflect _your_ situation, with a different organization ID and an email address linked to the token you specified as part of
TFC_TOKEN`.