To use aws or docker as provider when running localstack from container

I’m attempting to use terraform to build out infrastructure on a localstack that is running in a docker container. I clearly don’t know what i’m doing. I don’t know if it’s a networking issue or provider issue but it keeps on giving me a connection refused.

---[ REQUEST POST-SIGN ]-----------------------------
GET /terraform-000000000000?prefix=env%3A%2F HTTP/1.1
Host: localhost:4572
User-Agent: aws-sdk-go/1.25.3 (go1.12.13; linux; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.12.16
Authorization: AWS4-HMAC-SHA256 Credential=ASIA5UUKUUTPODVJA4NG/20191203/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=d1e62721ad944bce7a3c2d3d1ba48819ada2d61c35c6e9362eea0436fe71d049
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20191203T172138Z
Accept-Encoding: gzip


-----------------------------------------------------
2019/12/03 17:21:38 [DEBUG] [aws-sdk-go] DEBUG: Send Request s3/ListObjects failed, attempt 5/5, error RequestError: send request failed
caused by: Get http://localhost:4572/terraform-000000000000?prefix=env%3A%2F: dial tcp 127.0.0.1:4572: connect: connection refused

MY terraform looks like.

terraform {
backend “s3” {
bucket = “terraform-000000000000”
key = “local/terraform.tfstate”
region = “us-east-1”
endpoint = “http://localhost:4572
access_key = “ASIA5UUKUUTPODVJA4NG”
secret_key = “9KfQ6xJzmUGWhoytZEwD3iwKopX63gaq2qFM9xYO”
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}

resource “docker_container” “aoms_docker_terraform” {
image = “${docker_image.ubuntu.latest}”
name = “aoms_docker_terraform”
}

resource “docker_image” “ubuntu” {
name = “ubuntu:latest”
}

provider “docker” {
version = “~> 2.40”
access_key = “ASIA5UUKUUTPODVJA4NG”
secret_key = “9KfQ6xJzmUGWhoytZEwD3iwKopX63gaq2qFM9xYO”
region = “us-east-1”
s3_force_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
host = “tcp://localhost:2376”
//skip_requesting_account_id = true

endpoints {
s3 = “http://localhost:4572
apigateway = “http://localhost:4567
cloudformation = “http://localhost:4581
cloudwatch = “http://localhost:4582
dynamodb = “http://localhost:4564
es = “http://localhost:4578
iam = “http://localhost:4593
kinesis = “http://localhost:4568
lambda = “http://localhost:4574
redshift = “http://localhost:4577
route53 = “http://localhost:4580
secretsmanager = “http://localhost:4584
ses = “http://localhost:4579
sns = “http://localhost:4575
sqs = “http://localhost:4576
ssm = “http://localhost:4583
stepfunctions = “http://localhost:4585
sts = “http://localhost:4592
}
}

module “persistence” {
source = “…/…/modules/persistence”
environment = var.environment
}

module “events” {
source = “…/…/modules/events”
environment = var.environment
event_delay_time_in_seconds = var.event_delay_time_in_seconds
lambda_function_time_limit_in_seconds = var.lambda_function_time_limit_in_seconds
}

Hi
From what I can see in the error log, you get connection refused from the S3 endpoint of localstack.
Are you sure that localstack is running at all?

If you try and remove the backend stanza of the terraform definition so you use tfstate file in the current folder for storing state, what happens?