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

Fix Terraform 1.6 compat by finishing GetMetadata implementation #1089

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

nfagerlund
Copy link
Member

@nfagerlund nfagerlund commented Oct 4, 2023

Description

Fixes #1088

Providers implemented using the terraform-plugin-go library above version 0.19 or so must implement GetMetadata(), as part of supporting an optional memory usage improvement. See
hashicorp/terraform-plugin-sdk#1234 for the start of a breadcrumb trail with more details about this whole effort.

Almost nobody actually implements providers using terraform-plugin-go, but we do! It's one of our THREE muxed-together providers, because we once needed to do something that was impossible in the SDK before the new framework existed. It's used for ONE data source, tfe_outputs.

This function was added (with a blank return value) in #1046 and no one noticed a problem, presumably because acceptance tests were running with a Terraform version that didn't exercise the new memory-saving code path, instead just calling GetProviderSchema however many times.

But, Terraform 1.6 does exercise it, and it turns out a blank value causes it to bail out early with a not-found for the tfe_outputs data source.

This commit adds our lonely data source to the low-level provider's metadata, which fixes the issue. Longer-term, we should... probably migrate that data source to the framework and delete that whole third provider.

Remember to:

Testing plan

  1. Make a lil config that exercises at least one element from EACH internal provider server, just to really make sure!!!

Swap in your own organization and workspace names as needed, but here, try this:

terraform {
  required_providers {
    tfe = {
      source = "hashicorp/tfe"
      version = "0.49.1"
    }
  }
}

provider "tfe" {
  hostname = "app.terraform.io"
  organization = "nicktech"
}

data "tfe_outputs" "radish" {
    workspace = "horse-radish"
}

data "tfe_workspace" "radish" {
    name = "horse-radish"
}

output "outs" {
    value = data.tfe_outputs.radish.nonsensitive_values
}

output "outers" {
    value = data.tfe_workspace.radish.id
}

resource tfe_variable "oddish" {
    workspace_id = data.tfe_workspace.radish.id
    key = "extraneous"
    value = "vaaalllllluuuuueeeeee"
    category = "terraform"
}
  1. Try and apply it with Terraform 1.6.0. The tfe_outputs data source will blow up with a Not Implemented! (But, it works in 1.5 if you try that.)
╷
│ Error: Data Source Not Implemented
│
│   with data.tfe_outputs.radish,
│   on main.tf line 17, in data "tfe_outputs" "radish":
│   17: data "tfe_outputs" "radish" {
│
│ The combined provider does not implement the requested data source type. This is always an issue in the provider
│ implementation and should be reported to the provider developers.
│
│ Missing data source type: tfe_outputs
╵
  1. Build this branch of the provider, set your dev overrides to use your local build artifact, and do an apply with 1.6. Everything works!

Since I always forget how to do dev overrides:

TF_CLI_CONFIG_FILE=~/.terraformrc-dev-overrides

# In ~/.terraformrc-dev-overrides: 
provider_installation {
  dev_overrides {
    "hashicorp/tfe" = "/Users/nick/Documents/code/terraform-provider-tfe"
    "nfagerlund/fakerancher" = "/Users/nick/Documents/code/terraform-provider-fakerancher"
  }

  # For all other providers, install them directly from their origin provider
  # registries as normal. If you omit this, Terraform will _only_ use
  # the dev_overrides block, and so no other providers will be available.
  direct {}
}

Output from acceptance tests

I work here, so see CI output.

Providers implemented using the `terraform-plugin-go` library above version 0.19
or so must implement GetMetadata(), as part of supporting an optional memory
usage improvement. See
hashicorp/terraform-plugin-sdk#1234 for the start of a
breadcrumb trail with more details about this whole effort.

Almost nobody actually implements providers using terraform-plugin-go, but we
do! It's one of our THREE muxed-together providers, because we once needed to do
something that was impossible in the SDK before the new framework existed. It's
used for ONE data source, `tfe_outputs`.

This function was added (with a blank return value) in
#1046 and no one noticed
a problem, presumably because acceptance tests were running with a Terraform
version that didn't exercise the new memory-saving code path, instead just
calling GetProviderSchema however many times.

But, Terraform 1.6 *does* exercise it, and it turns out a blank value causes it
to bail out early with a not-found for the tfe_outputs data source.

This commit adds our lonely data source to the low-level provider's metadata,
which fixes the issue. Longer-term, we should... probably migrate that data
source to the framework and delete that whole third provider.
@nfagerlund nfagerlund requested a review from a team as a code owner October 4, 2023 22:27
Copy link
Collaborator

@uturunku1 uturunku1 left a comment

Choose a reason for hiding this comment

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

It works!

@nfagerlund nfagerlund merged commit 8995fb5 into main Oct 4, 2023
11 of 12 checks passed
@nfagerlund nfagerlund deleted the nf/oct23-terraform1.6support branch October 4, 2023 23:59
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.

Terraform 1.6.0 breaks "tfe_outputs" data source
2 participants