Skip to content

Commit 87cf93c

Browse files
author
Sohan Yadav
authored
Merge pull request #20 from clouddrove/0.15
Fix terratest and volume parts
2 parents 9c61d62 + 89725d2 commit 87cf93c

File tree

18 files changed

+325
-313
lines changed

18 files changed

+325
-313
lines changed

.github/workflows/readme.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: 'Create README.md file'
23
on:
34
push:
@@ -10,15 +11,15 @@ jobs:
1011
runs-on: ubuntu-latest
1112
steps:
1213
- name: 'Checkout'
13-
uses: actions/checkout@master
14+
uses: actions/checkout@v2.3.4
1415

1516
- name: Set up Python 3.7.
1617
uses: actions/setup-python@v2
1718
with:
1819
python-version: '3.x'
1920

2021
- name: 'create readme'
21-
uses: 'clouddrove/github-actions@v6.0'
22+
uses: 'clouddrove/github-actions@v8.0'
2223
with:
2324
actions_subcommand: 'readme'
2425
github_token: '${{ secrets.GITHUB}}'
@@ -35,7 +36,7 @@ jobs:
3536
continue-on-error: true
3637

3738
- name: 'push readme'
38-
uses: 'clouddrove/github-actions@v6.0'
39+
uses: 'clouddrove/github-actions@v8.0'
3940
continue-on-error: true
4041
with:
4142
actions_subcommand: 'push'

.github/workflows/terraform.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
uses: actions/[email protected]
1414

1515
- name: 'Terraform Format'
16-
uses: 'clouddrove/github-actions@v7.0'
16+
uses: 'clouddrove/github-actions@v8.0'
1717
with:
1818
actions_subcommand: 'fmt'
1919
- name: 'Terraform Format'
20-
uses: 'clouddrove/github-actions@v7.0'
20+
uses: 'clouddrove/github-actions@v8.0'
2121
with:
2222
actions_subcommand: 'fmt'
2323

@@ -36,25 +36,25 @@ jobs:
3636
aws-region: us-east-2
3737

3838
- name: 'Terraform init'
39-
uses: 'clouddrove/github-actions@v7.0'
39+
uses: 'clouddrove/github-actions@v8.0'
4040
with:
4141
actions_subcommand: 'init'
4242
tf_actions_working_dir: ./_example/basic_example
4343

4444
- name: 'Terraform validate'
45-
uses: 'clouddrove/github-actions@v7.0'
45+
uses: 'clouddrove/github-actions@v8.0'
4646
with:
4747
actions_subcommand: 'validate'
4848
tf_actions_working_dir: ./_example/basic_example
4949

5050
- name: 'Terraform plan for basic_example'
51-
uses: 'clouddrove/github-actions@v7.0'
51+
uses: 'clouddrove/github-actions@v8.0'
5252
with:
5353
actions_subcommand: 'plan'
5454
tf_actions_working_dir: ./_example/basic_example
5555

56-
secure_example:
57-
name: 'secure_example'
56+
ebs_mount:
57+
name: 'ebs_mount'
5858
runs-on: ubuntu-latest
5959
steps:
6060
- name: 'Checkout'
@@ -67,30 +67,30 @@ jobs:
6767
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
6868
aws-region: us-east-2
6969

70-
- name: 'Terraform init'
71-
uses: 'clouddrove/github-actions@v7.0'
70+
- name: 'Terraform init for ebs_mount'
71+
uses: 'clouddrove/github-actions@v8.0'
7272
with:
7373
actions_subcommand: 'init'
74-
tf_actions_working_dir: ./_example/secure_example
74+
tf_actions_working_dir: ./_example/ebs_mount
7575

76-
- name: 'Terraform validate'
77-
uses: 'clouddrove/github-actions@v7.0'
76+
- name: 'Terraform validate for ebs_mount'
77+
uses: 'clouddrove/github-actions@v8.0'
7878
with:
7979
actions_subcommand: 'validate'
80-
tf_actions_working_dir: ./_example/secure_example
80+
tf_actions_working_dir: ./_example/ebs_mount
8181

82-
- name: 'Terraform plan for secure_example'
83-
uses: 'clouddrove/github-actions@v7.0'
82+
- name: 'Terraform plan for ebs_mount'
83+
uses: 'clouddrove/github-actions@v8.0'
8484
with:
8585
actions_subcommand: 'plan'
86-
tf_actions_working_dir: ./_example/secure_example
86+
tf_actions_working_dir: ./_example/ebs_mount
8787

