Skip to content

Commit b905b18

Browse files
author
Kamlesh
committed
terraform 0.12.0
1 parent 2173452 commit b905b18

File tree

14 files changed

+740
-136
lines changed

14 files changed

+740
-136
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ignored files
2+
*.tfstate
3+
*.tfstate.backup
4+
.terraform
5+
.idea
6+
*.iml

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.12.0
4+
hooks:
5+
- id: terraform_fmt
6+
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v2.0.0
9+
hooks:
10+
- id: check-merge-conflict
11+
- id: trailing-whitespace
12+
- id: check-yaml
13+
- id: check-added-large-files

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Cloud Drove
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export GENIE_PATH ?= $(shell 'pwd')/../../../genie
2+
3+
include $(GENIE_PATH)/Makefile

README.md

100755100644
Lines changed: 184 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,193 @@
1-
AWS EC2 MODULE
2-
==============
1+
<!-- This file was automatically generated by the `geine`. Make all changes to `README.yaml` and run `make readme` to rebuild this file. -->
32

4-
This module is for create ec2 instance with related resources.
3+
<p align="center"> <img src="https://user-images.githubusercontent.com/50652676/62349836-882fef80-b51e-11e9-99e3-7b974309c7e3.png" width="100" height="100"></p>
54

6-
###### main.tf
7-
contain resource code for ec2 instance.
85

9-
###### variables.tf
10-
contain variables declaration. all variables are empty by default. we will define or put value to variables in equls.tf (main file for infrastructure). these are input vars.
6+
<h1 align="center">
7+
Terraform AWS EC2
8+
</h1>
119

12-
###### outputs.tf
13-
is alse contain variables but we will these variables for output like ec2 instance id.
10+
<p align="center" style="font-size: 1.2rem;">
11+
Terraform module to create an EC2 resource on AWS with Elastic IP Addresses and Elastic Block Store.
12+
</p>
1413

15-
## Infrastructure creats by this module
14+
<p align="center">
1615

17-
1. EC2
18-
16+
<a href="https://www.terraform.io">
17+
<img src="https://img.shields.io/badge/Terraform-v0.12-green" alt="Terraform">
18+
</a>
19+
<a href="LICENSE.md">
20+
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="Licence">
21+
</a>
1922

2023

24+
</p>
25+
<p align="center">
2126

