i tried to use depend_on on other module to automate configure the backend for my terraform,tfstae after creating a bucket :
module "s3_module" {
source = "./module/S3"
}
# module "s3_backend" {
# source = "./module/S3_backend"
# depends_on = [ module.s3_module ]
# }
but it didnt work and i got a message below:
Warning: Backend configuration ignored
│
│ on moduleS3_backends3_backend.tf line 9, in terraform:
│ 9: backend "s3" {
│
│ Any selected backend applies to the entire configuration, so Terraform expects provider
│ configurations only in the root module.
│
│ This is a warning rather than an error because it’s sometimes convenient to temporarily call
│ a root module as a child module for testing purposes, but this backend configuration block
│ will have no effect.
and there is a way to automate this ?
2
Answers
Thanks, a lot that's was satisfying answer
We can’t create both the backend and actual resources at the same time. To use s3 as the backend. We have to create the backend s3 bucket separately. There are multiple ways to create an s3 bucket(aws cli, aws console, aws cdk, cloudformation, terraform with local backend, etc)
Once the s3 bucket is created, configure it as a terraform backend for actual resource creation.
In general, the backend should be created before we run
terraform init
for actual resource creation.