# Creating an infra using Terraform

As, I already mentioned Terraform introduction earlier on previous page.

#### **Prerequisites**

1. IAM User with required ec2 policy
2. aws cli
3. terraform installed

{% content-ref url="../../terraform" %}
[terraform](https://abisec.gitbook.io/devsecops/terraform)
{% endcontent-ref %}

Also the terraform installation part.

{% content-ref url="../../terraform/terraform-installation" %}
[terraform-installation](https://abisec.gitbook.io/devsecops/terraform/terraform-installation)
{% endcontent-ref %}

Here is the terraform code which can be used to create an infra.

{% embed url="<https://github.com/whoami-anoint/wazu/tree/main/terraform>" %}

1. Clone the repo and use it

```
git clone https://github.com/whoami-anoint/wazu/
cd terraform/infra-templates/prod-minimal/
terraform validate
terraform init
terraform plan
terraform apply -auto-approve
```

2. In case you want to destroy the infra, use the given command

```
terraform destroy -auto-approve
```

***

Let's check the validity of our terraform code:

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2Fk6gnvykV4tXHD4wEkLnX%2Fimage.png?alt=media&#x26;token=05f7cbfe-eb66-494c-adf9-49178ad7ad59" alt="" width="348"><figcaption></figcaption></figure>

**The configuration is valid**.

*Pending issue on this challenge.*

*As I am using the organizational aws labs for learning purpose, I do have no access for this policy to create ec2 from iam users (aws cli) on this terraform. But we can try with any other account as we can see our code is valid too.*

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2F9ggmGfqiz2pC2pjhMFBt%2Fimage.png?alt=media&#x26;token=289c2472-589b-457b-91f0-b6530ba234c2" alt=""><figcaption></figcaption></figure>
