From 0f0c299a852da76d92989771cbae660104d57c46 Mon Sep 17 00:00:00 2001 From: freesky-edward Date: Thu, 12 Sep 2019 19:31:25 +0800 Subject: [PATCH] Add shared bandwidth support --- .../huaweicloud/internet/internet_temp.tf | 12 ++++++---- .../huaweicloud/internet/internet_vars.tf | 7 ++++++ environment/huaweicloud/internet/out_puts.tf | 5 ++++ environment/huaweicloud/resources.tf | 23 ++++++++++++------- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/environment/huaweicloud/internet/internet_temp.tf b/environment/huaweicloud/internet/internet_temp.tf index 2e3e5e7..3201572 100644 --- a/environment/huaweicloud/internet/internet_temp.tf +++ b/environment/huaweicloud/internet/internet_temp.tf @@ -4,9 +4,13 @@ resource "huaweicloud_vpc_eip_v1" "this" { type = "5_bgp" } bandwidth { - name = "${lookup(var.eips[count.index], "bandwidth-name", null)}" - size = "${lookup(var.eips[count.index], "size", null)}" - share_type = "PER" - charge_mode = "traffic" + id = "${lookup(var.eips[count.index], "bandwidth_id", null)}" + share_type = "WHOLE" } } + +resource "huaweicloud_vpc_bandwidth_v2" "this" { + count = "${length(var.bandwidths)}" + name = "${lookup(var.bandwidths[count.index], "name", null)}" + size = "${lookup(var.bandwidths[count.index], "size", 5)}" +} diff --git a/environment/huaweicloud/internet/internet_vars.tf b/environment/huaweicloud/internet/internet_vars.tf index 86a9ac9..0664e72 100644 --- a/environment/huaweicloud/internet/internet_vars.tf +++ b/environment/huaweicloud/internet/internet_vars.tf @@ -3,3 +3,10 @@ variable "eips" { description = "List of eips" default = [] } + + +variable "bandwidths" { + type = list(map(string)) + description = "List of bandwidths" + default = [] +} diff --git a/environment/huaweicloud/internet/out_puts.tf b/environment/huaweicloud/internet/out_puts.tf index 4f55f0b..b4fc5f1 100644 --- a/environment/huaweicloud/internet/out_puts.tf +++ b/environment/huaweicloud/internet/out_puts.tf @@ -7,3 +7,8 @@ output "this_eip_addresses" { description = "List of address of the eips" value = "${join(",",huaweicloud_vpc_eip_v1.this.*.publicip.0.ip_address)}" } + +output "this_bandwidth_ids" { + description = "List of bandwidth ids" + value = "${join(",",huaweicloud_vpc_bandwidth_v2.this.*.id)}" +} diff --git a/environment/huaweicloud/resources.tf b/environment/huaweicloud/resources.tf index 00d0419..40a3dda 100644 --- a/environment/huaweicloud/resources.tf +++ b/environment/huaweicloud/resources.tf @@ -49,23 +49,30 @@ module "cce" { module "internet" { source = "./internet" + + bandwidths = [ + { + name = "bandwidth-mail" + size = "5" + }, + { + name = "bandwidth-website" + size = "30" + } + ] eips = [ { - bandwidth-name = "bandwidth-01", - size = "5" + bandwidth_id = "${split(",", module.internet.this_bandwidth_ids)[0]}" }, { - bandwidth-name = "bandwidth-02", - size = "5" + bandwidth_id = "${split(",", module.internet.this_bandwidth_ids)[0]}" }, { - bandwidth-name = "bandwidth-03", - size = "5" + bandwidth_id = "${split(",", module.internet.this_bandwidth_ids)[0]}" }, { - bandwidth-name = "bandwidth-04", - size = "5" + bandwidth_id = "${split(",", module.internet.this_bandwidth_ids)[1]}" } ] } -- GitLab