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

Add optional network_interface_id variable #124

Merged
merged 12 commits into from
Nov 2, 2023
12 changes: 7 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ resource "aws_launch_template" "default" {

# https://github.com/terraform-providers/terraform-provider-aws/issues/4570
network_interfaces {
description = module.this.id
description = var.network_interface_id == null ? module.this.id : null
device_index = 0
associate_public_ip_address = var.associate_public_ip_address
delete_on_termination = true
security_groups = var.security_group_ids
associate_public_ip_address = var.network_interface_id == null ? var.associate_public_ip_address : null
delete_on_termination = var.network_interface_id == null ? true : false
security_groups = var.network_interface_id == null ? var.security_group_ids : null
network_interface_id = var.network_interface_id
}

metadata_options {
Expand Down Expand Up @@ -149,7 +150,8 @@ resource "aws_autoscaling_group" "default" {
count = module.this.enabled ? 1 : 0

name_prefix = format("%s%s", module.this.id, module.this.delimiter)
vpc_zone_identifier = var.subnet_ids
vpc_zone_identifier = var.availability_zones == null ? var.subnet_ids : null
availability_zones = var.subnet_ids == null ? var.availability_zones : null
gbarna-bd marked this conversation as resolved.
Show resolved Hide resolved
max_size = var.max_size
min_size = var.min_size
load_balancers = var.load_balancers
Expand Down
18 changes: 16 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ variable "launch_template_version" {
}

variable "associate_public_ip_address" {
type = bool
description = "Associate a public IP address with an instance in a VPC"
type = bool
# https://stackoverflow.com/a/76808361
description = "Associate a public IP address with an instance in a VPC. If a network_interface id is specified, this can only be false."
gbarna-bd marked this conversation as resolved.
Show resolved Hide resolved
default = false
}

variable "network_interface_id" {
type = string
description = "The ID of the network interface to attach. If specified, all the other network_interface block arguments are ignored."
default = null
}

variable "user_data_base64" {
type = string
description = "The Base64-encoded user data to provide when launching the instances"
Expand Down Expand Up @@ -196,8 +203,15 @@ variable "min_size" {
}

variable "subnet_ids" {
type = list(string)
description = "A list of subnet IDs to launch resources in"
default = null
gbarna-bd marked this conversation as resolved.
Show resolved Hide resolved
}

variable "availability_zones" {
type = list(string)
description = "A list of Availability Zones where instances in the Auto Scaling group can be created. Used for launching into the default VPC subnet in each Availability Zone when not using the subnet_ids variable, or for attaching a network interface when an existing network interface ID is specified. Conflicts with subnet_ids."
default = null
}

variable "default_cooldown" {
Expand Down