EC2 customize in the same resource (v 11)

I am building 3 ec2 instances. They are basically the same, however I need to be able to customize an environment context on each one (they all get deployed to the same aws account, vpc, region, subnet).

  1. prod
  2. test
  3. dev

I defined an ec2 resource and can use resource_count to deploy 3 instances.
How can I differentiate them from each other? ex. Populate a file in a home dir that will contain the environment.

Or do I need to create 3 separate resources?

In the past I could a variable, that would be different for each environment, but I was deploying each instance to a separate “environment”.

I also might need to assign a different IAM role based on the environment (but not a requirement).

You could define them separately.

You could create an object variable with a list of key/value pairs for the items you need to specify and use for_each in the resource block to create one resource for each entry in the list, pulling the attributes from the key/value pairs.

You could create a module which wraps up the resource and accepts a small number of variables to set the attributes you need.

There are likely other ways too :slight_smile: