Compare commits
No commits in common. '9a01c09928c93bf8cc8e4610b819525c7677a126' and '6c2d3e3837d7237bf2d56baae649371c343ae4ce' have entirely different histories.
9a01c09928
...
6c2d3e3837
@ -1,27 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
data "aws_security_group" "default" {
|
|
||||||
name = var.default-security-group-name
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
output "default-vpc" {
|
|
||||||
value = data.aws_vpc.default
|
|
||||||
}
|
|
||||||
|
|
||||||
output "default-sg" {
|
|
||||||
value = data.aws_security_group.default
|
|
||||||
}
|
|
||||||
|
|
||||||
output "subnets" {
|
|
||||||
description = "An array of all subnets in default-vpc."
|
|
||||||
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."
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
variable "default-security-group-name" {
|
|
||||||
description = "The name of the existing default security group. This module will query AWS for a security group with this name,"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "default-vpc-name" {
|
|
||||||
description = "The name of the existing default VPC. This module will query AWS for a VPC with this name,"
|
|
||||||
}
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
resource "aws_vpc" "vpc" {
|
|
||||||
cidr_block = var.vpc-cidr-block
|
|
||||||
tags = {
|
|
||||||
Name = "${var.name-prefix}-vpc"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "aws_subnet" "subnet" {
|
|
||||||
vpc_id = aws_vpc.vpc.id
|
|
||||||
cidr_block = var.subnet-cidr-block
|
|
||||||
# availability_zone = var.avail_zone
|
|
||||||
tags = {
|
|
||||||
Name = "${var.name-prefix}-subnet"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "aws_default_security_group" "sg" {
|
|
||||||
vpc_id = aws_vpc.vpc.id
|
|
||||||
|
|
||||||
ingress {
|
|
||||||
from_port = 22
|
|
||||||
to_port = 22
|
|
||||||
protocol = "tcp"
|
|
||||||
cidr_blocks = var.admin-ips
|
|
||||||
}
|
|
||||||
|
|
||||||
egress {
|
|
||||||
from_port = 0
|
|
||||||
to_port = 0
|
|
||||||
protocol = "-1"
|
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
|
||||||
prefix_list_ids = []
|
|
||||||
}
|
|
||||||
|
|
||||||
tags = {
|
|
||||||
Name = "${var.name-prefix}-ssh-from-admins-sg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "aws_internet_gateway" "igw" {
|
|
||||||
vpc_id = aws_vpc.vpc.id
|
|
||||||
tags = {
|
|
||||||
Name = "${var.name-prefix}-igw"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "aws_default_route_table" "route-table" {
|
|
||||||
default_route_table_id = aws_vpc.vpc.main_route_table_id
|
|
||||||
|
|
||||||
route {
|
|
||||||
cidr_block = "0.0.0.0/0"
|
|
||||||
gateway_id = aws_internet_gateway.igw.id
|
|
||||||
}
|
|
||||||
|
|
||||||
# default route, mapping VPC CIDR block to "local", created implicitly and
|
|
||||||
# cannot be specified.
|
|
||||||
|
|
||||||
tags = {
|
|
||||||
Name = "${var.name-prefix}-route-table"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Associate subnet with Route Table
|
|
||||||
resource "aws_route_table_association" "a-rtb-subnet" {
|
|
||||||
subnet_id = aws_subnet.subnet.id
|
|
||||||
route_table_id = aws_default_route_table.route-table.id
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
output "vpc" {
|
|
||||||
value = aws_vpc.vpc
|
|
||||||
}
|
|
||||||
|
|
||||||
output "subnet" {
|
|
||||||
value = aws_subnet.subnet
|
|
||||||
}
|
|
||||||
|
|
||||||
output "default-security-group" {
|
|
||||||
value = aws_default_security_group.sg
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
variable "admin-ips" {
|
|
||||||
description = "A list of ips or cidr blocks that are allowed to connect to the nodes."
|
|
||||||
type = list(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "name-prefix" {
|
|
||||||
default = "tf"
|
|
||||||
description = "This prefix will be used in all the names of the resources creates in our AWS network."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "subnet-cidr-block" {
|
|
||||||
default = "10.0.1.0/24"
|
|
||||||
description = "The address space to be used for this subnet."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vpc-cidr-block" {
|
|
||||||
default = "10.0.0.0/16"
|
|
||||||
description = "The address space to be used for out networks VPC."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
|
|
||||||
provider "aws" {
|
|
||||||
region = "us-gov-west-1"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
#S3 bucket create to hold our TFState file so we can all share env settings
|
|
||||||
resource "aws_s3_bucket" "terraform_state" {
|
|
||||||
bucket = "mss-terraform-state"
|
|
||||||
|
|
||||||
# enable versioning for the state files
|
|
||||||
versioning {
|
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
#enable server-side encryption
|
|
||||||
server_side_encryption_configuration {
|
|
||||||
|
|
||||||
rule {
|
|
||||||
apply_server_side_encryption_by_default {
|
|
||||||
sse_algorithm = "AES256"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# no sql database used so that we can lock the TFstate file in the S3 bucket to ensure two people
|
|
||||||
# are not running a terraform command at the same time
|
|
||||||
resource "aws_dynamodb_table" "terraform_locks" {
|
|
||||||
name = "mss-terraform-state-lock"
|
|
||||||
billing_mode = "PAY_PER_REQUEST"
|
|
||||||
hash_key = "LockID"
|
|
||||||
|
|
||||||
attribute {
|
|
||||||
name = "LockID"
|
|
||||||
type = "S"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# output variable to give details on the s3 bucket created
|
|
||||||
#TODO: move to output.tf
|
|
||||||
output "s3_bucket_arn" {
|
|
||||||
value = aws_s3_bucket.terraform_state.arn
|
|
||||||
description = "The ARN of the S3 bucket"
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue