Skip to content
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

Upgrade SDK to v2.x & Drop Terraform 0.11 support #246

Merged
merged 12 commits into from
Dec 10, 2020
Merged

Conversation

chrisarcand
Copy link
Member

@chrisarcand chrisarcand commented Nov 23, 2020

Description

This PR upgrades the provider to use the v2.x of the Terraform SDK. This allows for a number of benefits for provider development; the V2 upgrade guide is a great overview of some of the initial changes.

⚠️ Breaking change ⚠️

As a result of this major SDK upgrade, only Terraform CLI 0.12 and later can be supported past the current release (0.23.0). Users who wish to continue using Terraform 0.11 may continue to use version 0.23.x or earlier. This move will also consolidate all example code to use Terraform 0.12 syntax. Examples using the older syntax style can still be viewed by browsing older versions of the provider in the Terraform Registry.

The announcement that official HashiCorp-maintained providers would be dropping support for Terraform 0.11 was made in November 2019, over a year ago.

In Detail

  • Upgrades the Terraform SDK to version 2.x; a major version bump; makes all necessary changes to support this transition. Any APIs that are merely deprecated but not removed are not changed. For example, only the required helper/schema context-aware functions changes were made (all resources still use any deprecated equivalents, CreateFunc, etc).
  • Drops support for Terraform < 0.12; updates documentation and deprecated interpolation syntax.
  • Due to the SDK upgrade, it was discovered that some of the test configurations aren't actually compatible with Terraform 0.13 (which is installed automatically by the SDK as latest), causing CI to fail. Instead of making even more changes, I have instead pinned acceptance tests to use Terraform 0.12 (as it was before, or maybe 0.11? I don't know, with the legacy SDK) which still pass. Fixing these configs would be good to do later.

Upgrading

Upgrade details will be found in the release notes, but in case you've found your way here, instead:

No configuration changes should be necessary in using this provider (changes might be necessary in upgrading to Terraform 0.12+, though). As mentioned in this provider's documentation, it is considered best practice to pin a provider version to avoid bringing in potentially breaking changes automatically. To remain on previous versions of the provider until such time that you are able to accommodate upgrading to Terraform 0.12+, pin the installed version. Remember that as this provider is pre-1.0, 'minor' changes may signal breaking changes. In this example, we pin our configuration to only use patch versions of 0.23.x:

Terraform 0.13+

terraform {
  required_providers {
    tfe = {
      version = "~> 0.23.0"
    }
  }
}

Terraform 0.12

provider "tfe" {
  version = "~> 0.23.0"
  ...
}

Full documentation on how to pin a version of a provider can be found on the Terraform Website.

Testing plan

All resources and APIs should be thoroughly tested to ensure no regressions with the major SDK upgrade.


Closes #108

This is the result of running the tf-sdk-migrator tool
This complex API behavior (https://github.com/hashicorp/terraform-provider-tfe/blob/1836332f965b90962c2b852b86baa7b9482bbcac/website/docs/r/team_access.html.markdown#L41-L52)
was bound to have _something_ to change in V2 of the SDK.

Per hashicorp/terraform-plugin-sdk@83c83c4 :

These schema validations are now not allowed for computed attributes, as
it is assumed that computed attributes are *always* computed; this API,
however, relies on the fact that a user can specify either "access" or
"permissions" and whichever is not specified is computed, and
vice-versa.

With this removal, it's sadly possible to specify multiple "permissions"
blocks without an error (but there should be); this will result in a
plan attempting to add a second set of permissions that results in a
no-op (as only the first item in the permissions list is used).

It's probably possible to munge further into the CustomizeDiff logic to
just return an error ourselves at plan time should there be data at
"permissions.1.*", but I'm not going to touch that right now.
The output in V2 of the SDK must have changed slightly, as the
whitespacing looks ever so different and the messages aren't anchored to
the beginning of the line as expected here, so the tests fail.

The regexs here don't need to be this strict. Search for the substring
and that's a-ok.
In V2 of the SDK, acceptance tests are done using a real Terraform
binary and not via the inner workings of Terraform itself.

By default, the latest version of Terraform is installed and used
(unless specified via options to use a path or version)

In upgrading to the V2 SDK, it seems that we actually have some test
configurations that are not compatible with 0.13 (the current version,
as of this writing), and cause tests to fail:

=== FAIL: tfe TestAccTFEOrganizationMembershipDataSource_basic (1.60s)
    data_source_organization_membership_****.go:16: Step 1/1 error: Error running pre-apply plan:
        Error: Error retrieving organization memberships: resource not found

=== FAIL: tfe TestAccTFEWorkspaceIDsDataSource_basic (1.56s)
    data_source_workspace_ids_****.go:16: Step 1/1 error: Error running pre-apply plan:
        Error: Error retrieving workspaces: resource not found

This issue is due to a known issue with 0.13, issue number 26074 on
hashicorp/terraform, and I confirmed that even using SDKv1 these tests
fail if you use Terraform 0.13. Because of this, let's just force usage
of 0.12 (which is how things are run now) and fix these configurations
separately.
Now that the upgrade is complete, bump from 2.0 to 2.3
Copy link
Member

@radditude radditude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and local testing was all green!

website/docs/index.html.markdown Outdated Show resolved Hide resolved
@chrisarcand chrisarcand merged commit 5a80a5a into master Dec 10, 2020
@chrisarcand chrisarcand deleted the provider-sdk-2-0 branch December 10, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TFE provider to use terraform v0.12.x syntax
2 participants