---
type: archive
area: archive
status: archived
date: 2026-05-03
created: 2026-05-03
updated: 1980-01-01
tags:
  - archive
---
#### Create Aws EC2 instance with terraform
![[img-20240920-160047-24a85fe6.png]]
![[img-20240920-160109-331d0bbf.png]]
#### Generate key pairs
to make it easy to connect to created aws ec2 instance
![[img-20240920-160359-d21b298d.png]]
or
![[img-20240920-160424-5ce4b7df.png]]
![[img-20240920-160440-30d38991.png]]
#### Create security group to attach it to **EC2** instance
![[img-20240920-161039-92c57395.png]]
Add this to previous resources block that contains **ec2** instance definition
![[img-20240920-161109-1c78920c.png]]
#### How to run some initialization on an instance
![[img-20240920-192221-5a1b4434.png]]
![[img-20240920-192350-f56cf3dc.png]]
By default provisioner are run after resources is created (create time provisionner)
![[img-20240920-192621-6e98c9e5.png]]
Destroy time provisioner 
![[img-20240920-192641-881f7d14.png]]
when can also add on_failure argument {continue, fail} fail to stop execution and continue to pass this error and continue executing
provisioners specificaly remote one need a connection bloc to run commands in provisionned resources
![[img-20240920-213439-3a457205.png]]
userdata is recommended over remote-provisionners
