diff --git a/examples/basic-networking/main.tf b/examples/basic-networking/main.tf index 0189655..5692fd5 100644 --- a/examples/basic-networking/main.tf +++ b/examples/basic-networking/main.tf @@ -1,8 +1,43 @@ -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 -} \ No newline at end of file +module "vpc" { + source = "alibaba/vpc/alicloud" + version = "1.10.0" + + vpc_name = var.vpc-name + vpc_cidr = var.vpc-cidr + 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 +# } \ No newline at end of file diff --git a/examples/basic-networking/outputs.tf b/examples/basic-networking/outputs.tf index 9f7b29a..3973817 100644 --- a/examples/basic-networking/outputs.tf +++ b/examples/basic-networking/outputs.tf @@ -1,3 +1,9 @@ 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 } \ No newline at end of file diff --git a/examples/basic-networking/terraform.tfvars b/examples/basic-networking/terraform.tfvars index dff5c9f..98e8cfb 100644 --- a/examples/basic-networking/terraform.tfvars +++ b/examples/basic-networking/terraform.tfvars @@ -1,3 +1,4 @@ -vpc-name = "DefaultVpc" -vpc-description = "Default Vpc" -vpc-cidr = "172.16.0.0/16" \ No newline at end of file +vpc-name = "DemoVpc" +vpc-description = "Demo Vpc" +vpc-cidr = "172.28.0.0/16" +vswitch-prefix = "DemoVswitch" \ No newline at end of file diff --git a/examples/basic-networking/variables.tf b/examples/basic-networking/variables.tf index 6b2c7d8..d564ea6 100644 --- a/examples/basic-networking/variables.tf +++ b/examples/basic-networking/variables.tf @@ -11,4 +11,9 @@ variable vpc-description { variable vpc-cidr { type = string description = "CIDR of VPC" +} + +variable vswitch-prefix { + type = string + description = "Prefix of vswitch names" } \ No newline at end of file