简体   繁体   中英

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?

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.

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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM