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

Fixed subnets list type error #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ resource "aws_lb" "alb" {
internal = false
load_balancer_type = "application"
security_groups = ["${aws_security_group.alb-security-group.id}", "${module.eks.worker_security_group_id}"]
subnets = "${var.public_subnets}"
subnets = ["${var.public_subnets}",]

enable_deletion_protection = false

Expand Down
8 changes: 8 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ provider "aws" {
region = "us-east-1"
}

# provider for S3 bucket. when the bucket is stored in other region
provider "aws" {
region = "eu-central-1"
alias = "tfstate"
}

module "core" {
source = "github.com/lean-delivery/tf-module-aws-core?ref=v0.2"

Expand All @@ -21,6 +27,8 @@ module "eks_test" {
project = "eks"
environment = "test"

s3_bucket_name = "aws-eks-s3-bucket"

cluster_version = "1.14"
cluster_enabled_log_types = ["api"]

Expand Down
105 changes: 58 additions & 47 deletions kubectl.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ EOS
}
}


##### Template, save to S3 and deploy ingress_controller #####
data "template_file" "ingress_controller_service" {
template = "${file("${path.module}/manifests_templates/nginx-ingress-service.tpl")}"

Expand All @@ -69,29 +71,34 @@ data "template_file" "ingress_controller_service" {
}
}

resource "local_file" "ingress_controller_service" {
resource "aws_s3_bucket_object" "ingress_controller_service" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/3-nginx-ingress-service.yaml"
content = "${data.template_file.ingress_controller_service.rendered}"
filename = "${path.module}/manifests/nginx-ingress/3-nginx-ingress-service.yaml"
}

resource "null_resource" "deploy_ingress_controller" {
count = "${ var.deploy_ingress_controller ? 1 : 0 }"
depends_on = ["null_resource.check_api", "local_file.ingress_controller_service"]

depends_on = ["null_resource.check_api", "aws_s3_bucket_object.ingress_controller_service"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
kubectl apply -f manifests/nginx-ingress/1-namespace.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5; \
kubectl apply -f manifests/nginx-ingress/2-nginx-ingress-rbac-deployment.yaml -f manifests/nginx-ingress/3-nginx-ingress-service.yaml -f manifests/nginx-ingress/4-default-http-backend.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f manifests/nginx-ingress/2-nginx-ingress-rbac-deployment.yaml -f ${data.template_file.ingress_controller_service.rendered} -f manifests/nginx-ingress/4-default-http-backend.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5;
EOS

interpreter = ["${var.local_exec_interpreter}"]
}
}


##### Template, save to S3 and deploy external-dns #####
data "template_file" "external_dns_manifest" {
template = "${file("${path.module}/manifests_templates/external-dns.tpl")}"

Expand All @@ -101,28 +108,30 @@ data "template_file" "external_dns_manifest" {
environment = "${var.environment}"
}
}

resource "local_file" "external_dns_manifest" {
content = "${data.template_file.external_dns_manifest.rendered}"
filename = "${path.module}/manifests/external_dns.yaml"
resource "aws_s3_bucket_object" "external_dns_manifest" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/external_dns.yaml"
content = "${data.template_file.ingress_controller_service.rendered}"
}

