Skip to content

Commit dfd9869

Browse files
committed
updated docs
1 parent b115e5e commit dfd9869

File tree

4 files changed

+63
-45
lines changed

4 files changed

+63
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Use the `cookiecutter` template to create a new environment to hold your configu
6363
cd environments
6464
cookiecutter ../cookiecutter
6565

66-
and follow the prompts to complete the environment name and description.
66+
and follow the prompts to complete the environment name and description, leaving `is_site_env` and `parent_site_env` as their defaults.
6767

6868
**NB:** In subsequent sections this new environment is referred to as `$ENV`.
6969

docs/production.md

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ production-ready deployments.
1515
A `dev` environment should also be created if considered required, or this
1616
can be left until later.
1717

18-
These can all be produced using the cookicutter instructions, but the
19-
`production` and `staging` environments will need their
20-
`environments/$ENV/ansible.cfg` file modifying so that they point to the
21-
`site` environment:
22-
23-
```ini
24-
inventory = ../common/inventory,../site/inventory,inventory
25-
```
18+
These can all be produced with cookiecutter by running
19+
```sh
20+
cd environments
21+
cookiecutter ../cookiecutter
22+
```
23+
You should ensure that you set the `is_site_env` prompt to true for your `site` environment
24+
and set the `parent_site_env` to `site` for your `production` and `staging` environments
2625

2726
- To avoid divergence of configuration all possible overrides for group/role
2827
vars should be placed in `environments/site/inventory/group_vars/all/*.yml`
2928
unless the value really is environment-specific (e.g. DNS names for
30-
`openondemand_servername`).
29+
`openondemand_servername`). It is therefore recommended that you delete the initial
30+
`environments/{production/staging}/inventory/group_vars/all/*.yml` files in your `production` and
31+
`staging` environments.
3132

