From 6ad9c559b4e3e3473cbfa2a88444fa288f2e0b4d Mon Sep 17 00:00:00 2001 From: Sergei Ugdyzhekov Date: Sat, 18 Jul 2020 21:26:05 +0200 Subject: [PATCH] feat: Tags refactoring --- launch_template.tf | 20 ++++++-------------- routes.tf | 5 +---- s3_endpoint.tf | 1 + security_group.tf | 1 + variables.tf | 9 +++++++++ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/launch_template.tf b/launch_template.tf index 9d9a59f..4aedb95 100644 --- a/launch_template.tf +++ b/launch_template.tf @@ -2,25 +2,20 @@ resource "aws_network_interface" "nat" { subnet_id = local.public_subnet_ids[0] source_dest_check = false security_groups = [aws_security_group.nat.id] - - tags = { - Name = local.name - } + tags = local.tags } resource "aws_eip" "public_ip" { - vpc = true - network_interface = aws_network_interface.nat.id - - tags = { - Name = local.name - } + vpc = true + network_interface = aws_network_interface.nat.id + tags = local.tags } resource "aws_launch_template" "nat_instance" { name_prefix = local.name image_id = data.aws_ami.nat.id instance_type = local.instance_type + tags = local.tags network_interfaces { device_index = 0 @@ -29,9 +24,6 @@ resource "aws_launch_template" "nat_instance" { tag_specifications { resource_type = "instance" - - tags = { - Name = local.name - } + tags = local.tags } } diff --git a/routes.tf b/routes.tf index 6f99e4f..3b0de90 100644 --- a/routes.tf +++ b/routes.tf @@ -1,9 +1,6 @@ resource "aws_route_table" "nat" { vpc_id = local.vpc_id - - tags = { - Name = local.name - } + tags = local.tags } resource "aws_route" "internet" { diff --git a/s3_endpoint.tf b/s3_endpoint.tf index bfc7b9e..c60c945 100644 --- a/s3_endpoint.tf +++ b/s3_endpoint.tf @@ -3,4 +3,5 @@ resource "aws_vpc_endpoint" "s3" { service_name = "com.amazonaws.${data.aws_region.current.name}.s3" auto_accept = true route_table_ids = [aws_route_table.nat.id] + tags = local.tags } \ No newline at end of file diff --git a/security_group.tf b/security_group.tf index 73ea67c..29ad48d 100644 --- a/security_group.tf +++ b/security_group.tf @@ -2,6 +2,7 @@ resource "aws_security_group" "nat" { name = "Nat" description = "Default rules for Nat instance" vpc_id = local.vpc_id + tags = local.tags } resource "aws_security_group_rule" "ingess_http" { diff --git a/variables.tf b/variables.tf index b47b34c..1243382 100644 --- a/variables.tf +++ b/variables.tf @@ -1,6 +1,10 @@ variable "name" { default = "NatInstance" } +variable "tags" { + description = "Tags." + type = map(string) +} variable "public_subnet_id" {} variable "instance_type" { default = "t3a.small" @@ -32,4 +36,9 @@ locals { public_subnet_ids = [var.public_subnet_id] private_subnet_cidrs = var.private_subnet_cidrs az = "${data.aws_region.current.name}b" + tags = merge({ + Name = local.name + Module = "Nat Instance" + ModuleSource = "https://github.com/jetbrains-infra/terraform-aws-nat-instance/" + }, var.tags) } \ No newline at end of file