resource "null_resource" "deploy_external_dns" {
count = "${ var.deploy_external_dns ? 1 : 0 }"
depends_on = ["null_resource.check_api", "local_file.external_dns_manifest"]
depends_on = ["null_resource.check_api", "aws_s3_bucket_object.external_dns_manifest"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
kubectl apply -f manifests/external_dns.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f ${data.template_file.external_dns_manifest.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5;
EOS

interpreter = ["${var.local_exec_interpreter}"]
}
}

##### Template, save to S3 and deploy cluster autoscaler #####
data "template_file" "cluster_autoscaler_config" {
template = "${file("${path.module}/manifests_templates/cluster-autoscaler/kubernetes-autoscaler.tpl")}"

Expand All @@ -132,9 +141,11 @@ data "template_file" "cluster_autoscaler_config" {
}
}

resource "local_file" "cluster_autoscaler_config" {
resource "aws_s3_bucket_object" "cluster_autoscaler_config" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/cluster-autoscaler/kubernetes-autoscaler.yaml"
content = "${data.template_file.cluster_autoscaler_config.rendered}"
filename = "${path.module}/manifests/cluster-autoscaler/kubernetes-autoscaler.yaml"
}

data "template_file" "cluster_autoscaler_priority_configmap" {
Expand All @@ -146,21 +157,23 @@ data "template_file" "cluster_autoscaler_priority_configmap" {
}
}

resource "local_file" "cluster_autoscaler_priority_configmap" {
resource "aws_s3_bucket_object" "cluster_autoscaler_priority_configmap" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/cluster-autoscaler/autoscaler-priority.yaml"
content = "${data.template_file.cluster_autoscaler_priority_configmap.rendered}"
filename = "${path.module}/manifests/cluster-autoscaler/autoscaler-priority.yaml"
}

resource "null_resource" "deploy_cluster_autoscaler" {
depends_on = ["local_file.cluster_autoscaler_config", "null_resource.priority_class", "local_file.cluster_autoscaler_priority_configmap"]
depends_on = ["aws_s3_bucket_object.cluster_autoscaler_config", "null_resource.priority_class", "aws_s3_bucket_object.cluster_autoscaler_priority_configmap"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
kubectl apply -f manifests/cluster-autoscaler/autoscaler-priority.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f ${data.template_file.cluster_autoscaler_priority_configmap.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5; \
kubectl apply -f manifests/cluster-autoscaler/kubernetes-autoscaler.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f ${data.template_file.cluster_autoscaler_config.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5;
EOS

Expand Down Expand Up @@ -198,6 +211,7 @@ EOS
}
}

##### Template, save to S3 and deploy logging, monitoring, etc... #####
data "template_file" "fluentd_config" {
template = "${file("${path.module}/manifests_templates/fluentd_values.tpl")}"

Expand All @@ -209,20 +223,22 @@ data "template_file" "fluentd_config" {
}
}

resource "local_file" "fluentd_config" {
resource "aws_s3_bucket_object" "fluentd_config" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/logs_fluend_cloudwatch/values.yaml"
content = "${data.template_file.fluentd_config.rendered}"
filename = "${path.module}/manifests/logs_fluend_cloudwatch/values.yaml"
}

resource "null_resource" "deploy_fluentd" {
count = "${ var.enable_container_logs ? 1 : 0 }"
depends_on = ["null_resource.install_tiller", "local_file.fluentd_config"]
depends_on = ["null_resource.install_tiller", "aws_s3_bucket_object.fluentd_config"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
helm install --namespace logs --name fluentd ${path.module}/manifests/logs_fluend_cloudwatch/ --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
helm install --namespace logs --name fluentd ${path.module}/manifests/logs_fluend_cloudwatch/ --values ${data.template_file.fluentd_config.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 15;
EOS

Expand Down Expand Up @@ -266,60 +282,55 @@ data "template_file" "grafana_values" {
}
}

resource "local_file" "storage_class" {
resource "aws_s3_bucket_object" "storage_class" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/monitoring/storageClass.yaml"
content = "${data.template_file.storage_class.rendered}"
filename = "${path.module}/manifests/monitoring/storageClass.yaml"
}

resource "local_file" "grafana_pvc" {
resource "aws_s3_bucket_object" "grafana_pvc" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/monitoring/grafana_pvc.yaml"
content = "${data.template_file.grafana_pvc.rendered}"
filename = "${path.module}/manifests/monitoring/grafana_pvc.yaml"
}

resource "local_file" "prometheus_operator_config" {
resource "aws_s3_bucket_object" "prometheus_operator_config" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/monitoring/prometheus-operator-helm/values.yaml"
content = "${data.template_file.prometheus_operator_values.rendered}"
filename = "${path.module}/manifests/monitoring/prometheus-operator-helm/values.yaml"
}

resource "local_file" "grafana_config" {
resource "aws_s3_bucket_object" "grafana_config" {
provider = "aws.tfstate"
bucket = "${var.s3_bucket_name}"
key = "${var.project}/${var.environment}/manifests/monitoring/grafana-helm/values.yaml"
content = "${data.template_file.grafana_values.rendered}"
filename = "${path.module}/manifests/monitoring/grafana-helm/values.yaml"
}

resource "null_resource" "deploy_monitoring" {
count = "${ var.enable_monitoring ? 1 : 0 }"
depends_on = ["null_resource.install_tiller", "local_file.grafana_config", "local_file.prometheus_operator_config", "local_file.grafana_pvc", "local_file.storage_class"]
depends_on = ["null_resource.install_tiller", "aws_s3_bucket_object.grafana_config", "aws_s3_bucket_object.prometheus_operator_config", "aws_s3_bucket_object.grafana_pvc", "aws_s3_bucket_object.storage_class"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
kubectl apply -f manifests/monitoring/storageClass.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f ${data.template_file.storage_class.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5; \
helm install --namespace monitoring --name prometheus-operator manifests/monitoring/prometheus-operator-helm/ --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
helm install --namespace monitoring --name prometheus-operator manifests/monitoring/prometheus-operator-helm/ --values ${data.template_file.prometheus_operator_values.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5; \
helm install --namespace kube-system --name termination-handler-exporter manifests/spot-termination-exporter/ --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5;
kubectl apply -f manifests/monitoring/grafana_pvc.yaml --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
kubectl apply -f ${data.template_file.grafana_pvc.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5; \
helm install --namespace monitoring --name grafana manifests/monitoring/grafana-helm/ --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
helm install --namespace monitoring --name grafana manifests/monitoring/grafana-helm/ --values ${data.template_file.grafana_values.rendered} --kubeconfig ${path.cwd}/${module.eks.kubeconfig_filename}; \
sleep 5;
EOS

interpreter = ["${var.local_exec_interpreter}"]
}
}

resource "null_resource" "copy_manifests" {
depends_on = ["null_resource.deploy_cluster_autoscaler", "local_file.grafana_config", "local_file.prometheus_operator_config", "local_file.grafana_pvc", "local_file.storage_class", "local_file.fluentd_config", "local_file.external_dns_manifest", "local_file.ingress_controller_service"]

provisioner "local-exec" {
working_dir = "${path.module}"

command = <<EOS
cp -r ${path.module}/manifests ${path.root}/manifests_rendered
EOS

interpreter = ["${var.local_exec_interpreter}"]
}
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ variable "environment" {
type = "string"
}

variable "s3_bucket_name" {
description = "Name of the bucket to store kubernetes manifests"
type = "string"
}

variable "root_domain" {
description = "Root domain in which custom DNS record for ALB would be created"
}
Expand Down