Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common tagging of aws resources #7

Merged
merged 5 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,44 @@ resource "aws_key_pair" "ssh" {
}

module "kubernetes" {
source = "github.com/Jnig/terraform-kubernetes-aws?ref=v0.6"
name = "devops-dev-cluster"
source = "github.com/Jnig/terraform-kubernetes-aws?ref=v0.6"
name = "devops-dev-cluster"

ssh_key = "${aws_key_pair.ssh.key_name}"
ssh_key = "${aws_key_pair.ssh.key_name}"

master_instance_type = "t2.medium"
master_instance_type = "t2.medium"

node_instance_type = "t2.large"
node_asg_min = 1
node_asg_max = 2
node_asg_desired = 2
node_instance_type = "t2.large"
node_asg_min = 1
node_asg_max = 2
node_asg_desired = 2

#aws ec2 describe-vpcs
vpc = "<vpc>"
#aws ec2 describe-vpcs
vpc = "<vpc>"

# aws ec2 describe-subnets --filters Name=vpc-id,Values=<vpc>
# tag all subnets with the name of the cluster: kubernetes.io/cluster/<name>
subnets = ["subnet1", "subnet2", "subnet3"]
# aws ec2 describe-subnets --filters Name=vpc-id,Values=<vpc>
# tag all subnets with the name of the cluster: kubernetes.io/cluster/<name>
subnets = ["subnet1", "subnet2", "subnet3"]

proxy_servers = "<proxy with port>"
# optional add addtional certificates to the nodes
# useful if you have private docker repositories
additional_certificates = <<EOF
proxy_servers = "<proxy with port>"

# optional add additional certificates to the nodes
# useful if you have private docker repositories
additional_certificates = <<EOF
-----BEGIN CERTIFICATE-----
....
....
-----END CERTIFICATE-----
EOF



# optional add common tags, e.g. for corporate billing
additional_tags = {
Application = ""
Billing_ID = ""
Owner = ""
}
}
```

Known limitations
------------
* backups are missing

43 changes: 13 additions & 30 deletions autoscaling_master.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ resource "aws_ebs_volume" "master" {
size = 40
encrypted = true
type = "gp2"
tags {
Name = "${var.name}-master"
}
tags = "${merge(var.additional_tags, map("Name", "${var.name}-master"))}"
}

resource "aws_security_group" "master" {
Expand All @@ -48,9 +46,6 @@ resource "aws_security_group" "master" {
cidr_blocks = ["0.0.0.0/0"]
}




ingress {
from_port = 0
to_port = 0
Expand All @@ -72,7 +67,10 @@ resource "aws_security_group" "master" {
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = "${var.additional_tags}"
}

resource "aws_launch_configuration" "master" {
name_prefix = "${var.name}-master-"
image_id = "${data.aws_ami.ubuntu.id}"
Expand Down Expand Up @@ -105,43 +103,28 @@ resource "aws_autoscaling_group" "master" {

target_group_arns = ["${aws_lb_target_group.master_443.arn}"]

tags = [
{
key = "Name"
value = "${var.name}-master"
propagate_at_launch = true
},
{
key = "KubernetesCluster"
value = "${var.name}"
propagate_at_launch = true
},
{
key = "k8s.io/role/master"
value = 1
propagate_at_launch = true
},
]
tags = ["${concat(
list(map("key", "Name", "value", "${var.name}-master", "propagate_at_launch", true),
map("key", "KubernetesCluster", "value", "${var.name}", "propagate_at_launch", true),
map("key", "k8s.io/role/master", "value", 1, "propagate_at_launch", true),
),
local.tags_asg_format
)}"]

lifecycle {
create_before_destroy = true
}
}


resource "aws_lb" "master" {
name = "${var.name}-master"
internal = true
subnets = ["${data.aws_subnet.region_1a.id}"]
load_balancer_type = "network"

tags = {
Name = "${var.name}-master"
}


tags = "${merge(var.additional_tags, map("Name", "${var.name}-master"))}"
}


resource "aws_lb_listener" "master" {
load_balancer_arn = "${aws_lb.master.arn}"
port = "443"
Expand Down
29 changes: 9 additions & 20 deletions autoscaling_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ data "template_file" "nodes" {

load_balancer_dns = "${aws_lb.master.dns_name}"
}

}


resource "aws_security_group" "nodes" {
name = "${var.name}-nodes"
description = "${var.name}-nodes"
vpc_id = "${var.vpc}"

tags = "${var.additional_tags}"
}

resource "aws_security_group_rule" "nodes-self" {
Expand Down Expand Up @@ -101,23 +99,14 @@ resource "aws_autoscaling_group" "nodes" {
launch_configuration = "${aws_launch_configuration.nodes.name}"
vpc_zone_identifier = ["${data.aws_subnet.region_1b.id}", "${data.aws_subnet.region_1c.id}"]

tags = [
{
key = "Name"
value = "${var.name}-node"
propagate_at_launch = true
},
{
key = "KubernetesCluster"
value = "${var.name}"
propagate_at_launch = true
},
{
key = "k8s.io/role/node"
value = 1
propagate_at_launch = true
},
]
tags = ["${concat(
list(map("key", "Name", "value", "${var.name}-node", "propagate_at_launch", true),
map("key", "KubernetesCluster", "value", "${var.name}", "propagate_at_launch", true),
map("key", "k8s.io/role/node", "value", 1, "propagate_at_launch", true),
),
local.tags_asg_format
)}"]


lifecycle {
create_before_destroy = true
Expand Down
2 changes: 2 additions & 0 deletions certificate.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ resource "aws_s3_bucket_object" "certificate" {
key = "scripts/installation/additional.crt"
content = "${var.additional_certificates}"
server_side_encryption = "AES256"

tags = "${var.additional_tags}"
}
27 changes: 13 additions & 14 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ resource "aws_iam_role" "cluster" {

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}

resource "aws_iam_instance_profile" "cluster" {
name = "${var.name}"
name = "${var.name}"
role = "${aws_iam_role.cluster.name}"
}

Expand All @@ -39,11 +39,10 @@ resource "aws_iam_role_policy" "policy" {
policy = "${data.template_file.role_policy.rendered}"
}


resource "aws_iam_role_policy" "additional" {
count = "${var.iam_policy == "" ? 0 : 1}"
name = "additional"
role = "${aws_iam_role.cluster.id}"

policy = "${var.iam_policy}"
policy = "${var.iam_policy}"
}
18 changes: 11 additions & 7 deletions input.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ variable "name" {}
variable "ssh_key" {}

variable "master_instance_type" {
default = "t2.medium"
}
default = "t2.medium"
}

variable "node_instance_type" {
default = "t2.large"
default = "t2.large"
}

variable "node_asg_min" {}
Expand All @@ -15,11 +15,11 @@ variable "node_asg_desired" {}
variable "vpc" {}

variable "proxy_servers" {
default = ""
default = ""
}

variable "subnets" {
default = []
default = []
}

variable "kubernetes_version" {
Expand All @@ -31,9 +31,13 @@ variable "kubernetes_dashboard_version" {
}

variable "iam_policy" {
default = ""
default = ""
}

variable "additional_certificates" {
default = ""
default = ""
}

variable "additional_tags" {
default = {}
}
Loading