3 ms·
Instead of env conditionals, I strongly recommended feature/functionality conditionals or variables. E.g. var.create_s3 is better than var env == 'prod'
by manfre 2y ago
Instead of env conditionals, I strongly recommended feature/functionality conditionals or variables. E.g. var.create_s3 is better than var env == 'prod'
- baby_souffle 2y ago+1 for this. Do as much as you can in modules and write each of your modules to have a simple enable or disable input.
- bloopernova 2y agoI just wanted to clarify: are you referring to this pattern? module "cool_name" { count = var.create_cool_name ? 1 : 0 } I've always wanted a simple enable/disable syntax for modules in tf.
- baby_souffle 2y ago> I just wanted to clarify: are you referring to this pattern? Does TF support count on modules now?! The pattern I was referring to is akin to having an `enabled` var that you define in _every_ module (there are ways to make this easier to do [0]) and inside of each module you have a local { make_the_s3_bucket = var.enabled && var.make_s3_bucket make_the_rds_instance = var.enabled && var.enable_rds } Then you use the typical `count: foo == bar ? 1:0` trick where some part of the `foo/bar` conditional ropes in local.make_the_rds_instance [0]: https://github.com/cloudposse/terraform-null-label/tree/main https://github.com/cloudposse/terraform-null-label/tree/main
- bloopernova 2y agoYeah I use the count attribute on modules all the time. Thank you for replying though, I appreciate it :)
- bloopernova 2y agohttps://developer.hashicorp.com/terraform/language/modules/syntax https://developer.hashicorp.com/terraform/language/modules/s... count - Creates multiple instances of a module from a single module block. for_each - Creates multiple instances of a module from a single module block. providers - Passes provider configurations to a child module. If not specified, the child module inherits all of the default (un-aliased) provider configurations from the calling module. depends_on - Creates explicit dependencies between the entire module and the listed targets. I hope this doesn't come across as snarky, I just wanted to share the doc link :)