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

Terraform Up and Running, 3rd Edition, Chapter 4, Modularizing MySQL #103

Closed 0x1uke closed 1 year ago

0x1uke commented 1 year ago

I'm working through Terraform Up and Running. I'm on chapter 4, and I notice in the example code a module is only created for the webserver-cluster service but not for the MySQL datastore. Is there a reason why one can't modularize MySQL to follow the DRY principle?

I gave it shot, but I'm stuck with a cycle error in my MySQL module between the db_username and dp_password input variables and trying to pass those values to the child modules as output variables. The idea I'm getting at is one would pass the db_username and db_password as environment variables and the child module will have access to them to create the database using the parent module. I suppose I could create a variables.tf in the prod and stage MySQL directories defining the db_username and db_password variables, but that also seems repetitive. I've included a link below to my code for more detail.

https://github.com/0x1uke/terraform-up-and-running

Thank you!

brikis98 commented 1 year ago

I'm working through Terraform Up and Running. I'm on chapter 4, and I notice in the example code a module is only created for the webserver-cluster service but not for the MySQL datastore. Is there a reason why one can't modularize MySQL to follow the DRY principle?

The book does turn the MySQL code into a module, but it's a bit later, in chapter 7, under the "Working with Multiple AWS Regions" section.

I gave it shot, but I'm stuck with a cycle error in my MySQL module between the db_username and dp_password input variables and trying to pass those values to the child modules as output variables. The idea I'm getting at is one would pass the db_username and db_password as environment variables and the child module will have access to them to create the database using the parent module. I suppose I could create a variables.tf in the prod and stage MySQL directories defining the db_username and db_password variables, but that also seems repetitive. I've included a link below to my code for more detail.

https://github.com/0x1uke/terraform-up-and-running

Thank you!

From a quick look at your code:

0x1uke commented 1 year ago

Yevgeniy,

Thank you for your reply. In case I get stuck, I'll take a look at the DB module in Chapter 7, but I really appreciate the sanity check that a variables.tf is required in the DB staging and prod because I wasn't sure if I was missing something. I'll also fix the terraform_remote_state piece. I'll close this issue out.

Thank you again, and thank you for the awesome book.

brikis98 commented 1 year ago

Glad to help and happy to hear you're enjoying the book!