8888
pre-commit:
8989
name: 'Pre-Commit'
9090
needs:
9191
- fmt
9292
- basic_example
93-
- secure_example
93+
- ebs_mount
9494
runs-on: ubuntu-latest
9595
steps:
9696
- name: 'Checkout'

.github/workflows/terratest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
- name: 'Terratest Basic'
2525
if: ${{ github.event.label.name == 'terratest' }}
26-
uses: 'clouddrove/github-actions@v6.0'
26+
uses: 'clouddrove/github-actions@v8.0'
2727
with:
2828
actions_subcommand: 'terratest'
2929
tf_actions_working_dir: '_test/basic_example'
@@ -32,10 +32,10 @@ jobs:
3232

3333
- name: 'Terratest Secure'
3434
if: ${{ github.event.label.name == 'terratest' }}
35-
uses: 'clouddrove/github-actions@v6.0'
35+
uses: 'clouddrove/github-actions@v8.0'
3636
with:
3737
actions_subcommand: 'terratest'
38-
tf_actions_working_dir: '_test/secure_example'
38+
tf_actions_working_dir: '_test/ebs_mount'
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Terraform AWS EC2
88
</h1>
99

10-
<p align="center" style="font-size: 1.2rem;">
10+
<p align="center" style="font-size: 1.2rem;">
1111
Terraform module to create an EC2 resource on AWS with ElasticC IP Addresses and Elastic Block Store.
1212
</p>
1313

@@ -38,7 +38,7 @@
3838
<hr>
3939

4040

41-
We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
41+
We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
4242

