Created
August 30, 2019 06:28
-
-
Save yum-dev/8ab83be6713bf2f02a502364c76db75f to your computer and use it in GitHub Desktop.
Create EKS cluster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same we can do for clusterName by passing variable from outside