Skip to content

Commit

Permalink
aws-add-additional-tags-variable (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvix authored Nov 24, 2021
1 parent 55788d7 commit 8ac2e30
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 69 deletions.
5 changes: 1 addition & 4 deletions modules/aws/bastion/bastion-logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ resource "aws_cloudwatch_log_group" "bastion_log_group" {
count = var.forward_logs_enabled ? 1 : 0
name = "${var.cluster_name}_bastion"

tags = {
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = local.common_tags
}

resource "aws_cloudwatch_log_stream" "bastion_logs" {
Expand Down
34 changes: 20 additions & 14 deletions modules/aws/bastion/bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ locals {
# In China there is no tags for s3 buckets
s3_ignition_bastion_key = element(concat(aws_s3_bucket_object.ignition_bastion_with_tags.*.key, aws_s3_bucket_object.ignition_bastion_without_tags.*.key), 0)

common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)
}

Expand All @@ -34,11 +38,12 @@ resource "aws_instance" "bastion" {

user_data = data.ignition_config.s3.rendered

tags = {
Name = "${var.cluster_name}-bastion${count.index}"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-bastion${count.index}"
)
)
}

resource "aws_security_group" "bastion" {
Expand Down Expand Up @@ -86,11 +91,12 @@ resource "aws_security_group" "bastion" {
self = true
}

tags = {
Name = "${var.cluster_name}-bastion"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-bastion"
)
)
}

resource "aws_route53_record" "bastion" {
Expand Down
7 changes: 7 additions & 0 deletions modules/aws/bastion/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ variable "transit_vpc_cidr" {
type = string
}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map
default = {}
}

16 changes: 12 additions & 4 deletions modules/aws/master/master.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
locals {
common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)

common_tags_asg = join("",[for key, value in var.additional_tags : "{\"Key\":\"${key}\",\"Value\":\"${value}\",\"PropagateAtLaunch\": true},"])

customer_vpn_public_subnets = var.customer_vpn_public_subnets != "" ? split(",", var.customer_vpn_public_subnets) : []
customer_vpn_private_subnets = var.customer_vpn_private_subnets != "" ? split(",", var.customer_vpn_private_subnets) : []
# k8s_api prefixed values represent access to public loadbalancer
Expand Down Expand Up @@ -39,6 +46,7 @@ resource "aws_cloudformation_stack" "master_asg" {
"DesiredCapacity": "1",
"MinSize": "1",
"Tags": [
${local.common_tags_asg}
{
"Key": "Name",
"Value": "${var.cluster_name}-master-${count.index}",
Expand Down
7 changes: 7 additions & 0 deletions modules/aws/master/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ variable "vpc_id" {
}

variable "s3_bucket_tags" {}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map(string)
default = {}
}
12 changes: 8 additions & 4 deletions modules/aws/s3/s3.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
locals {
common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)
}

Expand Down
7 changes: 7 additions & 0 deletions modules/aws/s3/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ variable "logs_expiration_days" {
variable "s3_bucket_prefix" {
type = string
}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map
default = {}
}
7 changes: 7 additions & 0 deletions modules/aws/vault/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ variable "worker_subnet_count" {
}

variable "s3_bucket_tags" {}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map
default = {}
}
22 changes: 12 additions & 10 deletions modules/aws/vault/vault-elb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ resource "aws_elb" "vault" {
interval = 5
}

tags = {
Name = "${var.cluster_name}-vault"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-vault"
)
)
}

resource "aws_elb_attachment" "vault" {
Expand Down Expand Up @@ -57,11 +58,12 @@ resource "aws_security_group" "vault_elb" {
cidr_blocks = [var.ipam_network_cidr]
}

tags = {
Name = "${var.cluster_name}-vault-elb"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-vault-elb"
)
)
}

resource "aws_route53_record" "vault-elb" {
Expand Down
56 changes: 32 additions & 24 deletions modules/aws/vault/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ locals {
# In China there is no tags for s3 buckets
s3_ignition_vault_key = element(concat(aws_s3_bucket_object.ignition_vault_with_tags.*.key, aws_s3_bucket_object.ignition_vault_without_tags.*.key), 0)

common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)
}

Expand Down Expand Up @@ -43,23 +47,25 @@ resource "aws_instance" "vault" {

user_data = data.ignition_config.s3.rendered

tags = {
Name = "${var.cluster_name}-vault${count.index}"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-vault${count.index}"
)
)
}

resource "aws_ebs_volume" "vault_etcd" {
availability_zone = element(data.aws_availability_zones.available.names, 0)
size = var.volume_size_etcd
type = var.volume_type

tags = {
Name = "${var.cluster_name}-vault"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-vault"
)
)
}

resource "aws_volume_attachment" "vault_etcd_ebs" {
Expand All @@ -77,11 +83,12 @@ resource "aws_ebs_volume" "vault_logs" {
size = var.volume_size_logs
type = var.volume_type

tags = {
Name = "${var.cluster_name}-vault"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name", "${var.cluster_name}-vault"
),
)
}

resource "aws_volume_attachment" "vault_logs_ebs" {
Expand Down Expand Up @@ -148,11 +155,12 @@ resource "aws_security_group" "vault" {
cidr_blocks = concat(data.aws_subnet.worker_subnets.*.cidr_block,[var.aws_cni_cidr_block])
}

tags = {
Name = "${var.cluster_name}-vault"
"giantswarm.io/cluster" = var.cluster_name
"giantswarm.io/installation" = var.cluster_name
}
tags = merge(
local.common_tags,
map(
"Name" , "${var.cluster_name}-vault"
)
)
}

resource "aws_route53_record" "vault" {
Expand Down
6 changes: 6 additions & 0 deletions modules/aws/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ variable "transit_vpc_cidr" {
type = string
}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map
default = {}
}
13 changes: 8 additions & 5 deletions modules/aws/vpc/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
# * the private nat gateway is in the elb subnet as well (needs to be in a public subnet)

locals {
common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"giantswarm.io/cluster-type", "control-plane",
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)

policy_allow = <<EOF
Expand Down
7 changes: 7 additions & 0 deletions modules/aws/worker-asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ variable "vpc_id" {
}

variable "s3_bucket_tags" {}

### additional tags
variable "additional_tags" {
description = "Additional tags that can be added to all resources"
type = map
default = {}
}
15 changes: 11 additions & 4 deletions modules/aws/worker-asg/worker-asg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ locals {
# In China there is no tags for s3 buckets
s3_ignition_worker_key = element(concat(aws_s3_bucket_object.ignition_worker_with_tags.*.key, aws_s3_bucket_object.ignition_worker_without_tags.*.key), 0)

common_tags = map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
common_tags = merge(
var.additional_tags,
map(
"giantswarm.io/cluster", var.cluster_name,
"giantswarm.io/installation", var.cluster_name,
"kubernetes.io/cluster/${var.cluster_name}", "owned"
)
)
common_tags_asg = join("",[for key, value in var.additional_tags : "{\"Key\":\"${key}\",\"Value\":\"${value}\",\"PropagateAtLaunch\": true},"])


}

resource "aws_cloudformation_stack" "worker_asg" {
Expand All @@ -28,6 +34,7 @@ resource "aws_cloudformation_stack" "worker_asg" {
"MaxSize": "${var.worker_count * 2}",
"MinSize": "${var.worker_count}",
"Tags": [
${local.common_tags_asg}
{
"Key": "Name",
"Value": "${var.cluster_name}-worker",
Expand Down
Loading

0 comments on commit 8ac2e30

Please sign in to comment.