From ea5a4ffdd64ed9fd71bf1830914cb786becd6170 Mon Sep 17 00:00:00 2001 From: Aleksandr Titov <26012167+AleksandrTitov@users.noreply.github.com> Date: Wed, 24 May 2023 16:34:05 +0300 Subject: [PATCH] feat: Add module ELB IP Group (#1) --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- main.tf | 16 ++++++++++++++++ outputs.tf | 9 +++++++++ variables.tf | 29 +++++++++++++++++++++++++++++ versions.tf | 7 +++++++ 5 files changed, 103 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7234d11..690ced5 100644 --- a/README.md +++ b/README.md @@ -1 +1,42 @@ -# Module name \ No newline at end of file +# Huaweicloud ELB IP Group + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | ~> 1.4 | +| [huaweicloud](#requirement\_huaweicloud) | ~>1.47 | + +## Providers + +| Name | Version | +|------|---------| +| [huaweicloud](#provider\_huaweicloud) | ~>1.47 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [huaweicloud_elb_ipgroup.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/elb_ipgroup) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [description](#input\_description) | Specifies the description of an elb ip group | `string` | `null` | no | +| [ip\_list](#input\_ip\_list) | Specifies the list of allowed IP address or CIDR block | `list(string)` | `[]` | no | +| [name](#input\_name) | Specifies the elb ip group name | `string` | n/a | yes | +| [name\_postfix](#input\_name\_postfix) | Specifies the elb ip group name postfix | `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 | + +## Outputs + +| Name | Description | +|------|-------------| +| [id](#output\_id) | The uuid of the ip group | +| [name](#output\_name) | The name of the ip group | + \ No newline at end of file diff --git a/main.tf b/main.tf index e69de29..835f9f3 100644 --- a/main.tf +++ b/main.tf @@ -0,0 +1,16 @@ +locals { + name = var.name_postfix == null ? format("%s-ip-group", var.name) : format("%s-elb-%s", var.name, var.name_postfix) +} + +resource "huaweicloud_elb_ipgroup" "main" { + name = local.name + description = var.description + region = var.region + + dynamic "ip_list" { + for_each = toset(var.ip_list) + content { + ip = ip_list.key + } + } +} diff --git a/outputs.tf b/outputs.tf index e69de29..11525d5 100644 --- a/outputs.tf +++ b/outputs.tf @@ -0,0 +1,9 @@ +output "id" { + description = "The uuid of the ip group" + value = huaweicloud_elb_ipgroup.main.id +} + +output "name" { + description = "The name of the ip group" + value = huaweicloud_elb_ipgroup.main.name +} diff --git a/variables.tf b/variables.tf index e69de29..d9c4495 100644 --- a/variables.tf +++ b/variables.tf @@ -0,0 +1,29 @@ +variable "name" { + description = "Specifies the elb ip group name" + type = string + nullable = false +} + +variable "name_postfix" { + description = "Specifies the elb ip group name postfix" + type = string + default = null +} + +variable "description" { + description = "Specifies the description of an elb ip 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 "ip_list" { + description = "Specifies the list of allowed IP address or CIDR block" + type = list(string) + default = [] +} 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" + } + } }