A guide for a newbie on modules

On the main.tf on the module I configure this:

terraform {
  backend "s3" {
    #Replace this with your bucket name!
    bucket  = var.webserver_cluster_state_bucket
    key     =var.webserver_cluster_state_key
    region  = "us-east-2"
    #Replace this with your DynamoDB table name!
    dynamodb_table = var.dynamodb_table
    encrypt = true

and I am using here main.tf

module "webserver_cluster" {
  source                         = "../../../modules/services/webserver-cluster"
  webserver_cluster_state_bucket = "terraform-up-and-runningv2"
  webserver_cluster_state_key    = "prod/services/webserver-cluster/terraform.tfstate"
dynamodb_table                 = "terraform-up-and-runningv2"

Why the remote state is not updated? Do I need to define this inside of code of the second main.tf?

You appear to be trying to place a backend configuration block inside a reusable module. This is not how Terraform works.

You define a backend block only in the top level directory of your Terraform configuration. Modules provide a way to re-use portions of Terraform code, but all state associated with them is stored in the backend defined for the entire configuration as a whole.

1 Like

Thank you . Got it .