Skip to content

Instantly share code, notes, and snippets.

@yum-dev
Created August 30, 2019 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yum-dev/8ab83be6713bf2f02a502364c76db75f to your computer and use it in GitHub Desktop.
Save yum-dev/8ab83be6713bf2f02a502364c76db75f to your computer and use it in GitHub Desktop.
Create EKS cluster.
terraform {
required_version = ">= 0.12"
}
resource "aws_vpc" "eks-demo" {
cidr_block = "172.17.0.0/16"
tags = {
Name = "eks-demo"
}
}
# Fetch AZs in the current region
data "aws_availability_zones" "available" {
}
resource "aws_subnet" "private" {
count = 3
cidr_block = cidrsubnet(aws_vpc.eks-demo.cidr_block, 8, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
vpc_id = aws_vpc.eks-demo.id
tags = {
Name = "eks-demo"
}
}
data "aws_subnet_ids" "example" {
vpc_id = "${aws_vpc.eks-demo.id}"
}
data "aws_subnet" "example" {
count = 3
id = "${element(data.aws_subnet_ids.example.ids[count.index])}"
}
output "subnet_cidr_blocks" {
value = ["${data.aws_subnet.example.*.cidr_block}"]
}
# data "aws_subnet_ids" "example" {
# vpc_id = "${var.vpc_id}"
# }
#
# data "aws_subnet" "example" {
# count = "${length(data.aws_subnet_ids.example.ids)}"
# id = "${data.aws_subnet_ids.example.ids[count.index]}"
# }
#
# output "subnet_cidr_blocks" {
# value = ["${data.aws_subnet.example.*.cidr_block}"]
# }
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "5.1.0"
# insert the 3 required variables here
cluster_name = "eks-demo"
subnets = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
vpc_id = "${aws_vpc.eks-demo.id}"
}
@iot123
Copy link

iot123 commented Aug 30, 2019

For changing that count to any number, we can pass variable over there as var.count, and that variable value will come at time of
Terraform apply -var count=4 or any value

@iot123
Copy link

iot123 commented Aug 30, 2019

Same we can do for clusterName by passing variable from outside

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment