ソースを参照

Adds Support for Instance Tags to Most Instance Modules

To be used to tag reservation status.

To be tagged v3.1.1
Fred Damstra [afs macbook] 3 年 前
コミット
47be882d36

+ 1 - 1
base/bastion/main.tf

@@ -134,7 +134,7 @@ resource "aws_instance" "instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
   volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
 }
 

+ 6 - 0
base/bastion/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 2 - 2
base/customer_portal/main.tf

@@ -24,7 +24,7 @@ resource "aws_launch_template" "customer_portal" {
   image_id      = local.ami_map[local.ami_selection]
   user_data     = data.template_cloudinit_config.cloud-init.rendered
   ebs_optimized = true
-  tags          = merge(var.standard_tags, var.tags)
+  tags          = merge(var.standard_tags, var.instance_tags, var.tags)
   key_name      = "msoc-build"
 
   iam_instance_profile {
@@ -147,7 +147,7 @@ resource "aws_launch_template" "customer_portal" {
 
   tag_specifications {
     resource_type = "instance"
-    tags = merge(var.tags, { "Name": var.instance_name }) # This may have no effect?
+    tags = merge(var.tags, var.instance_tags, { "Name": var.instance_name }) # This may have no effect?
   }
 
   tag_specifications {

+ 4 - 0
base/customer_portal/vars.tf

@@ -51,4 +51,8 @@ variable "proxy_public_ip" {
   
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
 

+ 1 - 1
base/dns/resolver_instance/main.tf

@@ -53,7 +53,7 @@ resource "aws_instance" "instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = local.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = local.instance_name })
 }
 
 module "private_dns_record" {

+ 6 - 0
base/dns/resolver_instance/vars.tf

@@ -16,6 +16,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "resolver_instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/github/backup_server.tf

@@ -119,7 +119,7 @@ resource "aws_instance" "ghe-backup-instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = "ghe-backup" })
+  tags = merge( var.standard_tags, var.tags, var.backup_instance_tags, { Name = "ghe-backup" })
   volume_tags = merge( var.standard_tags, var.tags, { Name = "ghe-backup" })
 }
 

+ 1 - 1
base/github/github_servers.tf

@@ -48,7 +48,7 @@ resource "aws_instance" "ghe" {
     iops = 3000
   }
 
-  tags = merge( var.standard_tags, var.tags, { Name = format("%s-%s", "github-enterprise", count.index) })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = format("%s-%s", "github-enterprise", count.index) })
   volume_tags = merge( var.standard_tags, var.tags, { Name = format("%s-%s", "github-enterprise", count.index) })
 }
 

+ 12 - 0
base/github/vars.tf

@@ -28,6 +28,18 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
+variable "backup_instance_tags" {
+  description = "Tags for the backup instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/jira/instance_jira/main.tf

@@ -129,7 +129,7 @@ resource "aws_instance" "jira-server-instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = "jira-server" })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = "jira-server" })
   volume_tags = merge( var.standard_tags, var.tags, { Name = "jira-server" })
 }
 

+ 6 - 0
base/jira/instance_jira/vars.tf

@@ -25,6 +25,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/mailrelay/instance-mailrelay2.tf

@@ -106,7 +106,7 @@ resource "aws_instance" "instance2" {
   }
 
   user_data = data.template_cloudinit_config.cloud_init_config2.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
   volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
 }
 

+ 6 - 0
base/mailrelay/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/nessus/instance_nessus_manager/main.tf

@@ -142,7 +142,7 @@ resource "aws_instance" "nessus-manager-instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
-  tags = merge( var.standard_tags, var.tags, { Name = "nessus-manager-${count.index}" })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = "nessus-manager-${count.index}" })
   volume_tags = merge( var.standard_tags, var.tags, { Name = "nessus-manager-${count.index}" })
 }
 

+ 6 - 0
base/nessus/instance_nessus_manager/vars.tf

@@ -24,6 +24,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/nessus/instance_nessus_scanner/main.tf

@@ -130,7 +130,7 @@ resource "aws_instance" "nessus-scanner-instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
-  tags = merge( var.standard_tags, var.tags, { Name = "nessus-scanner-${count.index}" })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = "nessus-scanner-${count.index}" })
   volume_tags = merge( var.standard_tags, var.tags, { Name = "nessus-scanner-${count.index}" })
 }
 

+ 6 - 0
base/nessus/instance_nessus_scanner/vars.tf

@@ -24,6 +24,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/nessus/instance_security_center/main.tf

@@ -129,7 +129,7 @@ resource "aws_instance" "security-center-instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = "security-center-0" })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = "security-center-0" })
   volume_tags = merge( var.standard_tags, var.tags, { Name = "security-center-0" })
 }
 

+ 6 - 0
base/nessus/instance_security_center/vars.tf

@@ -20,6 +20,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/phantom/main.tf

@@ -156,7 +156,7 @@ resource "aws_instance" "phantom-server-instance" {
 
   user_data = data.template_cloudinit_config.cloud-init[count.index].rendered
   tags = merge( var.standard_tags, var.tags, { Name = "phantom-${count.index}" })
-  volume_tags = merge( var.standard_tags, var.tags, { Name = "phantom-${count.index}" })
+  volume_tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = "phantom-${count.index}" })
 }
 
 # Render a multi-part cloud-init config making use of the part

+ 6 - 0
base/phantom/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/repo_server/main.tf

@@ -134,7 +134,7 @@ resource "aws_instance" "instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud_init_config.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
   volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
 }
 

+ 6 - 0
base/repo_server/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/salt_master/main.tf

