Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add module VPC Address Group #3

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# Module name
# Huawei Cloud VPC Address Group
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.4 |
| <a name="requirement_huaweicloud"></a> [huaweicloud](#requirement\_huaweicloud) | ~>1.47 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_huaweicloud"></a> [huaweicloud](#provider\_huaweicloud) | ~>1.47 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [huaweicloud_vpc_address_group.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/vpc_address_group) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_addresses"></a> [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 |
| <a name="input_description"></a> [description](#input\_description) | Specifies the supplementary information about the IP address group | `string` | `null` | no |
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | Specifies whether to forcibly destroy the address group if it is associated with a security group rule,the address<br> group and the associated security group rule will be deleted together | `bool` | `false` | no |
| <a name="input_ip_version"></a> [ip\_version](#input\_ip\_version) | Specifies the IP version, changing this creates a new address group | `string` | `"4"` | no |
| <a name="input_max_capacity"></a> [max\_capacity](#input\_max\_capacity) | Specifies the maximum number of addresses that an address group can contain | `number` | `20` | no |
| <a name="input_name"></a> [name](#input\_name) | Specifies a name for the Address Group | `string` | n/a | yes |
| <a name="input_name_postfix"></a> [name\_postfix](#input\_name\_postfix) | Specifies a postfix for the Address Group | `string` | `null` | no |
| <a name="input_region"></a> [region](#input\_region) | Specifies the region in which to create the resource, if omitted, the provider-level region will be used | `string` | `null` | no |
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Address group timeouts configuration in minutes | <pre>object({<br> create = optional(number, 5)<br> update = optional(number, 5)<br> delete = optional(number, 5)<br> })</pre> | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | The Address Group ID in UUID format |
<!-- END_TF_DOCS -->
20 changes: 20 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
locals {
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" {
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
}
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
description = "The Address Group ID in UUID format"
value = huaweicloud_vpc_address_group.main.id
}
71 changes: 71 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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 = <<DES
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
DES
type = bool
default = false
}

variable "timeouts" {
description = "Address group timeouts configuration in minutes"
type = object({
create = optional(number, 5)
update = optional(number, 5)
delete = optional(number, 5)
})
default = {}
}
7 changes: 7 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
terraform {
required_version = "~> 1.4"

required_providers {
huaweicloud = {
source = "huaweicloud/huaweicloud"
version = "~>1.47"
}
}
}
Loading