Skip to content

Commit d83a91f

Browse files
author
Nikita Dugar
committed
add dynamic tags
1 parent 3c7e291 commit d83a91f

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

README.md

+18-11
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ This module has a few dependencies:
6161

6262

6363

64+
6465
## Examples
6566

67+
6668
**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).
6769

6870

6971
### Simple Example
7072
Here is an example of how you can use this module in your inventory structure:
7173
```hcl
7274
module "ec2" {
73-
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.1"
74-
name = "ec2-instance"
75-
application = "clouddrove"
76-
environment = "test"
77-
label_order = ["environment", "name", "application"]
75+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.2"
76+
name = "ec2-instance"
77+
application = "clouddrove"
78+
environment = "test"
79+
label_order = ["environment", "name", "application"]
7880
instance_count = 2
7981
ami = "ami-08d658f84a6d84a80"
8082
ebs_optimized = false
@@ -86,16 +88,20 @@ Here is an example of how you can use this module in your inventory structure:
8688
disk_size = 8
8789
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
8890
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"
91+
assign_eip_address = true
92+
ebs_volume_enabled = true
93+
ebs_volume_type = "gp2"
94+
ebs_volume_size = 30
95+
user_data = "./_bin/user_data.sh"
96+
instance_tags = {"snapshot"=true}
9497
}
9598
```
9699

97100

98101

102+
103+
104+
99105
## Inputs
100106

101107
| Name | Description | Type | Default | Required |
@@ -125,6 +131,7 @@ Here is an example of how you can use this module in your inventory structure:
125131
| instance_count | Number of instances to launch. | number | `1` | no |
126132
| instance_enabled | Flag to control the instance creation. | bool | `true` | no |
127133
| instance_initiated_shutdown_behavior | Shutdown behavior for the instance. | string | `` | no |
134+
| instance_tags | Instance tags. | map | `<map>` | no |
128135
| instance_type | The type of instance to start. Updates to this field will trigger a stop/start of the EC2 instance. | string | - | yes |
129136
| 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 |
130137
| ipv6_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface. | list | `<list>` | no |
@@ -161,8 +168,8 @@ Here is an example of how you can use this module in your inventory structure:
161168

162169

163170

164-
## Testing
165171

172+
## Testing
166173
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.
167174

168175
You need to run the following command in the testing folder:

README.yaml

+11-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ usage : |-
3636
Here is an example of how you can use this module in your inventory structure:
3737
```hcl
3838
module "ec2" {
39-
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.1"
40-
name = "ec2-instance"
41-
application = "clouddrove"
42-
environment = "test"
43-
label_order = ["environment", "name", "application"]
39+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.2"
40+
name = "ec2-instance"
41+
application = "clouddrove"
42+
environment = "test"
43+
label_order = ["environment", "name", "application"]
4444
instance_count = 2
4545
ami = "ami-08d658f84a6d84a80"
4646
ebs_optimized = false
@@ -52,10 +52,11 @@ usage : |-
5252
disk_size = 8
5353
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
5454
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"
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+
instance_tags = {"snapshot"=true}
6061
}
6162
```

_example/.terraform.tfstate.lock.info

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"ID":"47e23b37-aedf-eba4-4409-90e7f092db02","Operation":"OperationTypeApply","Info":"","Who":"nikita@nikita","Version":"0.12.9","Created":"2019-10-14T05:19:38.991300251Z","Path":"terraform.tfstate"}

_example/example.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module "ssh" {
6363
}
6464

6565
module "ec2" {
66-
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.1"
66+
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.2"
6767

6868
name = "ec2-instance"
6969
application = "clouddrove"
@@ -88,4 +88,5 @@ module "ec2" {
8888
ebs_volume_type = "gp2"
8989
ebs_volume_size = 30
9090
user_data = "./_bin/user_data.sh"
91+
instance_tags = { "snapshot" = true }
9192
}

main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ resource "aws_instance" "default" {
5757
{
5858

5959
"Name" = format("%s%s%s", module.labels.id, var.delimiter, (count.index + 1))
60-
}
60+
},
61+
var.instance_tags
6162
)
6263

6364
volume_tags = merge(

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,10 @@ variable "cpu_credits" {
250250
type = string
251251
default = "standard"
252252
description = "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."
253+
}
254+
255+
variable "instance_tags" {
256+
type = map
257+
default = {}
258+
description = "Instance tags."
253259
}

0 commit comments

Comments
 (0)