newcontext-oss / kitchen-terraform

Test Kitchen plugins for testing Terraform configurations
https://github.com/newcontext/kitchen-terraform
Apache License 2.0
1.13k stars 146 forks source link

Support for localstack AWS testing #519

Open meltingturret opened 1 year ago

meltingturret commented 1 year ago

Any thoughts on an easy way for configure terraform kitchen to converge against localstack? For verification I am using awsspec and the verifier does respond to http_proxy configuration fine but the provisioner does not.

driver:
  name: "terraform"
  variable_files:
    - testing.tfvars

provisioner:
  name: "terraform"

platforms:
  - name: "aws"

verifier:
  name: "awspec"

suites:
  - name: default
    verifier:
      #default_pattern: true
      patterns:
        - spec/**/*_spec.rb

When I run bundle exec kitchen converge aws is updated and not localstack running on http://localhost:4566.

I want to avoid adding this in the aws provider:

provider "aws" {
  endpoints {
    ec2            = "http://localhost:4566"
    s3             = "http://s3.localhost.localstack.cloud:4566"
    secretsmanager = "http://localhost:4566"
    ses            = "http://localhost:4566"
    sns            = "http://localhost:4566"
    sqs            = "http://localhost:4566"
    ssm            = "http://localhost:4566"
    stepfunctions  = "http://localhost:4566"
    sts            = "http://localhost:4566"
  }
}
aaron-lane commented 1 year ago

Hi @meltingturret šŸ‘‹šŸ¼

Based on the AWS provider documentation, it does not appear that there is any alternative to specifying the custom endpoints within the provider configuration. If you would like to avoid hard-coding that configuration in your main module then I suggest you create a separate test module which invokes your main module and includes the necessary provider configuration. You can override which module Kitchen-Terraform tests using the transport.root_module_directory configuration.