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

Provide volume type and size nodes #12

Open
wants to merge 2 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
63 changes: 63 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
data "aws_iam_policy_document" "assume_role_ec2" {
statement {
actions = ["sts:AssumeRole"]

principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
effect = "Allow"
}
}

#############################
### IAM Agent
#############################

resource "aws_iam_instance_profile" "agent_instance_profile" {
name = format("%sAgentInstanceProfile", title(var.name))
role = aws_iam_role.agent_role.name
}

resource "aws_iam_role" "agent_role" {
name = format("%sAgentRole", title(var.name))
assume_role_policy = data.aws_iam_policy_document.assume_role_ec2.json
}

resource "aws_iam_role_policy_attachment" "agent_cloudwatch_server_policy" {
count = var.enable_ssm == true ? 1 : 0
role = aws_iam_role.agent_role.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}

resource "aws_iam_role_policy_attachment" "agent_ssm_instance_core_policy" {
count = var.enable_ssm == true ? 1 : 0
role = aws_iam_role.agent_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}


#############################
### IAM Server
#############################
resource "aws_iam_instance_profile" "server_instance_profile" {
name = format("%sServerInstanceProfile", title(var.name))
role = aws_iam_role.server_role.name
}

resource "aws_iam_role" "server_role" {
name = format("%sServerRole", title(var.name))
assume_role_policy = data.aws_iam_policy_document.assume_role_ec2.json
}

resource "aws_iam_role_policy_attachment" "server_cloudwatch_server_policy" {
count = var.enable_ssm == "true" ? 1 : 0
role = aws_iam_role.server_role.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}

resource "aws_iam_role_policy_attachment" "server_ssm_instance_core_policy" {
count = var.enable_ssm == "true" ? 1 : 0
role = aws_iam_role.server_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
11 changes: 10 additions & 1 deletion infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ resource "aws_launch_template" "k3s_server" {
}
}

iam_instance_profile {
arn = aws_iam_instance_profile.server_instance_profile.arn
}

network_interfaces {
delete_on_termination = true
security_groups = concat([aws_security_group.self.id, aws_security_group.database.id], var.extra_server_security_groups)
Expand Down Expand Up @@ -138,10 +142,15 @@ resource "aws_launch_template" "k3s_agent" {
ebs {
encrypted = true
volume_type = local.agent_volume_type
volume_size = "50"
volume_size = local.agent_volume_size
iops = var.agent_volume_iops
}
}

iam_instance_profile {
arn = aws_iam_instance_profile.agent_instance_profile.arn
}

network_interfaces {
delete_on_termination = true
security_groups = concat([aws_security_group.ingress.id, aws_security_group.self.id], var.extra_agent_security_groups)
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ locals {
server_volume_type = var.server_volume_type
agent_instance_type = var.agent_instance_type
agent_volume_type = var.agent_volume_type
agent_volume_size = var.agent_volume_size
agent_image_id = var.agent_image_id != null ? var.agent_image_id : data.aws_ami.ubuntu.id
server_image_id = var.server_image_id != null ? var.server_image_id : data.aws_ami.ubuntu.id
aws_azs = var.aws_azs
Expand Down
8 changes: 8 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ output "k3s_cluster_secret" {
value = local.k3s_cluster_secret
sensitive = true
}

output "agent_role_arn" {
value = aws_iam_role.agent_role.arn
}

output "server_role_arn" {
value = aws_iam_role.server_role.arn
}
17 changes: 17 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ variable "agent_volume_type" {
type = string
}

variable "agent_volume_size" {
default = 50
description = "Volume Size for K3S Agent nodes"
type = number
}

variable "agent_volume_iops" {
default = null
description = "Volume IOPS for K3S Agent nodes"
type = number
}

variable "rancher_features" {
default = ""
description = "Comma-separated list of feature flags to enable in Rancher"
Expand All @@ -340,4 +352,9 @@ variable "nginx_version" {
default = "4.1.3"
description = "Version of ingress-nginx helm chart to install"
type = string
}

variable "enable_ssm" {
default = false
type = bool
}