Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate terraform with atlassian/localstack?

Terraform can be configured with custom S3 endpoints and it seems that localstack can create local stacks for S3, SES, Cloudformation and few others services.

The question is what to write in Terraform configuration to use localstack's S3 endpoint?

like image 921
cphoover Avatar asked May 11 '17 13:05

cphoover


2 Answers

Terraform does not officially support "AWS-workalike" systems, since they often have subtle quirks and differences relative to AWS itself. However, it is supported on a best-effort basis and may work if localstack is able to provide a sufficiently realistic impression of S3 for Terraform's purposes.

According to the localstack docs, by default the S3 API is exposed at http://localhost:4572 , so setting the custom endpoint this way may work:

provider "aws" {
  endpoints {
    s3 = "http://localhost:4572"
  }
}

Depending on the capabilities of localstack, you may need to set some other settings:

  • s3_force_path_style to use a path-based addressing scheme for buckets and objects.
  • skip_credentials_validation, since localstack seems to lack an implementation of the AWS token service.
  • skip_metadata_api_check if IAM-style credentials will not be used, to prevent Terraform from trying to get credentials from the EC2 metadata API.
like image 53
Martin Atkins Avatar answered Oct 17 '22 11:10

Martin Atkins


Building off @martin-atkins’ answer, here’s a sample Terraform file that works with Localstack:

provider "aws" {
  region = "us-east-1"
  access_key = "anaccesskey"
  secret_key = "asecretkey"
  skip_credentials_validation = true
  skip_metadata_api_check = true
  s3_force_path_style = true
  endpoints {
    s3 = "http://localhost:4572"
  }
}

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket"
  acl    = "public-read"
}
like image 11
Geoffrey Booth Avatar answered Oct 17 '22 13:10

Geoffrey Booth