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

fix tf code to match default subnets #1

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
18 changes: 3 additions & 15 deletions eks/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
#
###############################################################

# Get the default VPC details
data "aws_vpc" "default_vpc" {
default = true
}

# Get Public IP of your broadband account. This allows us to lock down SSH access
# into the environment from anyone other than yourself, by inserting your public
# IP to a security group ingress rule.
# Try this URL in your browser!
data "http" "cloudshell_ip" {
url = "https://checkip.amazonaws.com/"
}

# Get the subnets to use for the cluster ti bind to and the autoscaling group
# to place nodes in.
# Get the subnets to use for the cluster and autoscaling group
data "aws_subnets" "public" {
filter {
name = "vpc-id"
Expand All @@ -27,14 +17,12 @@ data "aws_subnets" "public" {
filter {
name = "availability-zone"
values = [
"${var.aws_region}a",
"${var.aws_region}b",
"${var.aws_region}c"
"${var.aws_region}c",
"${var.aws_region}d"
Comment on lines -30 to +21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the case. In the labs I get 6 subnets (a-f)

]
}
}

# Get AMI ID for latest recommended Amazon Linux 2 image
data "aws_ssm_parameter" "node_ami" {
name = "/aws/service/eks/optimized-ami/1.29/amazon-linux-2/recommended/image_id"
}
6 changes: 1 addition & 5 deletions eks/eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ resource "aws_iam_role_policy_attachment" "demo_eks_AmazonEKSClusterPolicy" {
}

# Optionally, enable Security Groups for Pods
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html
resource "aws_iam_role_policy_attachment" "demo_eks_AmazonEKSVPCResourceController" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.demo_eks.name
Expand All @@ -41,13 +40,10 @@ resource "aws_eks_cluster" "demo_eks" {
vpc_config {
subnet_ids = [
data.aws_subnets.public.ids[0],
data.aws_subnets.public.ids[1],
data.aws_subnets.public.ids[2]
data.aws_subnets.public.ids[1]
]
}

# Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
# Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
depends_on = [
aws_iam_role_policy_attachment.demo_eks_AmazonEKSClusterPolicy,
aws_iam_role_policy_attachment.demo_eks_AmazonEKSVPCResourceController,
Expand Down
6 changes: 2 additions & 4 deletions eks/nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,11 @@ resource "aws_launch_template" "node_launch_template" {
)
}


# Wait for LT to settle, or CloudFormation may fail
resource "time_sleep" "wait_30_seconds" {
depends_on = [
aws_launch_template.node_launch_template
]
]

create_duration = "30s"
}
Expand All @@ -223,7 +222,7 @@ Resources:
NodeGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: ["${data.aws_subnets.public.ids[0]}","${data.aws_subnets.public.ids[1]}", "${data.aws_subnets.public.ids[2]}"]
VPCZoneIdentifier: ["${data.aws_subnets.public.ids[0]}","${data.aws_subnets.public.ids[1]}"]
MinSize: "${var.node_group_min_size}"
MaxSize: "${var.node_group_max_size}"
DesiredCapacity: "${var.node_group_desired_capacity}"
Expand All @@ -232,7 +231,6 @@ Resources:
LaunchTemplateId: "${aws_launch_template.node_launch_template.id}"
Version: "${aws_launch_template.node_launch_template.latest_version}"
UpdatePolicy:
# Ignore differences in group size properties caused by scheduled actions
AutoScalingScheduledAction:
IgnoreUnmodifiedGroupSizeProperties: true
AutoScalingRollingUpdate:
Expand Down