Reputation: 1
I'm trying to init the backend in Terraform
this is the backend.tf
terraform {
backend "s3" {
dynamodb_table = "cpf-tflock-dev"
bucket = "s3_bucket"
key = "terraform.tfstate"
region = "us-east-1"
encrypt = true
}
}
terraform init
Error: Failed to get existing workspaces: Unable to list objects in S3 bucket "s3_bucket" with prefix "env:/": operation error S3: ListObjectsV2, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Get "http://s3_bucket.localhost:4566/?list-type=2&max-keys=1000&prefix=env%3A%2F": dial tcp: lookup s3_bucket.localhost: no such host
I'm trying to init the backend in terraform
The backend.tf
file is inside environment/dev/backend.tf
I'm trying to execute the terraform init in the dev folder. When I move the backend.tf
to the root of the project it's working fine. I'm using localstack for testing
Upvotes: 0
Views: 1800
Reputation: 541
I've seen other answers suggesting that you put access key data in here. you shouldn't do that. Configure a profile instead. Using the aws cli:
aws configure --profile your_profile
then pass the access key id and access key secret when prompted.
Alternatively, you can configure your profile manually by editing the credentials file. it should be located in ~/.aws/credentials
(that's for Linux and Mac).
it should be:
[your_profile]
aws_access_key_id=...
aws_secret_access_key=...
then, add the profile to your backend:
terraform {
backend "s3" {
dynamodb_table = "cpf-tflock-dev"
bucket = "s3_bucket"
key = "terraform.tfstate"
region = "us-east-1"
encrypt = true
profile = "your_profile"
}
}
Upvotes: 0
Reputation: 129
I think this issue is the answer. https://github.com/hashicorp/terraform/issues/34223
In short, try adding the access keys as parameters in the backend S3 provider.
Upvotes: 0
Reputation: 74025
s3_bucket.localhost
is not a globally-resolvable hostname, so it will work only if you've configured your local computer to resolve that hostname.
The LocalStack project offers a domain name localhost.localstack.cloud
which is currently configured to always resolve to the local loopback address 127.0.0.1
. If you use localhost.localstack.cloud
instead of just localhost
as your localstack domain then that should resolve as expected.
Upvotes: 0