From cc0948d9670b07d79787cf37530e16033dd6236f Mon Sep 17 00:00:00 2001 From: Aleksandr Titov Date: Mon, 18 Sep 2023 13:48:52 +0300 Subject: [PATCH 1/7] feat: Add module VPC Address Group --- README.md | 2 +- main.tf | 20 +++++++++++++++ outputs.tf | 4 +++ variables.tf | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7234d11..130f056 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Module name \ No newline at end of file +# Huawei Cloud VPC Address Group \ No newline at end of file diff --git a/main.tf b/main.tf index e69de29..26ba1ed 100644 --- a/main.tf +++ b/main.tf @@ -0,0 +1,20 @@ +locals { + name = var.name_postfix == null ? format("%s-key", var.name) : format("%s-key-%s", var.name, var.name_postfix) +} + +resource "huaweicloud_vpc_address_group" "main" { + name = local.name + region = var.region + ip_version = var.ip_version + + addresses = slice(var.addresses, 0, var.max_capacity - 1) + description = var.description + max_capacity = var.max_capacity + force_destroy = var.force_destroy + + timeouts { + create = var.timeouts.create + update = var.timeouts.update + delete = var.timeouts.delete + } +} diff --git a/outputs.tf b/outputs.tf index e69de29..7be2347 100644 --- a/outputs.tf +++ b/outputs.tf @@ -0,0 +1,4 @@ +output "id" { + description = "The Address Group ID in UUID format" + value = huaweicloud_vpc_address_group.main.id +} diff --git a/variables.tf b/variables.tf index e69de29..6d3305a 100644 --- a/variables.tf +++ b/variables.tf @@ -0,0 +1,71 @@ +variable "name" { + description = "Specifies a name for the Address Group" + type = string + nullable = false +} + +variable "name_postfix" { + description = "Specifies a postfix for the Address Group" + type = string + default = null +} + +variable "region" { + description = "Specifies the region in which to create the resource, if omitted, the provider-level region will be used" + type = string + default = null +} + +variable "addresses" { + description = "Specifies an array of one or more IP addresses, the address can be a single IP address, IP address range or IP address" + type = list(string) + validation { + condition = length(var.addresses) <= 20 + error_message = "The maximum length is 20." + } +} + +variable "ip_version" { + description = "Specifies the IP version, changing this creates a new address group" + type = string + default = "4" + validation { + condition = var.ip_version == "4" && var.ip_version == "6" + error_message = "There are two versions of IP that currently coexist in the global Internet: 4(IPv4) and 6(IPv6)" + } +} + +variable "description" { + description = "Specifies the supplementary information about the IP address group" + type = string + default = null +} + +variable "max_capacity" { + description = "Specifies the maximum number of addresses that an address group can contain" + type = number + default = 20 + validation { + condition = var.max_capacity >= 1 && var.max_capacity <= 20 + error_message = "Value range: 1-20" + } +} + +variable "force_destroy" { + description = < Date: Mon, 18 Sep 2023 10:52:52 +0000 Subject: [PATCH 2/7] terraform-docs: automated action --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 130f056..ed29377 100644 --- a/README.md +++ b/README.md @@ -1 +1,44 @@ -# Huawei Cloud VPC Address Group \ No newline at end of file +# Huawei Cloud VPC Address Group + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | ~> 1.4 | + +## Providers + +| Name | Version | +|------|---------| +| [huaweicloud](#provider\_huaweicloud) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [huaweicloud_vpc_address_group.main](https://registry.terraform.io/providers/hashicorp/huaweicloud/latest/docs/resources/vpc_address_group) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [addresses](#input\_addresses) | Specifies an array of one or more IP addresses, the address can be a single IP address, IP address range or IP address | `list(string)` | n/a | yes | +| [description](#input\_description) | Specifies the supplementary information about the IP address group | `string` | `null` | no | +| [force\_destroy](#input\_force\_destroy) | Specifies whether to forcibly destroy the address group if it is associated with a security group rule,the address
group and the associated security group rule will be deleted together | `bool` | `false` | no | +| [ip\_version](#input\_ip\_version) | Specifies the IP version, changing this creates a new address group | `string` | `"4"` | no | +| [max\_capacity](#input\_max\_capacity) | Specifies the maximum number of addresses that an address group can contain | `number` | `20` | no | +| [name](#input\_name) | Specifies a name for the Address Group | `string` | n/a | yes | +| [name\_postfix](#input\_name\_postfix) | Specifies a postfix for the Address Group | `string` | `null` | no | +| [region](#input\_region) | Specifies the region in which to create the resource, if omitted, the provider-level region will be used | `string` | `null` | no | +| [timeouts](#input\_timeouts) | Address group timeouts configuration in minutes |
map(object({
create = optional(number, 5)
update = optional(number, 5)
delete = optional(number, 5)
}))
| `{}` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | The Address Group ID in UUID format | + \ No newline at end of file From cf29cd4c97d8f6adbdb72a6347a111d696914fe0 Mon Sep 17 00:00:00 2001 From: Aleksandr Titov Date: Mon, 18 Sep 2023 13:56:27 +0300 Subject: [PATCH 3/7] fix: Add provider configuration --- versions.tf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/versions.tf b/versions.tf index 74655e1..af0509e 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,10 @@ terraform { required_version = "~> 1.4" + + required_providers { + huaweicloud = { + source = "huaweicloud/huaweicloud" + version = "~>1.47" + } + } } From ec02cf3731b35f779722e261966e89f5628c5eea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 18 Sep 2023 10:59:14 +0000 Subject: [PATCH 4/7] terraform-docs: automated action --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed29377..c2a342a 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,13 @@ | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | ~> 1.4 | +| [huaweicloud](#requirement\_huaweicloud) | ~>1.47 | ## Providers | Name | Version | |------|---------| -| [huaweicloud](#provider\_huaweicloud) | n/a | +| [huaweicloud](#provider\_huaweicloud) | ~>1.47 | ## Modules @@ -20,7 +21,7 @@ No modules. | Name | Type | |------|------| -| [huaweicloud_vpc_address_group.main](https://registry.terraform.io/providers/hashicorp/huaweicloud/latest/docs/resources/vpc_address_group) | resource | +| [huaweicloud_vpc_address_group.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/vpc_address_group) | resource | ## Inputs From 23a0c83c96cc684789cd80bf5743417e3bf08e53 Mon Sep 17 00:00:00 2001 From: Aleksandr Titov Date: Mon, 18 Sep 2023 14:01:29 +0300 Subject: [PATCH 5/7] fix: Fix type of variable timeouts --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 6d3305a..8a4dcdd 100644 --- a/variables.tf +++ b/variables.tf @@ -62,10 +62,10 @@ variable "force_destroy" { variable "timeouts" { description = "Address group timeouts configuration in minutes" - type = map(object({ + type = object({ create = optional(number, 5) update = optional(number, 5) delete = optional(number, 5) - })) + }) default = {} } From 91d935a14d4d320cc8a43589401f0c8ddfa4acdf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 18 Sep 2023 11:02:46 +0000 Subject: [PATCH 6/7] terraform-docs: automated action --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2a342a..7eab6eb 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ No modules. | [name](#input\_name) | Specifies a name for the Address Group | `string` | n/a | yes | | [name\_postfix](#input\_name\_postfix) | Specifies a postfix for the Address Group | `string` | `null` | no | | [region](#input\_region) | Specifies the region in which to create the resource, if omitted, the provider-level region will be used | `string` | `null` | no | -| [timeouts](#input\_timeouts) | Address group timeouts configuration in minutes |
map(object({
create = optional(number, 5)
update = optional(number, 5)
delete = optional(number, 5)
}))
| `{}` | no | +| [timeouts](#input\_timeouts) | Address group timeouts configuration in minutes |
object({
create = optional(number, 5)
update = optional(number, 5)
delete = optional(number, 5)
})
| `{}` | no | ## Outputs From 1f767c858e5123c82e7399b7dbcf59a2dc1df6fe Mon Sep 17 00:00:00 2001 From: Aleksandr Titov Date: Mon, 18 Sep 2023 14:03:55 +0300 Subject: [PATCH 7/7] fix: Fix naming --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 26ba1ed..a2e609e 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ locals { - name = var.name_postfix == null ? format("%s-key", var.name) : format("%s-key-%s", var.name, var.name_postfix) + name = var.name_postfix == null ? format("%s-address-group", var.name) : format("%s-address-group-%s", var.name, var.name_postfix) } resource "huaweicloud_vpc_address_group" "main" {