V
V
Vitaly Karasik2021-08-01 16:58:03
Amazon Web Services
Vitaly Karasik, 2021-08-01 16:58:03

How to iterate over servers in Terraform?

I have a dozen Transfer Servers, and two dozen users.
I need to go through the list of servers and create two users per server.
I read several docs ( https://blog.gruntwork.io/terraform-tips-tricks-lo... etc.) and tried, but it doesn't work.
Terraform is the newest - 1.0.3.
Advise, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2021-08-02
@vitaly_il1

Vitaly Karasik

Eugene, I want to do this Terraform

Terraform is an infrastructure provisioning tool .
tf manages infrastructure resources and stores their state in the state in order to calculate changes when parameters or code change tf will not.
Of course, you can use a crutch in the form of a null resource that simply launches a sh \ posh \ cmd script, which will take data from somewhere to connect to your servers, whose user data you need to create
Terraform essentially does not manage this resource, it will only execute / over-execute (by triggers on the state of other resources in tf) your script. About the insecurity of storing credentials in this way, I think you should not be reminded.
Similarly, instead of a script, there can be an ansible\chief (possibly through a provider) or something else that is also launched by a terraform (but the state of the created "resources" = users will be stored, again, not by terraforms, which means that we are not talking about management)
No need to hammer with pliers nails. Yes, in some cases it is possible to do this, but it creates more problems than it solves
. By the way, a hint of how to hammer a nail with pliers is contained in the description of null_resource - link above.

V
Vasily Shakhunov, 2021-08-01
@inf

In general, ansible should do this.
Terraform for this task can only be used when creating new servers, since the internal state of the server is not reflected in any way in the state of the terraform.
The classic solution is to use the user data attribute in the ec2 instance configuration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question