<p>Terraform would be the best resource to create these EC2 instances repeatedly. </p>

<p>I would highly recommend you to create a <code>variables.tf</code> or <code>terraform.tfvars</code> file template allowing you to create a new <em>instance</em> of these resources and store that file and the state file securely away for future management of the resources. A versioned S3 bucket would do quite well for this.</p>

<p>Please note that once you create your Terraform code you can instruct Terraform which state file(s) to work with, etc. Allowing you to <em>reuse</em> the same code over and over without duplication.</p>

CC BY-SA 4.0
2019-08-09T01:18:55.493Z
if have never used terraform ... is it worth learning its own config syntax ?  ... in the past I just used template text files then resolved env vars and used bash and sed to search N replace then it spit out all the various aws cli commands to spin up or teardown the cluster + instances + sg  etc ... not sure picking up terraform would help at this point
Scott Stensland
CC BY-SA 4.0
2019-08-08T23:46:26.067Z
2019-08-08T23:46:26.067Z
Steven K7FAQ
<p>Typically I spin up all aws ec2 instances together with all its accompanying security groups, volumes, etc ... by executing a series of aws cli commands.</p>

<p>However when I manually use the aws console in a browser to spin up instances, I am wondering if there is a tool I can run to exhaustively probe this set of running ec2 instances and output runable aws commands to recreate the currently running instances?</p>

<p>Does such a tool exist ?</p>

<p>I have never looked at Terraform, so I wonder if that has such a utility?</p>

CC BY-SA 4.0
2019-08-07T05:55:38.530Z
Although it won't produce AWS CLI commands, you can get what you want with Terraform. If that's acceptable to you, perhaps you could reword the question and this could be provided as an answer?
Bruce Becker
<amazon-web-services><amazon-ec2><terraform><aws-cli>
How to probe all running aws ec2 instances and their sec groups, etc to generate templates?
Scott Stensland
# How to probe all running aws ec2 instances and their sec groups, etc to generate templates?

(Asked by: username_0 on 2019-08-07)

Typically I spin up all aws ec2 instances together with all its accompanying security groups, volumes, etc ... by executing a series of aws cli commands.

However when I manually use the aws console in a browser to spin up instances, I am wondering if there is a tool I can run to exhaustively probe this set of running ec2 instances and output runable aws commands to recreate the currently running instances?

Does such a tool exist ?

I have never looked at Terraform, so I wonder if that has such a utility?

**Tags:** amazon-web-services, amazon-ec2, terraform, aws-cli

> **Comments:**
> **username_1**: Although it won't produce AWS CLI commands, you can get what you want with Terraform. If that's acceptable to you, perhaps you could reword the question and this could be provided as an answer?  

---

## 1 answers

### Answer by username_2 on 2019-08-08. Score: 1

Terraform would be the best resource to create these EC2 instances repeatedly.

I would highly recommend you to create a `variables.tf` or `terraform.tfvars` file template allowing you to create a new *instance* of these resources and store that file and the state file securely away for future management of the resources. A versioned S3 bucket would do quite well for this.

Please note that once you create your Terraform code you can instruct Terraform which state file(s) to work with, etc. Allowing you to *reuse* the same code over and over without duplication.

> **Comments:**
> **username_0**: if have never used terraform ... is it worth learning its own config syntax ?  ... in the past I just used template text files then resolved env vars and used bash and sed to search N replace then it spit out all the various aws cli commands to spin up or teardown the cluster + instances + sg  etc ... not sure picking up terraform would help at this point  

---

