Created
June 8, 2016 17:50
-
-
Save c4urself/c9e1546a3b4bd6f6cfa70c80c16fa397 to your computer and use it in GitHub Desktop.
How to dynamically tag instance via a module in Terraform?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "ami_id" { } | |
variable "subnet_id" { } | |
variable "security_group_id" { } | |
variable "key_name" { } | |
variable "instance_profile" { } | |
variable "instance_type" { } | |
variable "instance_name" { } | |
variable "hostname" { } | |
variable "tag_role" { } | |
variable "tag_cost_environment" { } | |
variable "tag_critical" { } | |
variable "tag_environment" { } | |
variable "tag_extra_one" { } | |
variable "tag_extra_two" { } | |
variable "tag_extra_three" { } | |
resource "template_file" "user_data" { | |
template = "${file("${path.module}/../../_utilities/bootstrap.sh")}" | |
vars { | |
hostname = "${var.hostname}" | |
} | |
} | |
resource "aws_instance" "instance" { | |
instance_type = "${var.instance_type}" | |
iam_instance_profile = "${var.instance_profile}" | |
ami = "${var.ami_id}" | |
key_name = "${var.key_name}" | |
vpc_security_group_ids = ["${var.security_group_id}"] | |
subnet_id = "${var.subnet_id}" | |
tags { | |
Name = "${var.instance_name}" | |
Roles = "${var.tag_role}" | |
Environment = "${var.tag_environment}" | |
CostEnvironment = "${var.tag_cost_environment}" | |
Critical = "${var.tag_critical}" | |
# How to do additional tags? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you find any way to do that?