Nodes are created across the given subnets.
This commit is contained in:
@@ -22,6 +22,14 @@ data "aws_subnet" "subnets" {
|
||||
id = each.key
|
||||
}
|
||||
|
||||
data "aws_subnet" "subnet-by-name" {
|
||||
for_each = toset(var.existing-subnet-names)
|
||||
filter {
|
||||
name = "tag:Name"
|
||||
values = [each.key]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_security_group" "default" {
|
||||
name = var.default-security-group-name
|
||||
}
|
||||
|
||||
@@ -11,11 +11,16 @@ output "subnets" {
|
||||
value = data.aws_subnet.subnets
|
||||
}
|
||||
|
||||
output "k8s-subnets-ids" {
|
||||
description = "An array of subnets to be used for k8s VMs. These subnets were chosen by selecting a single subnet from each availability_zone."
|
||||
output "one-subnet-per-az" {
|
||||
description = "An array of subnets that selects 1 subnet per az."
|
||||
value = [for k,v in local.az-to-subnets : v[0]]
|
||||
}
|
||||
|
||||
output "subnet-by-name" {
|
||||
description = "A map of subnet name to subnet resource."
|
||||
value = data.aws_subnet.subnet-by-name
|
||||
}
|
||||
|
||||
output "az-to-subnets" {
|
||||
description = "A map of availability zone to array of subnets that are in thet availability zone."
|
||||
value = local.az-to-subnets
|
||||
|
||||
@@ -5,3 +5,9 @@ variable "default-security-group-name" {
|
||||
variable "default-vpc-name" {
|
||||
description = "The name of the existing default VPC. This module will query AWS for a VPC with this name,"
|
||||
}
|
||||
|
||||
variable "existing-subnet-names" {
|
||||
description = "A list of subnet names that already exist in default-vpc-name"
|
||||
default = []
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ resource "aws_instance" "nodes" {
|
||||
instance_type = var.ec2-instance-type
|
||||
# TODO Make this a variable.
|
||||
associate_public_ip_address = true
|
||||
subnet_id = var.subnet-id
|
||||
subnet_id = element(var.subnet-ids, count.index % length(var.subnet-ids))
|
||||
vpc_security_group_ids = var.security-group-ids
|
||||
user_data = element(var.user-datas.*.rendered, count.index)
|
||||
count = var.num-nodes
|
||||
|
||||
@@ -25,9 +25,9 @@ variable "user-datas" {
|
||||
description = "A list of cloud-init configs that get applied to their corresponding node."
|
||||
}
|
||||
|
||||
variable "subnet-id" {
|
||||
description = "The ID of the subnet that all the nodes will be added to."
|
||||
type = string
|
||||
variable "subnet-ids" {
|
||||
description = "An array of subnet ids. These subnets will be round robined as the subnet to use for each node."
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "security-group-ids" {
|
||||
|
||||
Reference in New Issue
Block a user