Step 7 - Utils Pipeline
This pipeline is created for adding some more functionalities to the infrastsructure for e.g. creating a console user in client’s env. This is not necessary to be deployed for the application to work rather it acts as a supportive utility pipeline.
- All the below operations are to be performed under the terraform organization created in the step 2.
- Setting up the workspace
- Create a workspace with name
utilsprefixed with the organization’s environment type. For e.g. if env isprodthen the workspace name will beprod-utils. - Choose
/utilsin theterraformgithub repository for version control with default branch pointing tomaster. - Configure the following variables for the workspace
console_user- (HCL)(sensitive) user details and the permissions to attach to the user. setenabletotrue, give a name to the user inusernamefield, attach policies like[admin]and give base64 encoded public key (password protected) to encrypt the credentials generated for the user in the pipeline.
{enable = trueusername = ""policies = [# list of policies to attach]public_key = ""}
- Create a workspace with name
- Attach this workspace to the respective variable set of the organization created in Step 2.
- Run the pipeline by Actions.
- Click on
Actionsand thenStart new runto start a new run. - Below variables are present in the output
user_details- (sensitive) encrypted details of the user with credentials
- Click on
- To obtain the credentials for the AWS console user 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 your terraform organization.
- Enter your workspace (here:
<ENV>-utils) - Just below the name of the workspace you will find your workspace ID starting with
ws.
- Token is used to authenticate to the terraform cloud. To obtain Token
- To decrypt the
user_detailsin the output above, we need to have the private key for the correspondingpublic keyand its password.Terminal window # token and workspace ID hereexport TF_TOKEN="xxx"export WORKSPACE_ID="xxx"# for usernameexport CONSOLE_USERNAME=$(curl --silent --header "Authorization: Bearer $TF_TOKEN" 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=="user_details") | .links.self') | jq -r '.data.attributes.value | keys[]')# for password (requires above command to be executed first and you must have the private key loaded in gpg)# enter the password for private key to decryptexport CONSOLE_USERNAME_PASSWORD=$(curl --silent --header "Authorization: Bearer $TF_TOKEN" 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=="user_details") | .links.self') | jq -r --arg user "${CONSOLE_USERNAME}" '.data.attributes.value[$user]' | base64 -d | gpg --decrypt) - You have your username and password in
CONSOLE_USERNAMEandCONSOLE_USERNAME_PASSWORDenv variables.