4343
This module is basically combination of [Terraform open source](https://www.terraform.io/) and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.
4444

@@ -49,7 +49,7 @@ We have [*fifty plus terraform modules*][terraform_modules]. A few of them are c
4949

5050
## Prerequisites
5151

52-
This module has a few dependencies:
52+
This module has a few dependencies:
5353

5454
- [Terraform 0.13](https://learn.hashicorp.com/terraform/getting-started/install.html)
5555
- [Go](https://golang.org/doc/install)
@@ -214,7 +214,7 @@ Here is examples of how you can use this module in your inventory structure:
214214

215215

216216
## Testing
217-
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
217+
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
218218

219219
You need to run the following command in the testing folder:
220220
```hcl
@@ -223,7 +223,7 @@ You need to run the following command in the testing folder:
223223

224224

225225

226-
## Feedback
226+
## Feedback
227227
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-ec2/issues), or feel free to drop us an email at [[email protected]](mailto:[email protected]).
228228

229229
If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-ec2)!

_example/basic_example/example.tf

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ module "http-https" {
4141
allowed_ports = [80, 443]
4242
}
4343

44+
module "keypair" {
45+
source = "clouddrove/keypair/aws"
46+
version = "0.15.0"
47+
48+
public_key = "ssh-rsa /5sw7eCjbjO5d20kqCTdvcW/J0J++mRiGHZULA0FysjNrK3wqqawb91//saHkXGjQHm0pueiAODiqSoM3u3MGJb2qX5o/CFtFlPZWLqVLlk1q+zeb/yWOWV42zsQ+X+Glh7ynqnYfIzyQT7Bs0xBv95RBQabsjhYfi9OgImLyN6OZtpMev2T1l90DW2DjZp1iqAXvXQuFLJu0ygNpMlK4Ot6ZhahzgBCPy6oVvaPIHzWpRGt7iBiSZB1QYXnlYQ0VcN6LHZk2oq1Jjjd0yDMzO71onIcd8P7qCwlUhis7Yeq5B+3nzZce9G3lSptwHnKG3CDByemUdXp4WKhYpsixQHImgrZjXvLJVyMDP5RSJp57BxxAw1CbjmWAbuAAR6BpOceLxYwsEscmYPyPISZMFLhge56TX4mqTSSX+fBtBEPC4hbqMdZAW9boHqoBChqffOdnUe3NFT0BuxqwsUbqBCx/AWBop5ASSds4rN6cdROml+UvlSrrAp3htSaBafrE+9x1sLG7P9R97xZGFTTlfZoJcXHZ/405EdsOcU8k2WZOJOrrf3R4995AQsotSB6vqia/rFaXtzDPGLaJqUkluzH7RPRYYKG2PqVJuXkMOLA0i/JNTGwNO14UDK+qBnWiwQeZzfJeHqJXy1eNMMZJVMDLn/qEUezhJjuCOIF1kYJclHmCZtd07y4R4B3/vOYdknuwughecV3iBxF+pAzy8MckPaZVaR+dHoyNoD4ua9eIVDF71aXnqBHd2B3n1o4+3Jd2axyOV1uFP8jhpMeVaesTA+K+/oW8Bq+52c+1rpdySU5aozOJEncyolC+DLEgRYGuAaiXNIR/IZFsDJHD+GByMtopPzu4kvGbyRZp/I0u43MMDlcjCTZJLhVntrI1spgTMElFcFepS5piL062xwY8S/gFAB3TJH4Rx+fcOkYsRh9wb4gJ0Wy+d7sHVu2qLYgBCeeSYBR4DLRTv57gcgE9hdaBo7b2AXPevPV3LbUGuqDkF+pEHOdMPCTgW4lOFxfl6vpitP+o8kErNdt8T8ftwJccHv5x6NLI82lUMfdo8qIV devops"
49+
key_name = "devops"
50+
environment = "test"
51+
label_order = ["name", "environment"]
52+
enable_key_pair = true
53+
}
54+
55+
4456
module "ssh" {
4557
source = "clouddrove/security-group/aws"
4658
version = "0.15.0"
@@ -76,7 +88,7 @@ module "kms_key" {
7688
description = "KMS key for ec2"
7789
deletion_window_in_days = 7
7890
enable_key_rotation = true
79-
alias = "alias/ec2"
91+
alias = "alias/ec2-instance"
8092
policy = data.aws_iam_policy_document.kms.json
8193
}
8294

@@ -121,37 +133,59 @@ data "aws_iam_policy_document" "iam-policy" {
121133
}
122134

123135
module "ec2" {
124-
source = "./../../"
125-
126-
name = "ec2-instance"
136+
source = "./../../"
137+
name = "ec2"
127138
environment = "test"
128139
label_order = ["name", "environment"]
129140

130-
instance_count = 2
131-
ami = "ami-08d658f84a6d84a80"
132-
instance_type = "t2.nano"
133-
monitoring = false
134-
tenancy = "default"
141+
#instance
142+
instance_enabled = true
143+
instance_count = 2
144+
ami = "ami-08d658f84a6d84a80"
145+
instance_type = "t2.nano"
146+
monitoring = false
147+
tenancy = "default"
148+
149+
#Networking
135150
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
136151
subnet_ids = tolist(module.public_subnets.public_subnet_id)
137-
138-
assign_eip_address = true
139-
associate_public_ip_address = true
140-
instance_profile_enabled = true
141-
iam_instance_profile = module.iam-role.name
142-
disk_size = 8
143-
ebs_optimized = false
144-
ebs_volume_enabled = true
145-
ebs_volume_type = "gp2"
146-
ebs_volume_size = 30
147-
instance_tags = { "snapshot" = true }
148-
dns_zone_id = "Z1XJD7SSBKXLC1"
149-
hostname = "ec2"
150-
kms_key_id = module.kms_key.key_arn
151-
metadata_http_tokens_required = true
152-
metadata_http_endpoint_enabled = true
153-
metadata_http_put_response_hop_limit = "2"
154-
delete_on_termination = false
155-
user_data = file("user-data.sh")
152+
assign_eip_address = true
153+
associate_public_ip_address = true
154+
155+
#Keypair
156+
key_name = module.keypair.name
157+
158+
#IAM
159+
instance_profile_enabled = false
160+
iam_instance_profile = module.iam-role.name
161+
162+
#Root Volume
163+
root_block_device = [
164+
{
165+
volume_type = "gp2"
166+
volume_size = 15
167+
delete_on_termination = true
168+
kms_key_id = module.kms_key.key_arn
169+
}
170+
]
171+
172+
#EBS Volume
173+
ebs_optimized = false
174+
ebs_volume_enabled = false
175+
ebs_volume_type = "gp2"
176+
ebs_volume_size = 30
177+
178+
#DNS
179+
dns_enabled = false
180+
dns_zone_id = "Z1XJD7SSBKXLC1"
181+
hostname = "ec2"
182+
183+
#Tags
184+
instance_tags = { "snapshot" = true }
185+
186+
# Metadata
187+
metadata_http_tokens_required = "optional"
188+
metadata_http_endpoint_enabled = "enabled"
189+
metadata_http_put_response_hop_limit = 2
156190

157191
}

_example/basic_example/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ output "instance_id" {
22
value = module.ec2.*.instance_id
33
description = "The instance ID."
44
}
5+
6+
output "tags" {
7+
value = module.ec2.tags
8+
description = "The instance tags."
9+
}

0 commit comments

Comments
 (0)