Created
August 27, 2020 13:06
-
-
Save data-henrik/e652b45e250ae95e26dc8b2367ba7201 to your computer and use it in GitHub Desktop.
Create an IBM Cloud service ID, then create and download an API key for that service ID
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
# See https://cloud.ibm.com/docs/terraform?topic=terraform-getting-started | |
# for details on IBM Cloud and Terraform | |
# First, obtain an IBM Cloud IAM token | |
# Thereafter, create a new IAM service ID and as | |
# follow-up step, using a local execution environment, | |
# utilize curl to create and download an API key. | |
# Obtain the IBM Cloud IAM authentication token | |
# It is needed for the embedded curl command below | |
data "ibm_iam_auth_token" "iam_tokendata" {} | |
# Create a service ID | |
resource "ibm_iam_service_id" "myServiceID" { | |
name = "myServiceID" | |
description = "ServiceID for demonstrating API key access" | |
# create and download API key | |
provisioner "local-exec" { | |
command = "curl -X POST 'https://iam.cloud.ibm.com/v1/apikeys' -H 'Authorization: ${data.ibm_iam_auth_token.iam_tokendata.iam_access_token}' -H 'Content-Type: application/json' -d '{ \"name\":\"myServiceID-key\", \"iam_id\":\"iam-${ibm_iam_service_id.myServiceID.id}\", \"store_value\": true}' > myServiceID-key.json" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://stackoverflow.com/questions/63557050/ibm-cloud-and-terraform-how-to-create-and-download-api-key