Skip to content

Commit

Permalink
add dynamic tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Dugar committed Oct 14, 2019
1 parent 3c7e291 commit d83a91f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ This module has a few dependencies:




## Examples


**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).


### Simple Example
Here is an example of how you can use this module in your inventory structure:
```hcl
module "ec2" {
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.1"
name = "ec2-instance"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.2"
name = "ec2-instance"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
instance_count = 2
ami = "ami-08d658f84a6d84a80"
ebs_optimized = false
Expand All @@ -86,16 +88,20 @@ Here is an example of how you can use this module in your inventory structure:
disk_size = 8
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
subnet_ids = tolist(module.public_subnets.public_subnet_id)
assign_eip_address = true
ebs_volume_enabled = true
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
assign_eip_address = true
ebs_volume_enabled = true
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
instance_tags = {"snapshot"=true}
}
```






## Inputs

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



## Testing

## Testing
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.

You need to run the following command in the testing folder:
Expand Down
21 changes: 11 additions & 10 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ usage : |-
Here is an example of how you can use this module in your inventory structure:
```hcl
module "ec2" {
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.1"
name = "ec2-instance"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.2"
name = "ec2-instance"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
instance_count = 2
ami = "ami-08d658f84a6d84a80"
ebs_optimized = false
Expand All @@ -52,10 +52,11 @@ usage : |-
disk_size = 8
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
subnet_ids = tolist(module.public_subnets.public_subnet_id)
assign_eip_address = true
ebs_volume_enabled = true
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
assign_eip_address = true
ebs_volume_enabled = true
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
instance_tags = {"snapshot"=true}
}
```
1 change: 1 addition & 0 deletions _example/.terraform.tfstate.lock.info
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
3 changes: 2 additions & 1 deletion _example/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module "ssh" {
}

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

name = "ec2-instance"
application = "clouddrove"
Expand All @@ -88,4 +88,5 @@ module "ec2" {
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
instance_tags = { "snapshot" = true }
}
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ resource "aws_instance" "default" {
{

"Name" = format("%s%s%s", module.labels.id, var.delimiter, (count.index + 1))
}
},
var.instance_tags
)

volume_tags = merge(
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,10 @@ variable "cpu_credits" {
type = string
default = "standard"
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."
}

variable "instance_tags" {
type = map
default = {}
description = "Instance tags."
}

0 comments on commit d83a91f

Please sign in to comment.