3233
- Where possible hooks should also be placed in `environments/site/hooks/`
3334
and referenced from the `site` and `production` environments, e.g.:
@@ -38,38 +39,10 @@ and referenced from the `site` and `production` environments, e.g.:
3839
import_playbook: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}/../site/hooks/pre.yml"
3940
```
4041

41-
- OpenTofu configurations should be defined in the `site` environment and used
42-
as a module from the other environments. This can be done with the
43-
cookie-cutter generated configurations:
44-
- Delete the *contents* of the cookie-cutter generated `tofu/` directories
45-
from the `production` and `staging` environments.
46-
- Create a `main.tf` in those directories which uses `site/tofu/` as a
47-
[module](https://opentofu.org/docs/language/modules/), e.g. :
48-
49-
```
50-
...
51-
variable "environment_root" {
52-
type = string
53-
description = "Path to environment root, automatically set by activate script"
54-
}
55-
56-
module "cluster" {
57-
source = "../../site/tofu/"
58-
environment_root = var.environment_root
59-
60-
cluster_name = "foo"
61-
...
62-
}
63-
```
64-
65-
Note that:
66-
67-
- Environment-specific variables (`cluster_name`) should be hardcoded
68-
into the cluster module block.
42+
- Define OpenTofu configurations
43+
- Environment-specific variables (e.g `cluster_name`) should be set in `environments/$ENV/tofu/{$ENV}.tfvars`
6944
- Environment-independent variables (e.g. maybe `cluster_net` if the
70-
same is used for staging and production) should be set as *defaults*
71-
in `environments/site/tofu/variables.tf`, and then don't need to
72-
be passed in to the module.
45+
same is used for staging and production) should be set in `environments/site/tofu/site.auto.tfvars`
7346

7447
- Vault-encrypt secrets. Running the `generate-passwords.yml` playbook creates
7548
a secrets file at `environments/$ENV/inventory/group_vars/all/secrets.yml`.
@@ -103,8 +76,8 @@ and referenced from the `site` and `production` environments, e.g.:
10376
state_volume_provisioning = "attach"
10477

10578
either for a specific environment within the cluster module block in
106-
`environments/$ENV/tofu/main.tf`, or as the site default by changing the
107-
default in `environments/site/tofu/variables.tf`.
79+
`environments/$ENV/tofu/{$ENV}.tfvars`, or as the site default by changing the
80+
default in `environments/site/tofu/site.auto.tfvars`.
10881

10982
For a development environment allowing OpenTofu to manage the volumes using
11083
the default value of `"manage"` for those varibles is usually appropriate, as

docs/upgrades.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ All other commands should be run on the Ansible deploy host.
6262

6363
1. If required, build an "extra" image with local modifications, see [docs/image-build.md](./image-build.md).
6464

65-
1. Modify your site-specific environment to use this image, e.g. via `cluster_image_id` in `environments/$SITE_ENV/tofu/variables.tf`.
65+
1. Modify your site-specific environment to use this image, e.g. via `cluster_image_id` in `environments/site/tofu/site.auto.tfvars` if all environments use the same image
66+
or `environments/$SUB_ENV/tofu/{$SUB_ENV}.tfvars` if the image is environment-specific.
6667

6768
1. Test this in your staging cluster.
6869

@@ -101,3 +102,46 @@ playbook to reconfigure the cluster, e.g. as described in the main [README.md](.
101102

102103
1. Tell users the cluster is available again.
103104

105+
## Upgrading OpenTofu
106+
107+
As of v2.3, environments now import the appliance's latest Tofu as a module, ensuring that your Tofu infrastructure is up to date
108+
with the configuration expected upstream. Environment defined before v2.3 must therefore be manually migrated to the new model.
109+
110+
### Upgrading Site Environments
111+
112+
1. Identify any custom defaults you have set in your `variables.tf` file with `diff environments/site/tofu/variables.tf tofu/variables.tf`
113+
114+
1. Create a new `environments/site/tofu/site.auto.tfvars` file and assign any variables you previously set custom defaults for in `variables.tf` with their default value. For
115+
example,
116+
```sh
117+
variable "key_pair" {
118+
type = string
119+
description = "Name of an existing keypair in OpenStack"
120+
default = "my-key"
121+
}
122+
```
123+
in `variables.tf` becomes
124+
```sh
125+
key_pair = "my-key"
126+
```
127+
in `site.auto.tfvars`
128+
129+
1. Delete the contents of the `environments/site/tofu` except for the `site.auto.tfvars` file
130+
131+
### Upgrading Production/Staging Environments
132+
133+
1. In the `environments/$ENV_NAME/tofu/main.tf` file of your environment, identify any variables (other than `environment_root`) you have hardcoded as arguments to your site module
134+
135+
1. Move these variable assignments to a new `environments/$ENV_NAME/tofu/$ENV_NAME.tfvars` file
136+
137+
1. Delete the contents of the `environments/$ENV_NAME/tofu` directory, except for `.terraform`, `terraform.tfstate`, `.terraform.lock.hcl` and the new tfvars file
138+
139+
1. Create a symlink from `tofu/layouts/main.tf` to `environments/$ENV_NAME/tofu/main.tf`
140+
141+
1. Create a symlink from `tofu/variables.tf` to `environments/$ENV_NAME/tofu/main.tf`
142+
143+
1. Create a symlink from `environments/site/tofu/site.auto.tfvars` to `environments/$ENV_NAME/tofu/site.auto.tfvars`
144+
145+
1. Import the new module with `tofu init`
146+
147+
1. Verify no destructive changes were made to your existing infrastructure with `tofu plan -var-file=$YOUR-TFVARS-FILE`

environments/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ To define an environment using cookiecutter:
4242
cd environments
4343
cookiecutter ../cookiecutter
4444

45-
This will present you with a series of questions which you must answer.
45+
This will present you with a series of questions which you must answer. For guidance on setting
46+
`is_site_env` and `parent_site_env`, see [production docs](../docs/production.md).
4647
Once you have answered all questions, a new environment directory will
4748
be created. The directory will be named according to the answer you gave
4849
for `environment`.

0 commit comments

Comments
 (0)