Skip to content

Errors during tflocal init #70

@togakangaroo

Description

@togakangaroo

Running tflocal init

File ~/.pyenv/versions/3.12.6/lib/python3.12/site-packages/botocore/handlers.py:295, in validate_bucket_name(params, **kwargs)
    294 bucket = params['Bucket']
--> 295 if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
    296     error_msg = (
    297         f'Invalid bucket name "{bucket}": Bucket name must match '
    298         f'the regex "{VALID_BUCKET.pattern}" or be an ARN matching '
    299         f'the regex "{VALID_S3_ARN.pattern}"'
    300     )

TypeError: expected string or bytes-like object, got 'list'

Why?

Well, terraform-local seems to use hcl2 to parse terraform files.

I have a perfectly standard provider.tf file

terraform {
  required_version = "~> 1.8"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.91"
    }
    awscc = {
      source  = "hashicorp/awscc"
      version = "~> 0.14"
    }
    archive = {
      source  = "hashicorp/archive"
      version = "~> 2.4"
    }
  }

  backend "s3" {
    bucket = "ninety-terraform-state"
    key    = "devops-infra"
    region = "us-east-1"
  }
}

provider "aws" {
  region = "us-east-1"
}

provider "awscc" {
  region = "us-east-1"
}

When I parse that with hcl2 I get

with open('/home/gmauer/code/ninety-infra/devops/provider.tf', 'r') as fp:
   foo = hcl2.load(fp)


In [25]:     ...:     ...: 
In [26]: foo
Out[26]: 
{'terraform': [{'required_version': ['~> 1.8'],
   'required_providers': [{'aws': [{'source': 'hashicorp/aws',
       'version': '~> 5.91'}],
     'awscc': [{'source': 'hashicorp/awscc', 'version': '~> 0.14'}],
     'archive': [{'source': 'hashicorp/archive', 'version': '~> 2.4'}]}],
   'backend': [{'s3': {'bucket': ['ninety-terraform-state'],
      'key': ['devops-infra'],
      'region': ['us-east-1']}}],
   '__start_line__': 1,
   '__end_line__': 23}],
 'provider': [{'aws': {'region': ['us-east-1'],
    '__start_line__': 25,
    '__end_line__': 27}},
  {'awscc': {'region': ['us-east-1'],
    '__start_line__': 29,
    '__end_line__': 31}}]}

see that backend[0].s3.bucket? It's a list! The type signature of the handling code is pretty clear that it expects an str

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions