Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #176 from kinvolk/alban/tags
Browse files Browse the repository at this point in the history
aws: add tags on AWS resources
  • Loading branch information
alban authored Feb 13, 2020
2 parents e7b9e2b + 6ab8240 commit e872a5d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions aws/flatcar-linux/kubernetes/controllers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ resource "aws_route53_record" "etcds" {
resource "aws_instance" "controllers" {
count = var.controller_count

tags = {
tags = merge(var.tags, {
Name = "${var.cluster_name}-controller-${count.index}"
}
})

instance_type = var.controller_type

Expand Down
16 changes: 8 additions & 8 deletions aws/flatcar-linux/kubernetes/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ resource "aws_vpc" "network" {
enable_dns_support = true
enable_dns_hostnames = true

tags = {
tags = merge(var.tags, {
"Name" = var.cluster_name
}
})
}

resource "aws_internet_gateway" "gateway" {
vpc_id = aws_vpc.network.id

tags = {
tags = merge(var.tags, {
"Name" = var.cluster_name
}
})
}

resource "aws_route_table" "default" {
Expand All @@ -35,9 +35,9 @@ resource "aws_route_table" "default" {
gateway_id = aws_internet_gateway.gateway.id
}

tags = {
tags = merge(var.tags, {
"Name" = var.cluster_name
}
})
}

# Subnets (one per availability zone)
Expand All @@ -53,9 +53,9 @@ resource "aws_subnet" "public" {
map_public_ip_on_launch = true
assign_ipv6_address_on_creation = true

tags = {
tags = merge(var.tags, {
"Name" = "${var.cluster_name}-public-${count.index}"
}
})
}

resource "aws_route_table_association" "public" {
Expand Down
8 changes: 4 additions & 4 deletions aws/flatcar-linux/kubernetes/security.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ resource "aws_security_group" "controller" {

vpc_id = aws_vpc.network.id

tags = {
tags = merge(var.tags, {
"Name" = "${var.cluster_name}-controller"
}
})
}

resource "aws_security_group_rule" "controller-ssh" {
Expand Down Expand Up @@ -189,9 +189,9 @@ resource "aws_security_group" "worker" {

vpc_id = aws_vpc.network.id

tags = {
tags = merge(var.tags, {
"Name" = "${var.cluster_name}-worker"
}
})
}

resource "aws_security_group_rule" "worker-ssh" {
Expand Down
9 changes: 9 additions & 0 deletions aws/flatcar-linux/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ variable "worker_clc_snippets" {
default = []
}

variable "tags" {
type = map
default = {
"ManagedBy" = "Lokomotive"
"CreatedBy" = "Unspecified"
}
description = "Optional details to tag on AWS resources"
}

# configuration

variable "ssh_keys" {
Expand Down
1 change: 1 addition & 0 deletions aws/flatcar-linux/kubernetes/workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module "workers" {
disk_size = var.disk_size
spot_price = var.worker_price
target_groups = var.worker_target_groups
tags = var.tags

# configuration
kubeconfig = module.bootkube.kubeconfig-kubelet
Expand Down
9 changes: 9 additions & 0 deletions aws/flatcar-linux/kubernetes/workers/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ variable "clc_snippets" {
default = []
}

variable "tags" {
type = map
default = {
"ManagedBy" = "Lokomotive"
"CreatedBy" = "Unspecified"
}
description = "Optional details to tag on AWS resources"
}

# configuration

variable "kubeconfig" {
Expand Down
24 changes: 17 additions & 7 deletions aws/flatcar-linux/kubernetes/workers/workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ resource "aws_autoscaling_group" "workers" {
# used. Disable wait to avoid issues and align with other clouds.
wait_for_capacity_timeout = "0"

tags = [
{
key = "Name"
value = "${var.name}-worker"
propagate_at_launch = true
},
]
tags = flatten([
[
{
key = "Name"
value = "${var.name}-worker"
propagate_at_launch = true
},
],
[
for tag in keys(var.tags):
{
key = tag == "Name" ? "X-Name" : tag
value = var.tags[tag]
propagate_at_launch = true
}
],
])
}

# Worker template
Expand Down
1 change: 1 addition & 0 deletions docs/flatcar-linux/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Reference the DNS zone id with `"${aws_route53_zone.zone-for-clusters.zone_id}"`
| service_cidr | CIDR IPv4 range to assign to Kubernetes services | "10.3.0.0/16" | "10.3.0.0/24" |
| cluster_domain_suffix | FQDN suffix for Kubernetes services answered by coredns. | "cluster.local" | "k8s.example.com" |
| certs_validity_period_hours | Validity of all the certificates in hours | 8760 | 17520 |
| tags | Optional details to tag on AWS resources | `{}` | `{"CreatedBy" = "Devops team"}` |

Check the list of valid [instance types](https://aws.amazon.com/ec2/instance-types/).

Expand Down

0 comments on commit e872a5d

Please sign in to comment.