|
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. --> |
3 | 2 |
|
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> |
5 | 4 |
|
6 |
| -###### main.tf |
7 |
| -contain resource code for ec2 instance. |
8 | 5 |
|
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> |
11 | 9 |
|
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> |
14 | 13 |
|
15 |
| -## Infrastructure creats by this module |
| 14 | +<p align="center"> |
16 | 15 |
|
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> |
19 | 22 |
|
20 | 23 |
|
| 24 | +</p> |
| 25 | +<p align="center"> |
21 | 26 |
|
| 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= |
0 commit comments