27+
<a href='https://facebook.com/sharer/sharer.php?u=https://github.com/clouddrove/terraform-aws-ec2'>
28+
<img title="Share on Facebook" src="https://user-images.githubusercontent.com/50652676/62817743-4f64cb80-bb59-11e9-90c7-b057252ded50.png" />
29+
</a>
30+
<a href='https://www.linkedin.com/shareArticle?mini=true&title=Terraform+AWS+EC2&url=https://github.com/clouddrove/terraform-aws-ec2'>
31+
<img title="Share on LinkedIn" src="https://user-images.githubusercontent.com/50652676/62817742-4e339e80-bb59-11e9-87b9-a1f68cae1049.png" />
32+
</a>
33+
<a href='https://twitter.com/intent/tweet/?text=Terraform+AWS+EC2&url=https://github.com/clouddrove/terraform-aws-ec2'>
34+
<img title="Share on Twitter" src="https://user-images.githubusercontent.com/50652676/62817740-4c69db00-bb59-11e9-8a79-3580fbbf6d5c.png" />
35+
</a>
36+
37+
</p>
38+
<hr>
39+
40+
41+
We eat, drink, sleep and most importantly love **DevOps**. We are working towards stratergies 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.
42+
43+
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.
44+
45+
We have [*fifty plus terraform modules*][terraform_modules]. A few of them are comepleted and are available for open source usage while a few others are in progress.
46+
47+
48+
49+
50+
## Prerequisites
51+
52+
This module has a few dependencies:
53+
54+
- [Terraform 0.12](https://learn.hashicorp.com/terraform/getting-started/install.html)
55+
- [Go](https://golang.org/doc/install)
56+
- [github.com/stretchr/testify/assert](https://github.com/stretchr/testify)
57+
- [github.com/gruntwork-io/terratest/modules/terraform](https://github.com/gruntwork-io/terratest)
58+
59+
60+
61+
62+
63+
64+
## Examples
65+
66+
**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-ec2/releases).
67+
68+
69+
### Simple Example
70+
Here is an example of how you can use this module in your inventory structure:
71+
```hcl
72+
module "ec2" {
73+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git"
74+
name = "ec2-instance"
75+
application = "clouddrove"
76+
environment = "test"
77+
label_order = ["environment", "name", "application"]
78+
instance_count = 2
79+
ami = "ami-08d658f84a6d84a80"
80+
ebs_optimized = false
81+
instance_type = "t2.nano"
82+
key_name = module.keypair.name
83+
monitoring = false
84+
associate_public_ip_address = true
85+
tenancy = "default"
86+
disk_size = 8
87+
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
88+
subnet_ids = tolist(module.public_subnets.public_subnet_id)
89+
assign_eip_address = true
90+
ebs_volume_enabled = true
91+
ebs_volume_type = "gp2"
92+
ebs_volume_size = 30
93+
user_data = "./_bin/user_data.sh"
94+
}
95+
```
96+
97+
98+
99+
## Inputs
100+
101+
| Name | Description | Type | Default | Required |
102+
|------|-------------|:----:|:-----:|:-----:|
103+
| ami | The AMI to use for the instance. | string | - | yes |
104+
| application | Application (e.g. `cd` or `clouddrove`). | string | `` | no |
105+
| assign_eip_address | Assign an Elastic IP address to the instance. | bool | `false` | no |
106+
| associate_public_ip_address | Associate a public IP address with the instance. | bool | `true` | no |
107+
| attributes | Additional attributes (e.g. `1`). | list | `<list>` | no |
108+
| availability_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region. | string | `` | no |
109+
| cpu_core_count | Sets the number of CPU cores for an instance. | string | `` | no |
110+
| cpu_credits | The credit option for CPU usage. Can be `standard` or `unlimited`. T3 instances are launched as unlimited by default. T2 instances are launched as standard by default. | string | `standard` | no |
111+
| delimiter | Delimiter to be used between `organization`, `environment`, `name` and `attributes`. | string | `-` | no |
112+
| disable_api_termination | If true, enables EC2 Instance Termination Protection. | bool | `false` | no |
113+
| disk_size | Size of the root volume in gigabytes. | number | `8` | no |
114+
| ebs_block_device | Additional EBS block devices to attach to the instance. | list | `<list>` | no |
115+
| ebs_device_name | Name of the EBS device to mount. | list(string) | `<list>` | no |
116+
| ebs_iops | Amount of provisioned IOPS. This must be set with a volume_type of io1. | number | `0` | no |
117+
| ebs_optimized | If true, the launched EC2 instance will be EBS-optimized. | bool | `false` | no |
118+
| ebs_volume_enabled | Flag to control the ebs creation. | bool | `false` | no |
119+
| ebs_volume_size | Size of the EBS volume in gigabytes. | number | `30` | no |
120+
| ebs_volume_type | The type of EBS volume. Can be standard, gp2 or io1. | string | `gp2` | no |
121+
| environment | Environment (e.g. `prod`, `dev`, `staging`). | string | `` | no |
122+
| ephemeral_block_device | Customize Ephemeral (also known as Instance Store) volumes on the instance. | list | `<list>` | no |
123+
| host_id | The Id of a dedicated host that the instance will be assigned to. Use when an instance is to be launched on a specific dedicated host. | string | `` | no |
124+
| iam_instance_profile | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | string | `` | no |
125+
| instance_count | Number of instances to launch. | number | `1` | no |
126+
| instance_enabled | Flag to control the instance creation. | bool | `true` | no |
127+
| instance_initiated_shutdown_behavior | Shutdown behavior for the instance. | string | `` | no |
128+
| instance_type | The type of instance to start. Updates to this field will trigger a stop/start of the EC2 instance. | string | - | yes |
129+
| ipv6_address_count | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. | number | `0` | no |
130+
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface. | list | `<list>` | no |
131+
| key_name | The key name to use for the instance. | string | `` | no |
132+
| label_order | Label order, e.g. `name`,`application`. | list | `<list>` | no |
133+
| monitoring | If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0). | bool | `false` | no |
134+
| name | Name (e.g. `app` or `cluster`). | string | `` | no |
135+
| network_interface | Customize network interfaces to be attached at instance boot time. | list(map(string)) | `<list>` | no |
136+
| placement_group | The Placement Group to start the instance in. | string | `` | no |
137+
| root_block_device | Customize details about the root block device of the instance. See Block Devices below for details. | list | `<list>` | no |
138+
| source_dest_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. | bool | `true` | no |
139+
| subnet | VPC Subnet ID the instance is launched in. | string | `` | no |
140+
| subnet_ids | A list of VPC Subnet IDs to launch in. | list(string) | `<list>` | no |
141+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | map | `<map>` | no |
142+
| tenancy | The tenancy of the instance (if the instance is running in a VPC). An instance with a tenancy of dedicated runs on single-tenant hardware. The host tenancy is not supported for the import-instance command. | string | `` | no |
143+
| user_data | The Base64-encoded user data to provide when launching the instances. | string | `` | no |
144+
| vpc_security_group_ids_list | A list of security group IDs to associate with. | list(string) | `<list>` | no |
145+
146+
## Outputs
147+
148+
| Name | Description |
149+
|------|-------------|
150+
| arn | The ARN of the instance. |
151+
| az | The availability zone of the instance. |
152+
| instance_count | The count of instances. |
153+
| instance_id | The instance ID. |
154+
| ipv6_addresses | A list of assigned IPv6 addresses. |
155+
| key_name | The key name of the instance. |
156+
| placement_group | The placement group of the instance. |
157+
| private_ip | Private IP of instance. |
158+
| public_ip | Public IP of instance (or EIP). |
159+
| subnet_id | The EC2 subnet ID. |
160+
| vpc_security_group_ids | The associated security groups in non-default VPC. |
161+
162+
163+
164+
## Testing
165+
166+
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.
167+
168+
You need to run the following command in the testing folder:
169+
```hcl
170+
go test -run Test
171+
```
172+
173+
174+
175+
## Feedback
176+
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 [hello@clouddrove.com](mailto:hello@clouddrove.com).
177+
178+
If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-ec2)!
179+
180+
## About us
181+
182+
At [CloudDrove][website], we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.
183+
184+
<p align="center">We are <b> The Cloud Experts!</b></p>
185+
<hr />
186+
<p align="center">We ❤️ <a href="https://github.com/clouddrove">Open Source</a> and you can check out <a href="https://github.com/clouddrove">our other modules</a> to get help with your new Cloud ideas.</p>
187+
188+
[website]: https://clouddrove.com
189+
[github]: https://github.com/clouddrove
190+
[linkedin]: https://cpco.io/linkedin
191+
[twitter]: https://twitter.com/clouddrove/
192+
[email]: https://clouddrove.com/contact-us.html
193+
[terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language=

README.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
#
3+
# This is the canonical configuration for the `README.md`
4+
# Run `make readme` to rebuild the `README.md`
5+
#
6+
7+
# Name of this project
8+
name : Terraform AWS EC2
9+
10+
# License of this project
11+
license: "MIT"
12+
13+
# Canonical GitHub repo
14+
github_repo: clouddrove/terraform-aws-ec2
15+
16+
# Badges to display
17+
badges:
18+
- name: "Terraform"
19+
image: "https://img.shields.io/badge/Terraform-v0.12-green"
20+
url: "https://www.terraform.io"
21+
- name: "Licence"
22+
image: "https://img.shields.io/badge/License-MIT-blue.svg"
23+
url: "LICENSE.md"
24+
25+
# description of this project
26+
description: |-
27+
Terraform module to create an EC2 resource on AWS with Elastic IP Addresses and Elastic Block Store.
28+
29+
# extra content
30+
include:
31+
- "terraform.md"
32+
33+
# How to use this project
34+
usage : |-
35+
### Simple Example
36+
Here is an example of how you can use this module in your inventory structure:
37+
```hcl
38+
module "ec2" {
39+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git"
40+
name = "ec2-instance"
41+
application = "clouddrove"
42+
environment = "test"
43+
label_order = ["environment", "name", "application"]
44+
instance_count = 2
45+
ami = "ami-08d658f84a6d84a80"
46+
ebs_optimized = false
47+
instance_type = "t2.nano"
48+
key_name = module.keypair.name
49+
monitoring = false
50+
associate_public_ip_address = true
51+
tenancy = "default"
52+
disk_size = 8
53+
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
54+
subnet_ids = tolist(module.public_subnets.public_subnet_id)
55+
assign_eip_address = true
56+
ebs_volume_enabled = true
57+
ebs_volume_type = "gp2"
58+
ebs_volume_size = 30
59+
user_data = "./_bin/user_data.sh"
60+
}
61+
```

_example/_bin/user_data.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
sudo apt-get update && sudo apt-get install -y python

0 commit comments

Comments
 (0)