https://github.com/randomtask2000/terraform-ec2-instance
Simple example of how to provision an EC2 instance with Terraform
https://github.com/randomtask2000/terraform-ec2-instance
Last synced: 3 months ago
JSON representation
Simple example of how to provision an EC2 instance with Terraform
- Host: GitHub
- URL: https://github.com/randomtask2000/terraform-ec2-instance
- Owner: randomtask2000
- License: mit
- Created: 2018-12-19T12:17:56.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-22T17:28:00.000Z (about 7 years ago)
- Last Synced: 2025-01-23T08:44:11.540Z (about 1 year ago)
- Language: HCL
- Size: 119 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Terraform ec2 instance
Simple example of how to provision an EC2 instance with Terraform. This repo is used to show how to use AWS CodeBuild as a `Terraform` service [here](https://github.com/randomtask2000/terraform_codebuild_ec2_instance).
## Setup
Create a settings file `terraform.auto.tfvars` that will configure access to your `AWS VPC` and let you `ssh` into your `EC2` instance after you're done:
```
echo <<< EOL
aws_access_key = "XXXXXXXXXXXXXXXXXXXX"
aws_secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
aws_region = "us-east-1"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQ...rf+M7Q== my@laptop.local"
vpc_id = "vpc-00000000x00x0xxx0"
EOL >> terraform.auto.tfvars;
```
## Run Terraform
After you're done creating the above file and adding your `aws access key`, `secret` and your `ssh public key`, run the following:
```
terraform init
terraform plan
echo yes | terraform apply
```
To remove the instance you run:
```
echo yes | terraform destroy
```
## Done
You're done and have fun!