brikis98 / terraform-up-and-running-code

Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
http://www.terraformupandrunning.com/
MIT License
2.83k stars 1.9k forks source link

Ed. 2, Ch. 4 - Terraform modules. Remote state location for webserver uses key for mysql #78

Closed ncthanh2000 closed 1 year ago

ncthanh2000 commented 2 years ago

The file is stage/services/webserver-cluster/main.tf

module "webserver_cluster" {
  source = "../../../modules/services/webserver-cluster"
  cluster_name = "webservers-stage"
  db_remote_state_bucket = "(YOUR_BUCKET_NAME)"
  db_remote_state_key = "stage/data-stores/mysql/"
}

Should remote_state_key have been stage/services/webserver-cluster/terraform.tfstate instead?

brikis98 commented 1 year ago

Note that the parameter is called db_remote_state_key, so this is the key for the database. The webserver-cluster module uses a terraform_remote_state data source to look up the state at this key and reads outputs from it (e.g., the DB address and port). So I believe pointing it at the mysql key is correct.