-
-
Notifications
You must be signed in to change notification settings - Fork 225
Added install scripts #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aws/tfstate-backend/install.sh
Outdated
| @@ -0,0 +1,23 @@ | |||
| #!/usr/bin/env bash | |||
|
|
|||
| sed -i "s/backend/#backend/" main.tf | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will change backend in two other places:
https://github.com/cloudposse/terraform-root-modules/blob/master/aws/tfstate-backend/main.tf#L54
https://github.com/cloudposse/terraform-root-modules/blob/master/aws/tfstate-backend/main.tf#L55
I did this before:
sed -i 's/backend "s3" {}/#backend "s3" {}/' main.tf
sed -i 's/#backend "s3" {}/backend "s3" {}/' main.tf```
but it's too fragile and could be broken if the file changes
We need to think of a better way.
aws/tfstate-backend/install.sh
Outdated
| echo "yes" | init-terraform | ||
|
|
||
|
|
||
| echo "Add to the Geodesic Module Dockerfile following" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add to the Geodesic Module Dockerfile the following ENV vars:
aknysh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, a few comments
aws/tfstate-backend/install.sh
Outdated
|
|
||
| ## Spaces before and after `backend` required to select right word, because `backend` appears 3 times in main.tf | ||
| sed -i "s/ backend / #backend /" main.tf | ||
| sed -i "s/ role_arn / #role_arn /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be generally true. This is maybe true for the "root" org, but certainly not on subaccounts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roles are how we determine the account in which to provision the resources, so if this is not set, terraform won't use the appropriate account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will need to be an arg. e.g. --disable-role-arn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we disable the role only in the root account and only once at cold start when we provision iam and we don't have any roles yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the way I typically do something like this, is:
have two different make targets with
two different "invisible-to-terraform™" versions of the resource definitions:
provider-with-assume-role.tf.inprovider-bootstrap.tf.in
and the make targets look like:
bootstrap:
rm -f provider.tf
ln -s provider-bootstrap.tf.in provider.tf
default:
rm -f provider.tf
ln -s provider-with-assume-role.tf.in provider.tf
and the install script then looks closer to:
init-terraform
make bootstrap
terraform plan -input=false -out=install-plan &&
terraform apply -input=false install-plan &&
mv -v install-plan install-plan.applied
aws/tfstate-backend/install.sh
Outdated
| init-terraform | ||
| terraform plan | ||
|
|
||
| export TF_BUCKET=$(echo "yes" | terraform apply | grep -o -e "tfstate_backend_s3_bucket_id\s=\s.*" | cut -d ' ' -f 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever, but use terraform output instead.
export TF_BUCKET=$(terraform output -json | jq -r .tfstate_backend_s3_bucket_id.value)
| echo "Add to the Geodesic Module Dockerfile following" | ||
| echo "#----------------------------------------------" | ||
| echo "ENV TF_BUCKET=\"${TF_BUCKET}\"" | ||
| echo "ENV TF_BUCKET_REGION=\"${TF_BUCKET_REGION}\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output lock table too:
terraform output -json | jq -r .tfstate_backend_dynamodb_table_id.value
aws/tfstate-backend/install.sh
Outdated
|
|
||
| sed -i "s/ #role_arn / role_arn /" main.tf | ||
|
|
||
| echo "Add to the Geodesic Module Dockerfile following" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the following to the Geodesic Module's Dockerfile:
aws/tfstate-backend/install.sh
Outdated
| #!/usr/bin/env bash | ||
|
|
||
| ## Spaces before and after `backend` required to select right word, because `backend` appears 3 times in main.tf | ||
| sed -i "s/ backend / #backend /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be more precise.
sed -Ei 's/^(\s+backend\s+)/#\1/' main.tf
aws/tfstate-backend/install.sh
Outdated
| export TF_BUCKET_REGION=${TF_VAR_region} | ||
|
|
||
| ## Spaces before and after `backend` required to select right word, because `backend` appears 3 times in main.tf | ||
| sed -i "s/ #backend / backend /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use regex style from above.
aws/tfstate-backend/install.sh
Outdated
|
|
||
| echo "yes" | init-terraform | ||
|
|
||
| sed -i "s/ #role_arn / role_arn /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use regex style from above
| echo "ENV TF_BUCKET=\"${TF_BUCKET}\"" | ||
| echo "ENV TF_BUCKET_REGION=\"${TF_BUCKET_REGION}\"" | ||
| echo "#----------------------------------------------" | ||
| echo "And rebuild the module" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then rebuild the geodesic module.
|
|
||
| init-terraform | ||
| terraform plan | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run terraform apply here.
aws/accounts/install.sh
Outdated
| #!/usr/bin/env bash | ||
|
|
||
| ## Spaces before and after `backend` required to select right word, because `backend` appears 3 times in main.tf | ||
| sed -i "s/ role_arn / #role_arn /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous PR comments. This was not updated.
aws/cloudtrail/install.sh
Outdated
| @@ -0,0 +1,12 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want this script duplicated into each project. If we need that, then move it to geodesic
aws/accounts/install.sh
Outdated
| sed -i "s/ role_arn / #role_arn /" main.tf | ||
|
|
||
| init-terraform | ||
| terraform plan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest perhaps:
init-terraform
terraform plan -input=false -out=install-plan &&
terraform apply -input=false install-plan &&
mv install-plan install-plan.applied
aws/tfstate-backend/install.sh
Outdated
|
|
||
| ## Spaces before and after `backend` required to select right word, because `backend` appears 3 times in main.tf | ||
| sed -i "s/ backend / #backend /" main.tf | ||
| sed -i "s/ role_arn / #role_arn /" main.tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the way I typically do something like this, is:
have two different make targets with
two different "invisible-to-terraform™" versions of the resource definitions:
provider-with-assume-role.tf.inprovider-bootstrap.tf.in
and the make targets look like:
bootstrap:
rm -f provider.tf
ln -s provider-bootstrap.tf.in provider.tf
default:
rm -f provider.tf
ln -s provider-with-assume-role.tf.in provider.tf
and the install script then looks closer to:
init-terraform
make bootstrap
terraform plan -input=false -out=install-plan &&
terraform apply -input=false install-plan &&
mv -v install-plan install-plan.applied
|
Fix PR name |
What
tf-statemoduleroot-iammoduleWhy
tf-stateroot-iam