简体   繁体   English

LocalStack 使用 terraform 在本地创建 S3 Bucket 没有名称

[英]LocalStack Create S3 Bucket locally with terraform doesn't have a name

Aloha,阿罗哈,

TL&DR:长话短说:

I am trying to create an s3 bucket locally by using terraform instead of awscli or awslocal and i am running in some errors.我正在尝试使用 terraform 而不是 awscli 或 awslocal 在本地创建一个 s3 存储桶,但我遇到了一些错误。 I am wondering if this way is even supported by localstack.我想知道 localstack 是否支持这种方式。 I am not sure what i did wrong here but i guess i need to use the awscli here to create s3 buckets.我不确定我在这里做错了什么,但我想我需要在这里使用 awscli 来创建 s3 存储桶。 Anyone has an idea why the bucket name is not forwarded?任何人都知道为什么不转发存储桶名称?

Long Version:长版:

I am using a docker-compose.yaml to define the localstack docker container:我正在使用 docker-compose.yaml 来定义 localstack docker 容器:

version: '3'

services:
  localstack:
    image: localstack/localstack:0.10.5
    ports:
    - "4572:4572"
    - "4584:4584"
    - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
    - DEFAULT_REGION=eu-central-1
    - SERVICES=s3,secretsmanager
    - DEBUG=${DEBUG- }
    - DATA_DIR=${DATA_DIR- }
    - PORT_WEB_UI=${PORT_WEB_UI- }
    - DOCKER_HOST=${LOCALSTACK_DOCKER_HOST-unix:///var/run/docker.sock}
    - TF_VAR_localstack_host=localhost
    volumes:
    - "/var/run/docker.sock:/var/run/docker.sock"

I use this terraform main.tf to define what i want to create in the docker container:我使用这个 terraform main.tf 来定义我想在 docker 容器中创建的内容:

variable "localstack_host" {
  default = "localhost"
}

provider "aws" {
  version = "~> 2.39.0"
  alias = "local"
  region = "eu-central-1"
  access_key = "This is not an actual access key."
  secret_key = "This is not an actual secret key."
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true
  endpoints {
    secretsmanager  = "http://${var.localstack_host}:4584"
    s3              = "http://${var.localstack_host}:4572"
  }
}

resource "aws_s3_bucket" "s3_encryption_test_bucket" {
  bucket = "s3-encryption-test-bucket"
  provider = "aws.local"
}

After running the docker container I then apply the terraform file to the local running instance of localstack:运行 docker 容器后,我将 terraform 文件应用到本地运行的 localstack 实例:

terraform plan
terraform apply

The error i get from terraform is:我从 terraform 得到的错误是:

aws_s3_bucket.s3_encryption_test_bucket: Creating...
  acceleration_status:         "" => "<computed>"
  acl:                         "" => "private"
  arn:                         "" => "<computed>"
  bucket:                      "" => "s3-encryption-test-bucket"
  bucket_domain_name:          "" => "<computed>"
  bucket_regional_domain_name: "" => "<computed>"
  force_destroy:               "" => "false"
  hosted_zone_id:              "" => "<computed>"
  region:                      "" => "<computed>"
  request_payer:               "" => "<computed>"
  versioning.#:                "" => "<computed>"
  website_domain:              "" => "<computed>"
  website_endpoint:            "" => "<computed>"
aws_s3_bucket.s3_encryption_test_bucket: Still creating... (10s elapsed)
aws_s3_bucket.s3_encryption_test_bucket: Still creating... (20s elapsed)
.....
aws_s3_bucket.s3_encryption_test_bucket: Still creating... (2m10s elapsed)
aws_s3_bucket.s3_encryption_test_bucket: Still creating... (2m20s elapsed)

Error: Error applying plan:

1 error(s) occurred:

* aws_s3_bucket.s3_encryption_test_bucket: 1 error(s) occurred:

* aws_s3_bucket.s3_encryption_test_bucket: error getting S3 Bucket CORS configuration: timeout while waiting for state to become 'success' (timeout: 2m0s)

I also looked into the logs of the container and got this error message:我还查看了容器的日志并收到此错误消息:

2019-12-12T13:24:45:ERROR:localstack.services.generic_proxy: Error forwarding request: Parameter validation failed:
Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" Traceback (most recent call last):
  File "/opt/code/localstack/localstack/services/generic_proxy.py", line 240, in forward
    path=path, data=data, headers=forward_headers).......

I hade the same problem, the solution for me was adding s3_force_path_style = true to provider "aws" section:我遇到了同样的问题,我的解决方案是将s3_force_path_style = true添加到provider "aws"部分:

provider "aws" {
  ...
  s3_force_path_style = true
  ...
}

I encountered the same issue.我遇到了同样的问题。 Simply defining ACL in resource block solved it for me:简单地在资源块中定义 ACL 为我解决了这个问题:

resource "aws_s3_bucket" "s3_encryption_test_bucket" {
  bucket = "s3-encryption-test-bucket"
  provider = "aws.local"
  acl = "private"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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