Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

improve autodetection for plugin expander for backend like remote #195

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

tongueroo
Copy link
Contributor

@tongueroo tongueroo commented Jan 24, 2022

This is a 🐞 bug fix.
This is a πŸ™‹β€β™‚οΈ feature or enhancement.

  • I've added tests (if it's a bug, feature or enhancement)
  • I've adjusted the documentation (if it's a feature or enhancement)
  • The test suite passes (run bundle exec rspec to verify this)

Summary

Fixes expander auto-detection bug with remote backend and a terraspace cloud plugin like aws. IE:

config/teraform/backend.tf

terraform {
  backend "remote" {
    organization = "<%= ENV['TFC_ORG'] %>" 
    workspaces {
      name = "<%= expansion('my-engine-:MOD_NAME-:ENV-:REGION-:ACCOUNT') %>"
    }
  }
}

When on-prem support was added, it changed the auto-detection to be only based what was parsed from config/terraform/backend.tf. So a remote backend would result in on-prem being detected, and the expansion variables would not be expanded correctly. Even though users would have terraspace_plugin_aws in their Gemfile and want to use the aws plugin expander, it would use the on-prem generic expander.

Before on-prem support, it was assumed that if the aws terraspace plugin was installed it would just use the aws plugin expander. That's why it previously worked.

But with on-prem support, the backend can be http, remote, etc and the terraspace plugin and its expander cannot be detected based on that.

Instead, this fix improves auto-detection so that Terraspace auto-detects based on:

  1. config.autodetect.expander - config setting that allows override of the auto-detection entirely.
  2. backend.tf parsing - will try to find the s3, azurerm, gcs backend and use the right terraspace plugin based on that.
  3. Gemfile: check what plugins are loaded in the Gemfile and auto-detect based on that.

#3 will solve the issue for users who were on 0.6 and had everything working. So there is no need to configure #1. It should just work.

#1 is provided as another configuration option if you need to override default auto-detection behavior.

Context

How to Test

Try a remote backend like so:

config/teraform/backend.tf

terraform {
  backend "remote" {
    organization = "<%= ENV['TFC_ORG'] %>" 
    workspaces {
      name = "<%= expansion('my-engine-:MOD_NAME-:ENV-:REGION-:ACCOUNT') %>"
    }
  }
}

Confirm your Gemfile has:

Gemfile:

gem "terraspace_plugin_aws"

Run

terraspace build

It should expand out the variables using the aws terrspace plugin expander. Example of something it'll look like:

$ cat .terraspace-cache/us-west-2/dev/stacks/demo/backend.tf
terraform {
  backend "remote" {
    organization = "boltops"
    workspaces {
      name = "demo-dev-us-west-2"
    }
  }
}

Version Changes

Patch

@tongueroo tongueroo merged commit a99caea into master Jan 24, 2022
@tongueroo tongueroo deleted the autodetect-expander branch January 24, 2022 01:44
@tongueroo
Copy link
Contributor Author

Released in 1.0.6

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant