Skip to content

Instantly share code, notes, and snippets.

@c4urself
Created June 8, 2016 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c4urself/c9e1546a3b4bd6f6cfa70c80c16fa397 to your computer and use it in GitHub Desktop.
Save c4urself/c9e1546a3b4bd6f6cfa70c80c16fa397 to your computer and use it in GitHub Desktop.
How to dynamically tag instance via a module in Terraform?
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?
}
}
@luisdalves
Copy link

Did you find any way to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment