localstack / terraform-local

Terraform CLI wrapper to deploy your Terraform applications directly to LocalStack
Apache License 2.0
203 stars 24 forks source link

Region parsed as list #20

Closed rmvangun closed 1 year ago

rmvangun commented 1 year ago

I began getting the following error when using tflocal:

╷
│ Error: Invalid AWS Region: ['us-east-1']
│ 
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 15, in provider "aws":
│   15: provider "aws" {
│ 

This is odd, of course, because the region should be us-east-1 and not ['us-east-1']. I dug in, and it seems this is due to the HCL2 library parsing everything as a list. I specify the region in the provider block rather than falling back to AWS_DEFAULT_REGION, which results in the following being parsed (trimmed results to focus on the relevant piece):

... 'provider': [{'aws': {'region': ['${var.region}'], ...

I'm really not familiar with the HCL2 library and don't regularly write Python, but wanted to bring this up and determine if there is something I may be doing wrong or if this is a bug that should be remediated.

rmvangun commented 1 year ago

I'm running in to this again in another context, using a provider alias,

╷
│ Error: Invalid provider configuration alias
│ 
│ An alias must be a valid name. A name must start with a letter or underscore and may contain only letters, digits, underscores, and dashes.
╵

╷
│ Error: Missing base provider configuration for override
│ 
│   on localstack_providers_override.tf line 113:
│  113: provider "aws" {
│ 
│ There is no aws provider configuration with the alias "['us-west-2']". An override file can only override an aliased provider configuration that was already defined in a primary configuration
│ file.
╵

Again, the HCL2 library appears to return the provider as a list, so it's reading as ['us-west-2'] rather than just us-west-2 in the provider block in the override file. It seems like something is a little broken on my end, I wonder if this is due to a lack of version constraints in the terraform-local project? Could a requirements.txt help pin down libraries like HCL2? Or is something else causing this?

Terraform v1.5.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v5.8.0
+ provider registry.terraform.io/hashicorp/local v2.4.0
+ provider registry.terraform.io/hashicorp/random v3.5.1

Running the latest terraform-local, which I think is 0.11 based on the PyPI release history, though I don't see releases in this repo so I'm not sure what actual code those versions correspond to.

lakkeger commented 1 year ago

Closing the issue as it seems it has been patched by #23