Skip to content

Commit c9c990f

Browse files
committed
updates
1 parent 8b6fb84 commit c9c990f

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# out files from $ terraform plan command
9+
*.out*
10+
*.hcl*
11+
*.terraform*
12+
*.terraform.lock.hcl*
13+
14+
# SSH configurations files
15+
*id_rsa*
16+
17+
# Crash log files
18+
crash.log

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
1-
# terraform-aws-ec2-ssh-
2-
just a basic virtual instance
1+
# terraform-aws-ec2-ssh
2+
Terraform & AWS: How to provisioning and connect into the EC2 machine with SSH
3+
4+
## Table of Contents
5+
- [terraform-aws-ec2-ssh](#terraform-aws-ec2-ssh)
6+
- [Table of Contents](#table-of-contents)
7+
- [Requirements](#requirements)
8+
- [How does it work?](#how-does-it-work)
9+
- [Setup AWS credentials](#setup-aws-credentials)
10+
- [Create a AWS Key pairs](#create-a-aws-key-pairs)
11+
- [Create the Terraform files](#create-the-terraform-files)
12+
- [Terraform CLI Usage](#terraform-cli-usage)
13+
- [Contributing](#contributing)
14+
- [License](#license)
15+
16+
## Requirements
17+
- AWS Account
18+
- Terraform
19+
- AWS CLI
20+
- Linux CLI
21+
22+
## How does it work?
23+
Basically, the Terraform will create some resources on AWS, such as, EC2, SG and the Ansible will be invoked via Terraform resources (local-exec) to call Ansible Roles for then to install the Docker app on EC2 instance.
24+
25+
## Setup AWS credentials
26+
Use the AWS Documentation to setup your AWS Credentials, basically you have some ways to do this, for example via credentials file or environment variables:
27+
28+
- In my case I used the ```~/.aws/credentials``` file to create my credentials:
29+
30+
```
31+
[default]
32+
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
33+
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
34+
```
35+
36+
## Create a AWS Key pairs
37+
Now you can create your Key pairs on AWS following the AWS Documentation below:
38+
39+
- [Create AWS Key pairs](https://docs.aws.amazon.com/pt_br/AWSEC2/latest/UserGuide/ec2-key-pairs.html)
40+
41+
Remember you can create a Terraform resource to provision automatically:
42+
43+
```
44+
resource "aws_key_pair" "deployer" {
45+
key_name = "deployer-key"
46+
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"
47+
}
48+
```
49+
50+
## Create the Terraform files
51+
According to the best practices from the Terraform documentation, is necessary create several files ".tf" to keep the environment working fine, the Terraform will read all files ".tf" and will provision on the AWS Cloud.
52+
53+
- provider.tf
54+
- securityGroups.tf
55+
- ec2Intance.tf
56+
57+
## Terraform CLI Usage
58+
Main commands:
59+
60+
```
61+
init Prepare your working directory for other commands
62+
validate Check whether the configuration is valid
63+
plan Show changes required by the current configuration
64+
apply Create or update infrastructure
65+
destroy Destroy previously-created infrastructure
66+
```
67+
68+
Execute these commands after get completed before steps:
69+
70+
```
71+
$ terraform init
72+
$ terraform plan
73+
$ terraform apply
74+
$ terraform destroy
75+
```
76+
77+
## Contributing
78+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
79+
80+
Please make sure to update tests as appropriate.
81+
82+
## License
83+
[MIT](https://choosealicense.com/licenses/mit/)

provider.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 3.73.0"
6+
}
7+
}
8+
9+
}
10+
11+
provider "aws" {
12+
shared_credentials_file = "/home/amaurybsouza/.aws"
13+
profile = "devopsaws"
14+
region = "us-east-1"
15+
default_tags {
16+
tags = {
17+
Environment = "Test"
18+
Owner = "Amaury"
19+
maneged-by = "Terraform"
20+
Project = "Test"
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)