Skip to content

Instantly share code, notes, and snippets.

@data-henrik
Created August 27, 2020 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save data-henrik/e652b45e250ae95e26dc8b2367ba7201 to your computer and use it in GitHub Desktop.
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
# 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