Skip to content

command/0.12checklist: Terraform 0.11 command to help prep for 0.12#21241

Merged
apparentlymart merged 4 commits intov0.11from
f-0.12-upgrade-checklist
May 8, 2019
Merged

command/0.12checklist: Terraform 0.11 command to help prep for 0.12#21241
apparentlymart merged 4 commits intov0.11from
f-0.12-upgrade-checklist

Conversation

@apparentlymart
Copy link
Copy Markdown
Contributor

@apparentlymart apparentlymart commented May 8, 2019

(Please note that this PR is targeted at the v0.11 maintenance branch, not at the master branch.)

There's a small set of tasks that are easier to do if handled before upgrading to Terraform 0.12, while still on 0.11:

  • Upgrading to compatible provider versions. Not doing this doesn't actually hurt once upgraded to Terraform 0.12 (it will produce suitable error messages itself if not compatible) but doing it ahead of time will allow the user to deal with any provider-level upgrade steps separately from the core upgrade, thus reducing risk compared to doing everything at once.
  • Fixing any resource names that v0.12 would consider invalid because they start with digits. Dealing with this in 0.11 is easier because the 0.11 terraform state mv command will accept these now-invalid names while the 0.12 version will not.
  • Fixing any provider aliases that v0.12 would consider invalid because they start with digits. Dealing with this in 0.11 is easier because then the user can run terraform apply to rewrite all of the provider assignments in the state before upgrading, whereas 0.12 would consider it a syntax error.
  • Dealing with any of the above tasks on external modules the configuration refers to.

This tool can also serve a more short-lived purpose of providing a way to easily check if all of the providers used by a configuration have v0.12-compatible versions available.

The idea here is to merge this and include it in one last v0.11 release, and then the v0.12 upgrade guide would direct users to:

  1. Upgrade to this final release of Terraform v0.11 to make the tool available.
  2. Run terraform init to make sure the working directory is in a consistent state.
  3. Run terraform apply to make sure the configuration, state, and remote objects are all consistent.
  4. Run terraform 0.12checklist to obtain a list of preparation steps, if any, or a prompt to refer back to the upgrade guide for next steps if everything looks okay.

The main idea here is to leave the user in a state where all of the providers are already upgraded and the next step would be to upgrade to Terraform v0.12 and run terraform 0.12upgrade to prepare the configuration.

This extra v0.11 release should also include #21226, so upgrading to it will have benefit even if the checklist doesn't produce any tasks by avoiding imposing a strict dependency order on upgrades of different configurations in a decomposed environment that is using terraform_remote_state to connect between workspaces.

Because this is a best-effort tool with a very temporary scope, I elected not to write any automated tests for this since the opportunity costs of doing so would be high relative to the value. Instead, I have tested this manually against a number of configurations, including both tailored configurations designed to trigger these checks and a number of module repositories index in the Terraform Registry that use complex module trees. If it turns out that there are bugs in this tool in practice, we'll use language in the 0.12 upgrade guide to warn about it and suggest workarounds.


The output of this tool is in GitHub-flavored Markdown format so it can easily be pasted into a Markdown-capable issue tracker, like GitHub issues. Here is an example of output from a tailored configuration I wrote to show off some of the different checklist item types:

After analyzing this configuration and working directory, we have identified some necessary steps that we recommend you take before upgrading to Terraform v0.12:

  • Upgrade provider "local" to version 1.2.2 or newer.

    No currently-installed version is compatible with Terraform 0.12. To upgrade, set the version constraint for this provider as follows and then run terraform init:

      version = "~> 1.2.2"
    
  • Upgrade provider "rundeck" to a version that is compatible with Terraform 0.12.

    No compatible version is available for automatic installation at this time. If this provider is still supported (not archived) then a compatible release should be available soon. For more information, check for 0.12 compatibility tasks in the provider's issue tracker.

  • data "local_file" "99problems" has a name that is not a valid identifier.

    In Terraform 0.12, resource names must start with a letter. To fix this, rename the resource in the configuration and then use terraform state mv to mirror that name change in the state.

  • provider "local" alias "4baz" is not a valid identifier.

    In Terraform 0.12, provider aliases must start with a letter. To fix this, rename the provider alias and any references to it in the configuration and then run terraform apply to re-attach any existing resources to the new alias name.

  • resource "null_resource" "99bottlesofbeer" has a name that is not a valid identifier.

    In Terraform 0.12, resource names must start with a letter. To fix this, rename the resource in the configuration and then use terraform state mv to mirror that name change in the state.

Taking these steps before upgrading to Terraform v0.12 will simplify the upgrade process by avoiding syntax errors and other compatibility problems.

This will grow to include various checks for steps we recommend users to
take before upgrading to Terraform 0.12, including:

- Upgrading providers to the minimum versions that support Terraform 0.12
- Warn about any names that violate the new stricter naming rules in 0.12,
  so users can optionally fix them before upgrading.
- Upgrading any child modules that themselves have checklist warnings.
Terraform 0.11 had incomplete validation of resource and provider alias
names, which worked only due to the strange way HIL parsed variable names.
Terraform 0.12 (based on HIL) requires valid identifiers, so we'll let
users know about this before they upgrade. It will be easier for users to
deal with this while still on Terraform 0.11 because it won't run into
parse errors trying to work with the invalid name.
We'll use the Terraform Registry API here (mimicking what the v0.12 plugin
installer would do) to see if any of the provider versions already
installed are 0.12-compatible, and produce a checklist item for any one
that isn't.

In the ideal case we can suggest an exact version to upgrade to -- the
newest one with protocol 5 support -- but failing that we'll produce
a less actionable error, potentially saying that the provider may see
a new release soon if it seems like it's a HashiCorp-distributed provider
(has a suitable entry in the registry) but nothing is compatible yet.
Along with the checklist items, we should also include some surrounding
commentary to add context about what these recommendations are for.

If no changes seem to be required at all, we direct the user back to the
upgrade guide in case there are other steps described there that this
tool is unable to detect or represent.
@apparentlymart apparentlymart requested a review from a team May 8, 2019 01:55
@apparentlymart apparentlymart self-assigned this May 8, 2019
@apparentlymart
Copy link
Copy Markdown
Contributor Author

As with #21226, the CI tests will fail here because the v0.11 website directory is no longer viable. We no longer publish to the website from that directory, so the errors there are not a concern.

@apparentlymart apparentlymart merged commit ef86b2c into v0.11 May 8, 2019
@apparentlymart apparentlymart deleted the f-0.12-upgrade-checklist branch May 8, 2019 23:19
@ghost
Copy link
Copy Markdown

ghost commented Jul 26, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants