mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Commit first run at using modules
Commit a set of files that show the use of modules Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
parent
545996b891
commit
fa0bd115bb
6 changed files with 106 additions and 0 deletions
23
terraform/aws/simple-module/main.tf
Normal file
23
terraform/aws/simple-module/main.tf
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
module "vpc20" {
|
||||
source = "./modules/vpc"
|
||||
|
||||
name = "test-vpc-1"
|
||||
vpc_cidr_block = "10.20.0.0/16"
|
||||
vpc_dns_hostnames = "true"
|
||||
vpc_dns_support = "true"
|
||||
|
||||
subnet_cidr_block = "10.20.1.0/24"
|
||||
subnet_map_pub_ip = "true"
|
||||
}
|
||||
|
||||
module "vpc50" {
|
||||
source = "./modules/vpc"
|
||||
|
||||
name = "test-vpc-1"
|
||||
vpc_cidr_block = "10.50.0.0/16"
|
||||
vpc_dns_hostnames = "true"
|
||||
vpc_dns_support = "true"
|
||||
|
||||
subnet_cidr_block = "10.50.1.0/24"
|
||||
subnet_map_pub_ip = "true"
|
||||
}
|
||||
36
terraform/aws/simple-module/modules/vpc/main.tf
Normal file
36
terraform/aws/simple-module/modules/vpc/main.tf
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Create a new VPC
|
||||
resource "aws_vpc" "vpc" {
|
||||
cidr_block = "${var.vpc_cidr_block}"
|
||||
enable_dns_hostnames = "${var.vpc_dns_hostnames}"
|
||||
enable_dns_support = "${var.vpc_dns_support}"
|
||||
}
|
||||
|
||||
# Create a public subnet in the new VPC
|
||||
resource "aws_subnet" "subnet" {
|
||||
vpc_id = "${aws_vpc.vpc.id}"
|
||||
cidr_block = "${var.subnet_cidr_block}"
|
||||
map_public_ip_on_launch = "${var.subnet_map_pub_ip}"
|
||||
}
|
||||
|
||||
# Create a new Internet gateway
|
||||
resource "aws_internet_gateway" "gateway" {
|
||||
vpc_id = "${aws_vpc.vpc.id}"
|
||||
}
|
||||
|
||||
# Create a route table for the new VPC
|
||||
resource "aws_route_table" "routes" {
|
||||
vpc_id = "${aws_vpc.vpc.id}"
|
||||
}
|
||||
|
||||
# Create a route in new route table
|
||||
resource "aws_route" "default_route" {
|
||||
route_table_id = "${aws_route_table.routes.id}"
|
||||
destination_cidr_block = "0.0.0.0/0"
|
||||
gateway_id = "${aws_internet_gateway.gateway.id}"
|
||||
}
|
||||
|
||||
# Associate route table with subnet in VPC
|
||||
resource "aws_route_table_association" "rte_tbl_assoc" {
|
||||
subnet_id = "${aws_subnet.subnet.id}"
|
||||
route_table_id = "${aws_route_table.routes.id}"
|
||||
}
|
||||
11
terraform/aws/simple-module/modules/vpc/output.tf
Normal file
11
terraform/aws/simple-module/modules/vpc/output.tf
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
output "new_vpc_id" {
|
||||
value = "${aws_vpc.vpc.id}"
|
||||
}
|
||||
|
||||
output "new_subnet_id" {
|
||||
value = "${aws_subnet.subnet.id}"
|
||||
}
|
||||
|
||||
output "new_subnet_az" {
|
||||
value = "${aws_subnet.subnet.availability_zone}"
|
||||
}
|
||||
29
terraform/aws/simple-module/modules/vpc/variables.tf
Normal file
29
terraform/aws/simple-module/modules/vpc/variables.tf
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
variable "name" {
|
||||
type = "string"
|
||||
description = "Name prefix to use for networking resources"
|
||||
}
|
||||
|
||||
variable "vpc_cidr_block" {
|
||||
type = "string"
|
||||
description = "CIDR block to use for new VPC"
|
||||
}
|
||||
|
||||
variable "vpc_dns_hostnames" {
|
||||
type = "string"
|
||||
description = "True/False to enable DNS hostnames in new VPC"
|
||||
}
|
||||
|
||||
variable "vpc_dns_support" {
|
||||
type = "string"
|
||||
description = "True/False to enable DNS support in new VPC"
|
||||
}
|
||||
|
||||
variable "subnet_cidr_block" {
|
||||
type = "string"
|
||||
description = "CIDR block (in VPC CIDR block) to use for new subnet"
|
||||
}
|
||||
|
||||
variable "subnet_map_pub_ip" {
|
||||
type = "string"
|
||||
description = "True/False to map public IP addresses on launch"
|
||||
}
|
||||
3
terraform/aws/simple-module/provider.tf
Normal file
3
terraform/aws/simple-module/provider.tf
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
provider "aws" {
|
||||
region = "${var.user_region}"
|
||||
}
|
||||
4
terraform/aws/simple-module/variables.tf
Normal file
4
terraform/aws/simple-module/variables.tf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
variable "user_region" {
|
||||
type = "string"
|
||||
description = "AWS region to use for all resources"
|
||||
}
|
||||
Loading…
Reference in a new issue