@@ -134,7 +134,7 @@ resource "aws_instance" "instance" {
   }
 
   user_data = data.template_cloudinit_config.salt_master_cloud_init_config.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
   volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
 }
 

+ 6 - 0
base/salt_master/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/splunk_servers/cluster_master/main.tf

@@ -137,7 +137,7 @@ resource "aws_instance" "instance" {
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
   tags = merge( var.standard_tags, var.tags, { Name = local.instance_name })
-  volume_tags = merge( var.standard_tags, var.tags, { Name = local.instance_name })
+  volume_tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = local.instance_name })
 }
 
 module "private_dns_record" {

+ 6 - 0
base/splunk_servers/cluster_master/vars.tf

@@ -35,6 +35,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 3 - 3
base/splunk_servers/indexer_cluster/asg.tf

@@ -14,7 +14,7 @@ module "indexer0" {
   max_size                   = var.splunk_asg_sizes[0]
   iam_instance_profile       = aws_iam_instance_profile.indexer_instance_profile.name
   common_services_account    = var.common_services_account
-  tags = merge(var.standard_tags, var.tags, { Name = "${local.asg_name}-0" } )
+  tags = merge(var.standard_tags, var.tags, var.instance_tags[0], { Name = "${local.asg_name}-0" } )
 }
 
 module "indexer1" {
@@ -33,7 +33,7 @@ module "indexer1" {
   max_size                   = var.splunk_asg_sizes[1]
   iam_instance_profile       = aws_iam_instance_profile.indexer_instance_profile.name
   common_services_account    = var.common_services_account
-  tags = merge(var.standard_tags, var.tags, { Name = "${local.asg_name}-1" } )
+  tags = merge(var.standard_tags, var.tags, var.instance_tags[1], { Name = "${local.asg_name}-1" } )
 }
 
 module "indexer2" {
@@ -52,5 +52,5 @@ module "indexer2" {
   max_size                   = var.splunk_asg_sizes[2]
   iam_instance_profile       = aws_iam_instance_profile.indexer_instance_profile.name
   common_services_account    = var.common_services_account
-  tags = merge(var.standard_tags, var.tags, { Name = "${local.asg_name}-2" } )
+  tags = merge(var.standard_tags, var.tags, var.instance_tags[2], { Name = "${local.asg_name}-2" } )
 }

+ 6 - 0
base/splunk_servers/indexer_cluster/vars.tf

@@ -63,6 +63,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags only for the ASG instances. For the indexer clusters, this is an array with different tags for each of the 3 ASGs."
+  type = list(map(string))
+  default = [ {}, {}, {} ]
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/splunk_servers/searchhead/main.tf

@@ -139,7 +139,7 @@ resource "aws_instance" "instance" {
   }
 
   user_data = data.template_cloudinit_config.cloud-init.rendered
-  tags = merge( var.standard_tags, var.tags, { Name = local.instance_name })
+  tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = local.instance_name })
   volume_tags = merge( var.standard_tags, var.tags, { Name = local.instance_name })
 
   depends_on = [ aws_iam_instance_profile.moose_splunk_sh_instance_profile ]

+ 6 - 0
base/splunk_servers/searchhead/vars.tf

@@ -47,6 +47,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 1 - 1
base/teleport-single-instance/main.tf

@@ -135,7 +135,7 @@ resource "aws_instance" "instance" {
 
   user_data = data.template_cloudinit_config.cloud_init_config.rendered
   tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
-  volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
+  volume_tags = merge( var.standard_tags, var.tags, var.instance_tags, { Name = var.instance_name })
 }
 
 module "private_dns_record" {

+ 6 - 0
base/teleport-single-instance/vars.tf

@@ -21,6 +21,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "Tags for the instance only."
+  type = map(string)
+  default = { }
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"

+ 4 - 1
base/vault/main.tf

@@ -36,6 +36,9 @@ resource "aws_network_interface" "instance" {
 # }
 
 resource "aws_instance" "instance" {
+  # TODO: Make instance count numeric. While Instance count is currently a list of strings so
+  # that the names are nicely 1, 2, and 3, but this could also have been solved with a '+1'. A count
+  # seems like it would be cleaner.
   for_each = toset(var.instance_count)
   #availability_zone = var.azs[count.index % 2]
   tenancy = "default"
@@ -140,7 +143,7 @@ resource "aws_instance" "instance" {
   #TODO switch to dynamic tag
   user_data = data.template_cloudinit_config.cloud_init_config[each.key].rendered
   tags = merge( var.standard_tags, var.tags, { "Name": length(var.instance_count) > 1 ? "${var.instance_name}-${each.value}" : var.instance_name })
-  volume_tags = merge( var.standard_tags, var.tags, { "Name": length(var.instance_count) > 1 ? "${var.instance_name}-${each.value}" : var.instance_name })
+  volume_tags = merge( var.standard_tags, var.tags, var.instance_tags[tonumber(each.key)-1], { "Name": length(var.instance_count) > 1 ? "${var.instance_name}-${each.value}" : var.instance_name })
 }
 
 module "private_dns_record" {

+ 7 - 0
base/vault/vars.tf

@@ -4,6 +4,7 @@ variable "instance_name" {
 }
 
 variable "instance_count" {
+  # This is an unusual way to do this. TODO.
   description = "Number of servers"
   type = list(string)
   default = ["1","2","3"]
@@ -27,6 +28,12 @@ variable "tags" {
   default     = { }
 }
 
+variable "instance_tags" {
+  description = "List of tags for the instances only."
+  type = list(map(string))
+  default = [{ }, { }, { }]
+}
+
 variable "instance_type" { 
   type = string
   default = "t3a.micro"