Skip to content

Fail to run TFLocal apply from docker container #12975

@tal-rofe

Description

@tal-rofe

Hi, I try to use LocalStack with Terraform. I try to avoid installing TFLocal on my machine, but instead run it in Terraform.
To do so, I created the following docker compose file:

services:
    localstack:
        env_file: ./envs/.env.development
        container_name: localstack
        image: localstack/localstack
        ports:
            - '127.0.0.1:4566:4566'
            - '127.0.0.1:4510-4559:4510-4559'
        environment:
            - DEBUG=0
            - PERSISTENCE=0
        volumes:
            - './volume/localstack:/var/lib/localstack'
            - '/var/run/docker.sock:/var/run/docker.sock'
        networks:
            - my_network

    local_terraform_setup:
        build:
            context: .
            dockerfile: Dockerfile.local-terraform-setup
        container_name: local-terraform-setup
        environment:
            AWS_ENDPOINT_URL: http://localstack:4566
        volumes:
            - ../terraform:/workspace
        working_dir: /workspace/development
        networks:
            - my_network

networks:
    my_network:
        name: my_network

And created this Dockerfile (Dockerfile.local-terraform-setup):

FROM hashicorp/terraform:1.12.1

RUN apk add --no-cache python3 py3-pip
RUN pip install --upgrade --break-system-packages pip
RUN pip install --break-system-packages terraform-local

Then I run the following script:

docker compose -f ../../docker/docker-compose.dev.yaml run --rm --entrypoint tflocal local_terraform_setup init
docker compose -f ../../docker/docker-compose.dev.yaml run --rm --entrypoint tflocal local_terraform_setup apply -auto-approve

The init script succeeds - but the apply does not.

Log:

Plan: 6 to add, 0 to change, 0 to destroy.
╷
│ Error: listing S3 Buckets: operation error S3: ListBuckets, exceeded maximum number of attempts, 9, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Get "http://s3.localhost.localstack.cloud:4566/?x-id=ListBuckets": dial tcp 127.0.0.1:4566: connect: connection refused
│ 
│   with module.payments_invoices_storage.module.payments_invoices_storage_s3_bucket.data.aws_canonical_user_id.this[0],
│   on .terraform/modules/payments_invoices_storage.payments_invoices_storage_s3_bucket/main.tf line 3, in data "aws_canonical_user_id" "this":
│    3: data "aws_canonical_user_id" "this" {
│ 
╵
╷
│ Error: listing S3 Buckets: operation error S3: ListBuckets, exceeded maximum number of attempts, 9, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Get "http://s3.localhost.localstack.cloud:4566/?x-id=ListBuckets": dial tcp 127.0.0.1:4566: connect: connection refused
│ 
│   with module.resume_storage.module.resume_storage_s3_bucket.data.aws_canonical_user_id.this[0],
│   on .terraform/modules/resume_storage.resume_storage_s3_bucket/main.tf line 3, in data "aws_canonical_user_id" "this":
│    3: data "aws_canonical_user_id" "this" {
│ 
╵

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions