Upgrade to Universal Installer 0.3

Guide to Upgrade Mesosphere Universal Installer to version 0.3

Upgrade Universal Installer 0.2 to 0.3

You should test this procedure on a test cluster before applying it any production cluster to ensure you understand the procedure and it does not break anything.

Ideally you should use tfenv to switch between terraform versions but you can also do it by yourself. so tfenv use 0.12.25 means you need to replace your 0.11 terraform version with 0.12.25 We assume you’re using a clusters main.tf similar to this:

Make sure you’re using the latest modules and your state is properly updated:

  1. terraform init -upgrade
  2. terraform apply

Now we switch to terraform 0.12.25 which offers us an option to translate terraform 0.11 code into terraform 0.12 code

  1. tfenv use 0.12.25

Translate into 0.12 code

  1. terraform 0.12upgrade

You must change the module version to 0.3.0:

change:

  1. version = "~> 0.2.0"

First we upgrade our modules to Universal Installer 0.3 ( version change from above)

not every option might be properly translated. Lets check if our main.tf is valid.

  1. terraform validate

A known issue is the providers part:

  1. providers = {
  2. google = "google"
  3. }

it should look like this:

  1. providers = {
  2. }

the important part is that the provider reference must be without quotes (“”) You can find more information about tf 0.11 to 0.12 upgrade here: https://www.terraform.io/upgrade-guides/0-12.html

Now we apply the new modules to our previous terraform state.

Due to a needed change in the way the load balancer module is being used we must exclude it from the first apply:

After this was successful most of the infrastructure is updated

Import forwarding rules in the new format.

The forwarding rules module had quite some changes about its addressing. Therefore we now need to create import statements from the current state, drop the old state for load balancer rules and reimport them into terraform.

  1. terraform state pull | jq -r '.resources[] | select(.module != null) |select(.module|startswith("module.dcos.module.dcos-infrastructure.module.dcos-forwarding-rules")) | select(.type=="google_compute_forwarding_rule")| . as $i | .instances[] | .attributes_flat as $ attr | .attributes_flat.port_range|split("-") | "terraform import \""+$i.module+"."+$i.type+"."+$i.name+"[\\\"" + if (.[0] == .[1]) then .[0] else .|join("-") end +"\\\"]" +"\" \"" + $attr.id + "\""' > import_rules.sh

In the next step we will drop the complete state for these load balancers. We must make sure that the previous commands ran successfully and stored the forwarding rules.

In our example this looks like this:

  1. $ cat import_rules.sh
  2. terraform import "module.dcos.module.dcos-infrastructure.module.dcos-forwarding-rules.module.dcos-forwarding-rule-masters.module.dcos-forwarding-rule-masters.google_compute_forwarding_rule.forwarding_rule_config[\"80\"]" "m-generic-dcos-ee-demo-80"
  3. [...]

Our file has this amount of command lines:

  1. wc -l import_rules.sh
  2. 4 import_rules.sh

The numbers might differ on your infrastructure if you use additional ports. Before we import these resources again we will drop state for the load balancer rules:

  1. for addr in $(terraform state pull | jq -r '.resources[] | select(.module != null) |select(.module|startswith("module.dcos.module.dcos-infrastructure.module.dcos-forwarding-rules")) | select(.type=="google_compute_forwarding_rule")| . as $i | .instances[] | $i.module+"."+$i.type+"."+$i.name+(if .index_key == null then "" else "["+(.index_key|tostring)+"]" end)'); do terraform state rm "${addr}";done

After dropping the state we import the load balancer rules into our new format

from now on terraform plan should not show any additional changes.