synalabs / terraspace_plugin_scaleway

Terraspace Scaleway Provider
Apache License 2.0
1 stars 0 forks source link

Bug: expansion broken with Terraspace 0.7.x #1

Closed IceBear2k closed 2 years ago

IceBear2k commented 2 years ago

Terraspace has changed expansion lookups with the release of 0.7.0.

Lookups for :REGION or :ZONE don't seem to be correctly delegated to the Scaleway plugin anymore. The following setup works correctly with 0.6.x:

❯ env | grep SCW
SCW_DEFAULT_REGION=fr-par
SCW_DEFAULT_ZONE=fr-par-1
[...]
❯ cat config/terraform/tfvars/base.tfvars
scw_region = "<%= expansion(':REGION') %>"
scw_zone = "<%= expansion(':ZONE') %>"
[...]
❯ terraspace validate cluster
I, [2022-01-06T08:47:28.753986 #2344]  INFO -- : Building .terraspace-cache/dev/stacks/cluster
I, [2022-01-06T08:47:31.020011 #2344]  INFO -- : Built in .terraspace-cache/dev/stacks/cluster
I, [2022-01-06T08:47:31.034492 #2344]  INFO -- : Current directory: .terraspace-cache/dev/stacks/cluster
I, [2022-01-06T08:47:31.038357 #2344]  INFO -- : => terraform init -get -input=false >> /tmp/terraspace/log/init/cluster.log
E, [2022-01-06T08:47:31.151758 #2344] ERROR -- : Error refreshing state: MissingRegion: could not find region configuration
E, [2022-01-06T08:47:31.152041 #2344] ERROR -- : Error running command: terraform init -get -input=false >> /tmp/terraspace/log/init/cluster.log
❯ cat .terraspace-cache/dev/stacks/cluster/1-project-base.auto.tfvars
scw_region = ""
scw_zone = ":ZONE"
[...]
IceBear2k commented 2 years ago

I have further analyzed this issue and it turns out it's not the expansion that's not working, it's the loading of the Scaleway plugin entirely.

https://github.com/boltops-tools/terraspace/pull/195 has changed how Terraspace autodetects plugins, especially option number 2 is relevant here:

backend.tf parsing - will try to find the s3, azurerm, gcs backend and use the right terraspace plugin based on that.

Since Scaleway also uses S3 as a backend, Terraspace believes it has successfully identified usage of the AWS plugin, resulting in the above error messages.

To fix this, and make the Scaleway plugin usable with any Terraspace version >= 0.7.0 (including 1.x), simply add the following to the project's config/terraform/app.rb:

Terraspace.configure do |config|
  config.autodetect.expander = "scaleway"
end

This will overwrite the autodetection (mentioned as option number 1 in the PR above).

Might be worth noting in the plugin's documentation.