Step 1 - Creating AWS Organization under Blotout SSO
The first step is to create the organization under Blotout SSO in Terraform Cloud. For this, a pipeline is already created and we just need to trigger it with right variables.
-
A terraform organization with name
blotout-adminis already created. This organization is responsible for all the admin task which fall under theBlotout Infrastructurestrategy. -
We need to set up terraform workspace in
blotout-adminorganization. Let’s assume the name of the organization as example for the entire deployment- Create a workspace with name of the client’s organization. The workspace should be named as the organization name with the environment-type as the prefix, for e.g. if name of organization is
exampleand env type isprodthen name of the workspace will beprod-example. To know more about this, check how to create a workspace. - Choose
/adminin theterraformgithub repository for version control with default branch pointing tomaster. - Configure the following variables for the workspace. To know more, check how to create variables in a workspace
organization_name- preferred name of the clientorganization_mail- mail ID of the clientorganization_region- chosen region of the clientenvironment- env type chosen by the clientiam_user- name of the user through which we will create the resource in the client account. (default:blotout-k8s)role_name- name of the role with restrictive permission that will get created in the client account and will be attached toiam_useruser (default:self-serve-role)
- Create a workspace with name of the client’s organization. The workspace should be named as the organization name with the environment-type as the prefix, for e.g. if name of organization is
-
A variable set is already created in the
blotout-adminterraform organization with name ofadmin-varset. We need to attach the client organizationexampleifApply to specific workspacesoption is selected in theWorkspacessection of the variable set. This variable set consists of 4 variables. To know more, check how to attach a variable setaws_access_key- (secret) Access key of our blotout parent account.aws_secret_key- (secret) Secret key of our blotout parent account.aws_region- AWS region (default:us-east-1)public_key- public key to encrypt theiam_usercredentials.
Note: - These variables are set with their static values. Changing this is not recommended.
-
Run the pipeline. If needed, check how to run a pipeline
- Once the pipeline successfully finishes we will get the following variables as output
account_arn- arn of the new client’s accountaccount_id- account IDiam_user_details- (sensitive) credentials of theiam_userencrypted bypublic_key
- Once the pipeline successfully finishes we will get the following variables as output
-
If we go to Blotout SSO we will be able to see the organization now.
-
To obtain the credentials for the AWS organization we need to first obtain the token and the workspace ID.
- Token is used to authenticate to the terraform cloud. To obtain Token
- click on your profile in terraform cloud
- click on User settings
- click on
Tokens - click on
Create an API token.
- Workspace ID is the unique ID of the workspace.
- go inside
blotout-adminterraform organization. - Enter your workspace (here:
example) - Just below the name of the workspace you will find your workspace ID starting with
ws.
- go inside
- Token is used to authenticate to the terraform cloud. To obtain Token
-
To obtain the access key and secret key, you must have the private key corresponding to the public key used in the
public_keyvariable (above) with its password to decrypt the output.Terminal window # token and workspace ID hereexport TF_TOKEN="xxx"export WORKSPACE_ID="xxx"# for access keyexport ACCESS_KEY=$(curl --silent --header "Authorization: Bearer ${TF_TOKEN}" --header "Content-Type: application/vnd.api+json" https://app.terraform.io/$(curl --silent --header "Authorization: Bearer ${TF_TOKEN}" --header "Content-Type: application/vnd.api+json" https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/current-state-version-outputs | jq -r '.data[] | select(.attributes.name=="iam_user_details") | .links.self') | jq '.data.attributes.value["access-key"]' --raw-output)# for secret key (you must have the private key loaded in gpg)# enter the password for private key to decryptexport SECRET_KEY=$(curl --silent --header "Authorization: Bearer ${TF_TOKEN}" --header "Content-Type: application/vnd.api+json" https://app.terraform.io/$(curl --silent --header "Authorization: Bearer ${TF_TOKEN}" --header "Content-Type: application/vnd.api+json" https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/current-state-version-outputs | jq -r '.data[] | select(.attributes.name=="iam_user_details") | .links.self') | jq '.data.attributes.value["secret-key"]' --raw-output | base64 -d | gpg --decrypt) -
You have your keys in the environment variable
ACCESS_KEYandSECRET_KEY.