Terraform tips & tricks: loops, if-statements, and gotchas
Yevgeniy Brikman

Thanks for all your really good posts!

I read this one with special interest and wanted to ask you if you can think of a workaround for the conditional use of blocks/objects in modules? You recomend to avoid inline blocks (and use separate resources) in your previous post but it’s not always possible.

For example, if I have a module using the aws_dynamodb_table resource how can I have a variable number of attribute blocks? Another similar case would be a generic s3_bucket module in which I would make conditional use of the various objects supported by the aws_s3_bucket resource.

Maybe my understanding of modules is incorrect and I’m trying to generalise them too much?

I know that the support for conditional logic is under discussion in the Terraform community but maybe there are hacks that I haven’t thought about that could provide an equivalent result for the time being!