UPD: Replaced standalone resources with vpc module

This commit is contained in:
KF 2024-07-26 10:03:03 +08:00
parent 8902c5c43a
commit 46b19a606f
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
4 changed files with 59 additions and 12 deletions

View File

@ -1,8 +1,43 @@
resource "alicloud_vpc" "vpc" { module "vpc" {
vpc_name = var.vpc-name source = "alibaba/vpc/alicloud"
description = var.vpc-description version = "1.10.0"
cidr_block = var.vpc-cidr
is_default = true vpc_name = var.vpc-name
enable_ipv6 = false vpc_cidr = var.vpc-cidr
tags = local.tags availability_zones = data.alicloud_zones.zones.ids
vswitch_cidrs = cidrsubnets(var.vpc-cidr, 2, 2)
vswitch_name = var.vswitch-prefix
vpc_tags = local.tags
vswitch_tags = local.tags
} }
data "alicloud_zones" "zones" {
available_disk_category = "cloud_ssd"
available_resource_creation = "VSwitch"
}
# resource "alicloud_vpc" "vpc" {
# vpc_name = var.vpc-name
# description = var.vpc-description
# cidr_block = var.vpc-cidr
# is_default = true
# enable_ipv6 = false
# tags = local.tags
# }
#
#
# locals {
# vswitch-cidrs = cidrsubnets(var.vpc-cidr, 2, 2)
# vswitch-map = {
# for k, v in zipmap(local.vswitch-cidrs, data.alicloud_zones.zones.ids) : v => k
# }
# }
#
# resource "alicloud_vswitch" "vswitches" {
# for_each = local.vswitch-map
# vswitch_name = "Vswitch-${each.key}"
# cidr_block = each.value
# vpc_id = alicloud_vpc.vpc.id
# zone_id = each.key
# }

View File

@ -1,3 +1,9 @@
output "vpc-id" { output "vpc-id" {
value = alicloud_vpc.vpc.id # value = alicloud_vpc.vpc.id
value = module.vpc.vpc_id
}
output "vswitch-cidrs" {
# value = local.vswitch-map
value = module.vpc.this_vswitch_cidr_blocks
} }

View File

@ -1,3 +1,4 @@
vpc-name = "DefaultVpc" vpc-name = "DemoVpc"
vpc-description = "Default Vpc" vpc-description = "Demo Vpc"
vpc-cidr = "172.16.0.0/16" vpc-cidr = "172.28.0.0/16"
vswitch-prefix = "DemoVswitch"

View File

@ -12,3 +12,8 @@ variable vpc-cidr {
type = string type = string
description = "CIDR of VPC" description = "CIDR of VPC"
} }
variable vswitch-prefix {
type = string
description = "Prefix of vswitch names"
}