IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 670 forks source link

Need to be able to pass the accountId in the provider block #4941

Open lionelmace opened 12 months ago

lionelmace commented 12 months ago

Community Note

Description

Context: I create child cloud account under an Enterprise account.

The challenge is to specify in which account a resource should be created. Today, the provider block does not provide the ability to pass the accountId.

Example:

How can I tell Terraform now that the COS should be created in account A and not in account B? Because the API key xxx_api_key has access to both accounts. For me it seems that in this case the resource is always deployed in the enterprise account E, but we also need to deploy resources in the child accounts directly after we created them to set up the landing zones.

stevestrutt commented 12 months ago

Internal discussion https://ibm-cloudplatform.slack.com/archives/C53NF5MB4/p1700583212171669

lionelmace commented 12 months ago

Internal idea https://internal-ibmcloud.ideas.aha.io/ideas/IDEAINT-I-8282

lionelmace commented 11 months ago

Here is the current workaround:

  1. Create a child account via TF. Set the child account owner id with the same enterprise account owner id.
  2. Wrapped in terraform a call to create an API Key for the Child Account Owner using the API https://cloud.ibm.com/apidocs/iam-identity-token-api#create-api-key.
  3. Set this newly created API Key in the Cloud Provider
  4. Store the child account API Key in a Secrets Manager (Vault) instance in the Enterprise Account for further use
lionelmace commented 11 months ago

The approach described above is not working

When I generate a token using an enterprise level API key, I cannot use this token to create an API key in a child account, as the token is bound to the enterprise account and does not allow to create an API key in another account (even if the user would be allowed).

image

image