finish
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
resource "aws_vpc" "main_vpc" {
|
||||
cidr_block = var.vpc_cidr_block
|
||||
|
||||
tags = merge(var.common_tags, {
|
||||
Name = var.vpc_name
|
||||
})
|
||||
}
|
||||
|
||||
data "aws_availability_zones" "az" {
|
||||
filter {
|
||||
name = "opt-in-status"
|
||||
values = ["opt-in-not-required"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "subnet" {
|
||||
for_each = var.subnets
|
||||
|
||||
vpc_id = aws_vpc.main_vpc.id
|
||||
cidr_block = each.value.cidr
|
||||
availability_zone = element(data.aws_availability_zones.az.names, each.value.az_id)
|
||||
|
||||
tags = merge(var.common_tags, {
|
||||
Name = "${var.subnet_name_prefix}-${each.key}"
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
output "subnet_ids" {
|
||||
description = "Subnet IDs"
|
||||
value = { for k, v in aws_subnet.subnet : k => v.id }
|
||||
}
|
||||
|
||||
output "subnet_az" {
|
||||
description = "Subnet AZs"
|
||||
value = { for k, v in aws_subnet.subnet : k => v.availability_zone }
|
||||
}
|
||||
|
||||
output "subnets" {
|
||||
description = "Subnets data"
|
||||
value = { for k, v in aws_subnet.subnet : k => {
|
||||
id = v.id,
|
||||
az = v.availability_zone
|
||||
}}
|
||||
}
|
||||
|
||||
output "subnets_full" {
|
||||
description = "Subnets all data"
|
||||
value = aws_subnet.subnet
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
variable "vpc_name" {
|
||||
type = string
|
||||
description = "VPC name"
|
||||
}
|
||||
|
||||
variable "vpc_cidr_block" {
|
||||
description = "VPC CIDR block"
|
||||
type = string
|
||||
default = "10.0.0.0/16"
|
||||
}
|
||||
|
||||
variable "subnet_name_prefix" {
|
||||
description = "Subnet name prefix"
|
||||
type = string
|
||||
default = "sub"
|
||||
}
|
||||
|
||||
variable "common_tags" {
|
||||
type = map(string)
|
||||
description = "Default common tags"
|
||||
default = {
|
||||
Owner = "user"
|
||||
CourseId = "my_course"
|
||||
}
|
||||
}
|
||||
|
||||
variable "subnets" {
|
||||
description = "Subnets to create"
|
||||
type = map(map(string))
|
||||
default = {}
|
||||
}
|
||||
Reference in New Issue
Block a user