- Log in to console for
root
account as your IAM user[email protected]
- Go to https://console.aws.amazon.com/iam/home
- Add an MFA device to your user
- Generate an access key and store it securely to be added to aws-vault
- Change:
FROM cloudposse/geodesic:0.123.1
- Change:
RUN apk add --update terraform_0.11@cloudposse terraform_0.12@cloudposse
(Change version to 0.90.0)
export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules.git//aws/tfstate-backend?ref=tags/0.90.0"
git clone <stage>.example.com
cd <stage>.example.com
mkdir ~/.geodesic/overrides.d ~/.geodesic/preferences.d
If you want to change where the Geodesic config files are stored, set GEODESIC_CONFIG_HOME
in your profile.
If your private key is not located at ~/.ssh/id_rsa
, edit Dockerfile, and add:
echo "export SSH_KEY=/localhost/.ssh/id_rsa_my_key" > ~/.geodesic/overrides.d/ssh
If your AWS profile is not named in the standard way you could change the env var.
echo "export AWS_DEFAULT_PROFILE=\${NAMESPACE}-\${STAGE}-admin" > ~/.geodesic/overrides.d/aws
make init
make docker/build
make install
The following command will start a shell session within the Docker image for the stage.
<stage>.example.com
You will need to enter your private ssh key's passphrase if it has one.
The first time you load the shell you should configure your AWS credentials
aws-config-setup
Follow the prompts. On the first time you do this, you'll need to enter the access key you created above. Make sure you say 'y' to Use MFA?
.
This script will add your credentials to your local aws-vault storage.
You need to do this for each repo/account but the second time you do it you can skip adding the credentials since they have already been added. Here is example output:
⧉ dev
✗ . (none) ~ ⨠ aws-config-setup
Use MFA? [y/n] y
AWS IAM Username: [email protected]
Setup AWS Credentials (aws-vault)? [y/n] y
Enter Access Key ID: AK.......
Enter Secret Access Key: 2dc.....
Enter passphrase to unlock /conf/.awsvault/keys/:
Added credentials to profile "example" in vault
Configured AWS example-dev-admin profile for ap-southeast-2 region in the xxx548454819 account
-> Run 'assume-role' to login to AWS with aws-vault
⧉ dev
✗ . (none) ~ ⨠
⧉ root.example.com
✗ . (none) ~ ⨠ aws-config-setup
Use MFA? [y/n] y
AWS IAM Username: [email protected]
Setup AWS Credentials (aws-vault)? [y/n] n
Configured AWS example-root-admin profile for ap-southeast-2 region in the xxx392324150 account
-> Run 'assume-role' to login to AWS with aws-vault
⧉ root.example.com
✗ . (none) ~ ⨠
Log in to AWS:
assume-role
You should see something like:
✗ . (none) ~ ⨠ assume-role
* Docker clock is 2 seconds behind Host clock
Enter passphrase to unlock /conf/.awsvault/keys/:
Enter token for arn:aws:iam::xxx392324150:mfa/[email protected]: 123456
* Assumed role arn:aws:iam::xxx548454819:role/OrganizationAccountAccessRole
* Found SSH agent config
⧉ dev
√ : (example-dev-admin) ~ ⨠
If you change something in conf/ you must re-run make docker/build
To avoid rebuilding the Docker image every time you change something in the repo, from within the Geodesic container cd to your repo conf directory inside your mounted local drive.
From this directory you can use Geodesic's tools to work with Terraform modules.
For example:
cd /localhost/projects/example/dev.example.com/conf/my-module
make
Once you have everything working you should commit the changes and rebuild the Geodesic image for the account.
If you want to develop a module that requires Terraform 0.12, you must make the following changes:
Makefile.tasks
(replace with:)
$(shell mkdir -p ${TF_MODULE_CACHE})
-include ${TF_MODULE_CACHE}/Makefile
## Fetch the remote terraform module
deps:
terraform init
## Reset this project
reset:
rm -rf Makefile *.tf .terraform ${TF_MODULE_CACHE}
.envrc
(change 0.11 to 0.12)
use envrc
use terraform 0.12
use atlantis
use tfenv
terraform.envrc
Add:
export TF_MODULE_CACHE=.module
make
terraform plan
terraform apply
If you change the root module, run make reset && make
to refresh the module from git.
If Terraform seems to hang, re-run the command prefixed with TF_LOG=DEBUG
. Usually it's caused by an expired session token.