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

feat: Support cloud-config content in pre-bootstrap script #2335

Closed
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 examples/user_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ No providers.
| <a name="module_eks_mng_bottlerocket_custom_template"></a> [eks\_mng\_bottlerocket\_custom\_template](#module\_eks\_mng\_bottlerocket\_custom\_template) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_bottlerocket_no_op"></a> [eks\_mng\_bottlerocket\_no\_op](#module\_eks\_mng\_bottlerocket\_no\_op) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_linux_additional"></a> [eks\_mng\_linux\_additional](#module\_eks\_mng\_linux\_additional) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_linux_cloud_config"></a> [eks\_mng\_linux\_cloud\_config](#module\_eks\_mng\_linux\_cloud\_config) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_linux_custom_ami"></a> [eks\_mng\_linux\_custom\_ami](#module\_eks\_mng\_linux\_custom\_ami) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_linux_custom_template"></a> [eks\_mng\_linux\_custom\_template](#module\_eks\_mng\_linux\_custom\_template) | ../../modules/_user_data | n/a |
| <a name="module_eks_mng_linux_no_op"></a> [eks\_mng\_linux\_no\_op](#module\_eks\_mng\_linux\_no\_op) | ../../modules/_user_data | n/a |
Expand Down
10 changes: 10 additions & 0 deletions examples/user_data/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ module "eks_mng_linux_additional" {
EOT
}

module "eks_mng_linux_cloud_config" {
source = "../../modules/_user_data"

cloud_config_content_type = "text/cloud-config"
pre_bootstrap_user_data = templatefile(
"${path.module}/templates/cloud_config.yaml",
{ var1 = "rocks" }
)
}

module "eks_mng_linux_custom_ami" {
source = "../../modules/_user_data"

Expand Down
6 changes: 6 additions & 0 deletions examples/user_data/templates/cloud_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#cloud-config
cloud_final_modules:
- [scripts-user, always]

runcmd:
- echo "cloud-config ${var1} !"
1 change: 1 addition & 0 deletions modules/_user_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_bootstrap_extra_args"></a> [bootstrap\_extra\_args](#input\_bootstrap\_extra\_args) | Additional arguments passed to the bootstrap script. When `platform` = `bottlerocket`; these are additional [settings](https://github.com/bottlerocket-os/bottlerocket#settings) that are provided to the Bottlerocket user data | `string` | `""` | no |
| <a name="input_cloud_config_content_type"></a> [cloud\_config\_content\_type](#input\_cloud\_config\_content\_type) | Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
| <a name="input_cluster_auth_base64"></a> [cluster\_auth\_base64](#input\_cluster\_auth\_base64) | Base64 encoded CA of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_endpoint"></a> [cluster\_endpoint](#input\_cluster\_endpoint) | Endpoint of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the EKS cluster | `string` | `""` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/_user_data/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data "cloudinit_config" "linux_eks_managed_node_group" {

# Prepend to existing user data supplied by AWS EKS
part {
content_type = "text/x-shellscript"
content_type = var.cloud_config_content_type
content = var.pre_bootstrap_user_data
}
}
6 changes: 6 additions & 0 deletions modules/_user_data/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ variable "cluster_service_ipv4_cidr" {
default = null
}

variable "cloud_config_content_type" {
description = "Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
default = ""
}

variable "pre_bootstrap_user_data" {
description = "User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
Expand Down
1 change: 1 addition & 0 deletions modules/eks-managed-node-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module "eks_managed_node_group" {
| <a name="input_bootstrap_extra_args"></a> [bootstrap\_extra\_args](#input\_bootstrap\_extra\_args) | Additional arguments passed to the bootstrap script. When `platform` = `bottlerocket`; these are additional [settings](https://github.com/bottlerocket-os/bottlerocket#settings) that are provided to the Bottlerocket user data | `string` | `""` | no |
| <a name="input_capacity_reservation_specification"></a> [capacity\_reservation\_specification](#input\_capacity\_reservation\_specification) | Targeting for EC2 capacity reservations | `any` | `{}` | no |
| <a name="input_capacity_type"></a> [capacity\_type](#input\_capacity\_type) | Type of capacity associated with the EKS Node Group. Valid values: `ON_DEMAND`, `SPOT` | `string` | `"ON_DEMAND"` | no |
| <a name="input_cloud_config_content_type"></a> [cloud\_config\_content\_type](#input\_cloud\_config\_content\_type) | Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
| <a name="input_cluster_auth_base64"></a> [cluster\_auth\_base64](#input\_cluster\_auth\_base64) | Base64 encoded CA of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_endpoint"></a> [cluster\_endpoint](#input\_cluster\_endpoint) | Endpoint of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_ip_family"></a> [cluster\_ip\_family](#input\_cluster\_ip\_family) | The IP family used to assign Kubernetes pod and service addresses. Valid values are `ipv4` (default) and `ipv6` | `string` | `null` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/eks-managed-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module "user_data" {
cluster_service_ipv4_cidr = var.cluster_service_ipv4_cidr

enable_bootstrap_user_data = var.enable_bootstrap_user_data
cloud_config_content_type = var.cloud_config_content_type
pre_bootstrap_user_data = var.pre_bootstrap_user_data
post_bootstrap_user_data = var.post_bootstrap_user_data
bootstrap_extra_args = var.bootstrap_extra_args
Expand Down
6 changes: 6 additions & 0 deletions modules/eks-managed-node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ variable "cluster_service_ipv4_cidr" {
default = null
}

variable "cloud_config_content_type" {
description = "Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
default = ""
}

variable "pre_bootstrap_user_data" {
description = "User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
Expand Down
1 change: 1 addition & 0 deletions modules/self-managed-node-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module "self_managed_node_group" {
| <a name="input_bootstrap_extra_args"></a> [bootstrap\_extra\_args](#input\_bootstrap\_extra\_args) | Additional arguments passed to the bootstrap script. When `platform` = `bottlerocket`; these are additional [settings](https://github.com/bottlerocket-os/bottlerocket#settings) that are provided to the Bottlerocket user data | `string` | `""` | no |
| <a name="input_capacity_rebalance"></a> [capacity\_rebalance](#input\_capacity\_rebalance) | Indicates whether capacity rebalance is enabled | `bool` | `null` | no |
| <a name="input_capacity_reservation_specification"></a> [capacity\_reservation\_specification](#input\_capacity\_reservation\_specification) | Targeting for EC2 capacity reservations | `any` | `{}` | no |
| <a name="input_cloud_config_content_type"></a> [cloud\_config\_content\_type](#input\_cloud\_config\_content\_type) | Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
| <a name="input_cluster_auth_base64"></a> [cluster\_auth\_base64](#input\_cluster\_auth\_base64) | Base64 encoded CA of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_endpoint"></a> [cluster\_endpoint](#input\_cluster\_endpoint) | Endpoint of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_ip_family"></a> [cluster\_ip\_family](#input\_cluster\_ip\_family) | The IP family used to assign Kubernetes pod and service addresses. Valid values are `ipv4` (default) and `ipv6` | `string` | `null` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/self-managed-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module "user_data" {
cluster_auth_base64 = var.cluster_auth_base64

enable_bootstrap_user_data = true
cloud_config_content_type = var.cloud_config_content_type
pre_bootstrap_user_data = var.pre_bootstrap_user_data
post_bootstrap_user_data = var.post_bootstrap_user_data
bootstrap_extra_args = var.bootstrap_extra_args
Expand Down
6 changes: 6 additions & 0 deletions modules/self-managed-node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ variable "cluster_auth_base64" {
default = ""
}

variable "cloud_config_content_type" {
description = "Content type of the user data script injected ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
default = ""
}

variable "pre_bootstrap_user_data" {
description = "User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket`"
type = string
Expand Down
16 changes: 9 additions & 7 deletions node_groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ module "eks_managed_node_group" {
cluster_auth_base64 = try(aws_eks_cluster.this[0].certificate_authority[0].data, "")
cluster_service_ipv4_cidr = var.cluster_service_ipv4_cidr
enable_bootstrap_user_data = try(each.value.enable_bootstrap_user_data, var.eks_managed_node_group_defaults.enable_bootstrap_user_data, false)
cloud_config_content_type = try(each.value.cloud_config_content_type, var.eks_managed_node_group_defaults.cloud_config_content_type, "text/x-shellscript")
pre_bootstrap_user_data = try(each.value.pre_bootstrap_user_data, var.eks_managed_node_group_defaults.pre_bootstrap_user_data, "")
post_bootstrap_user_data = try(each.value.post_bootstrap_user_data, var.eks_managed_node_group_defaults.post_bootstrap_user_data, "")
bootstrap_extra_args = try(each.value.bootstrap_extra_args, var.eks_managed_node_group_defaults.bootstrap_extra_args, "")
Expand Down Expand Up @@ -393,13 +394,14 @@ module "self_managed_node_group" {
autoscaling_group_tags = try(each.value.autoscaling_group_tags, var.self_managed_node_group_defaults.autoscaling_group_tags, {})

# User data
platform = try(each.value.platform, var.self_managed_node_group_defaults.platform, "linux")
cluster_endpoint = try(aws_eks_cluster.this[0].endpoint, "")
cluster_auth_base64 = try(aws_eks_cluster.this[0].certificate_authority[0].data, "")
pre_bootstrap_user_data = try(each.value.pre_bootstrap_user_data, var.self_managed_node_group_defaults.pre_bootstrap_user_data, "")
post_bootstrap_user_data = try(each.value.post_bootstrap_user_data, var.self_managed_node_group_defaults.post_bootstrap_user_data, "")
bootstrap_extra_args = try(each.value.bootstrap_extra_args, var.self_managed_node_group_defaults.bootstrap_extra_args, "")
user_data_template_path = try(each.value.user_data_template_path, var.self_managed_node_group_defaults.user_data_template_path, "")
platform = try(each.value.platform, var.self_managed_node_group_defaults.platform, "linux")
cluster_endpoint = try(aws_eks_cluster.this[0].endpoint, "")
cluster_auth_base64 = try(aws_eks_cluster.this[0].certificate_authority[0].data, "")
cloud_config_content_type = try(each.value.cloud_config_content_type, var.eks_managed_node_group_defaults.cloud_config_content_type, "text/x-shellscript")
pre_bootstrap_user_data = try(each.value.pre_bootstrap_user_data, var.self_managed_node_group_defaults.pre_bootstrap_user_data, "")
post_bootstrap_user_data = try(each.value.post_bootstrap_user_data, var.self_managed_node_group_defaults.post_bootstrap_user_data, "")
bootstrap_extra_args = try(each.value.bootstrap_extra_args, var.self_managed_node_group_defaults.bootstrap_extra_args, "")
user_data_template_path = try(each.value.user_data_template_path, var.self_managed_node_group_defaults.user_data_template_path, "")

# Launch Template
create_launch_template = try(each.value.create_launch_template, var.self_managed_node_group_defaults.create_launch_template, true)
Expand Down