@@ -10,47 +10,53 @@ Cloud Native Computing Foundation.
1010 is a set of resources that are all managed together. Each root module has a state file that
1111 records the results of the latest apply operation.
1212
13+ - [ bloom_dev] ( ./tofu_root_modules/bloom_dev/README.md ) : Configures the bloom-dev AWS account.
1314 - [ bloom_dev_deployer_permission_set] ( ./tofu_root_modules/bloom_dev_deployer_permission_set/README.md ) :
1415 Configures the bloom-dev-deployer permission set that is assigned on the bloom-dev account.
1516
17+ - [ tofu_importable_modules] ( ./tofu_importable_modules ) : Contains all the Open Tofu importable
18+ modules. An importable module is a reusable set of resources configured through input
19+ parameters. Root modules import importable modules.
20+
21+ - [ bloom_deployment] ( ./tofu_importable_modules/bloom_deployment/ ) : Configures all the resources
22+ needed for a Bloom deployment in a single AWS account.
23+
24+
25+
1626## Infrastructure-as-code mental model
1727
1828Let's say that you need to deploy Bloom to an AWS account. A straight-forward way of achieving this
1929would be to log into the AWS web console and create all the required resources. The downside of this
20- approach is that unless you take really good notes, it is a difficult process to replicate. Even if
21- you take really good notes, the process might have a lot of steps which are all opportunities for
22- making mistakes. Additionally, it is not possible to automate such a process (well, maybe if you
23- have one of those neat AIs that can control your browser. But the AI could also make mistakes just
24- like a human).
30+ approach is that unless you take really good notes, it is a difficult process to replicate.
2531
2632Another approach could be to write a bash script that calls a bunch of AWS CLI commands that create
2733the resources. This improves on the web-based approach because all the steps are explicitly written
2834down. However, the script only works on a fresh AWS account - if you run it again there will be
2935a bunch of errors because the resources will have already been created. If you need to change how
30- the account is configured, you need to write more scripts. That reminds me too much of database
31- evolutions to seem like an good idea...
32-
33- Enter infrastructure-as-code tools like Open Tofu. I like to think of them as CLI scripting with
34- a bunch of functionality already built in. We have ` .tf ` files that contain [ resource
35- descriptions] ( https://opentofu.org/docs/language/resources/ ) for everything we want to configure. We
36- can run the 'script' by running [ ` tofu apply ` ] ( https://opentofu.org/docs/cli/commands/apply/ ) . If
37- the AWS account already matches our desired configuration, Tofu gives us a nice message that the
38- infrastructure matches the configuration. Otherwise, Tofu presents us with a list of planned changes
39- it thinks it needs to make and asks if it should go forward with the plan.
40-
41- These tools are not magic, however. It is still possible to misconfigure resources and get errors
42- from the AWS API. These cases are not always handled gracefully and sometimes require deleting or
43- configuring things manually to unbork the tool. Using a infrastructure-as-code still requires manual
44- testing and knowledge of the underlying systems you are configuring. It is a heck of a lot better
45- than shell scripting, however, at least in my experience :)
46-
47- _ Monologue by Avritt Rohwer_
36+ the account is configured, you need to write more scripts.
37+
38+ Enter infrastructure-as-code tools like Terraform and Open Tofu. I like to think of them as CLI
39+ scripting with a bunch of functionality already built in. ` .tf ` files contain [ resource
40+ descriptions] ( https://opentofu.org/docs/language/resources/ ) . Run the 'script' by running [ `tofu
41+ apply`] ( https://opentofu.org/docs/cli/commands/apply/ ) . If the AWS account already matches the
42+ desired configuration, Tofu prints a nice message that the infrastructure matches the
43+ configuration. Otherwise, Tofu presents us with a list of planned changes it thinks it needs to make
44+ and asks if it should go forward with the plan.
45+
46+ It is still possible to misconfigure resources and get errors from the AWS API. These cases are not
47+ always handled gracefully and sometimes require deleting or configuring things manually to unblock
48+ the tool. Using a infrastructure-as-code still requires manual testing and knowledge of the
49+ underlying systems you are configuring. It is a heck of a lot better than shell scripting, however,
50+ at least in my experience :)
4851
4952## Developer setup
5053
51- 1 . Install required tools:
52- 1 . Open Tofu: https://opentofu.org/docs/intro/install/
53- 2 . AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
54+ 1 . Install required CLI tools:
55+ 1 . bash: ` which bash `
56+ 2 . openssl: ` which openssl `
57+ 3 . tr: ` which tr `
58+ 4 . Open Tofu: https://opentofu.org/docs/intro/install/
59+ 5 . AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
5460
5561 After installing, edit your ` ~/.aws/config ` file for SSO authentication:
5662
@@ -100,8 +106,7 @@ unless you add a provider. In that case, run:
100106tofu init
101107```
102108
103- To update a required version for a provider, change the version in the relevant ` main.tf ` file then
104- run:
109+ To update a required version for a provider, change the version then run:
105110
106111``` bash
107112tofu init -upgrade
@@ -113,15 +118,27 @@ directory.
113118### Applying changes
114119
1151201 . Open a shell and change directory to the root module.
116- 2 . Run ` aws sso login ` to authenticate to AWS. After 1 hour, you will need to re-authenticate using
117- the same command.
118- 3 . Edit the ` main.tf ` file to update the desired configuration.
121+ 2 . Run ` aws sso login ` to authenticate to AWS.
122+ 3 . Edit the tofu files for the desired configuration.
1191234 . Run ` tofu apply ` and review the planned changes. If there are unexpected planned changes, go back
120124 to step 1. If all the changes are expected, approve the apply.
1211255 . Inspect the relevant AWS resources via the CLI or the AWS web console
122126 (Log in via https://d-9067ac8222.awsapps.com/start ). If there are unexpected results, go back to
123- step 1 . In some cases you may have to manually modify or delete resources directly to 'unstick'
127+ step 3 . In some cases you may have to manually modify or delete resources directly to 'unstick'
124128 Open Tofu.
129+ 6 . To delete only the resources provisioned by the bloom_deployment module, run `tofu destroy
130+ -target=module.bloom_deployment`.
131+
132+ #### Forcing resource recreation
133+
134+ To force Tofu to replace a resource, run ` tofu apply -recreate=ADDRESS ` . For example:
135+
136+ ```
137+ tofu apply -recreate=module.bloom_deployment.aws_secretsmanager_secret.api_jwt_signing_key
138+ ```
139+
140+ This is helpful when testing the local-exec provisioner because the provisioner only runs on
141+ resource creation.
125142
126143## AWS setup done manually
127144
0 commit comments