Shared state is working. Qeurying for default VPC.

consolidate
Curtis Wilson 4 years ago
parent d8cdc95573
commit b73f00dd1b

@ -1,23 +1,3 @@
terraform {
required_version = ">= 1.0.8"
backend "s3" {
bucket = "mss-terraform-state"
key = "global/s3/terraform.tfstate"
region = "us-gov-west-1"
dynamodb_table = "mss-terraform-state-lock"
encrypt = true
}
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.6.11"
}
}
}
locals {
nodes-config = {
@ -54,10 +34,6 @@ module "cloud-init-config" {
# libvirt modules/resources.
################################################################################
provider "aws" {
region = "us-gov-west-1"
}
# This module will grab the latest ami for a variety of distros. Uncomment to
# get a list of the latest AMIs for our supported distros.
# module "aws-amis" {
@ -67,14 +43,27 @@ provider "aws" {
# value = module.aws-amis.amis
# }
module "aws-network" {
source = "./modules/aws-network"
name-prefix = var.vm-name-prefix
vpc-cidr-block = var.aws-vpc-cidr-block
subnet-cidr-block = var.aws-subnet-cidr-block
admin-ips = var.admin-ips
################################################################################
# AWS Networking
# Use of the 2 modules below to create resources for the AWS network.
# aws-network-from-scratch will build the AWS network from scratch.
# aws-network-existing will query AWS for an existing VPC.
################################################################################
# module "aws-network-from-scratch" {
# source = "./modules/aws-network-from-scratch"
# name-prefix = var.vm-name-prefix
# vpc-cidr-block = var.aws-vpc-cidr-block
# subnet-cidr-block = var.aws-subnet-cidr-block
# admin-ips = var.admin-ips
# }
module "aws-network-existing" {
source = "./modules/aws-network-existing"
}
################################################################################
# This key pair is not actually used. Keys are added to the nodes via cloud-init
# instead. We just add this here that this key will show up in the AWS console."
resource "aws_key_pair" "key" {

@ -0,0 +1,23 @@
locals {
az-to-subnets = {
for s in data.aws_subnet.subnets : s.availability_zone => s.id...
}
}
data "aws_vpc" "default" {
tags = {
Name = var.default-vpc-name
}
}
data "aws_subnets" "subnet-ids" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}
data "aws_subnet" "subnets" {
for_each = toset(data.aws_subnets.subnet-ids.ids)
id = each.key
}

@ -0,0 +1,18 @@
output "default-vpc" {
value = data.aws_vpc.default
}
output "subnets" {
description = "An array of all subnets in default-vpc."
value = data.aws_subnet.subnets
}
output "k8s-subnets" {
description = "An array of subnets to be used for k8s VMs. These subnets were chosen by selecting a single subnet from each availability_zone."
value = [for k,v in local.az-to-subnets : v[0]]
}
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
}

@ -0,0 +1,4 @@
variable "default-vpc-name" {
description = "The name of the existing default VPC. This module will query AWS for a VPC with this name,"
default = "Managed VPC"
}

@ -8,6 +8,11 @@ variable "aws-ec2-instance-type" {
description = "The AWS instance type to use for all nodes."
}
variable "aws-region" {
default = "us-east-1"
description = "The AWS region to use."
}
variable "aws-subnet-cidr-block" {
default = "10.0.1.0/24"
description = "The address space to be used for this subnet."

Loading…
Cancel
Save