diff --git a/README.md b/README.md
index 7234d11..96df7f9 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,67 @@
-# Module name
\ No newline at end of file
+# Huawei Cloud DMS RocketMQ
+
+
+## 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_dms_rocketmq_consumer_group.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/dms_rocketmq_consumer_group) | resource |
+| [huaweicloud_dms_rocketmq_instance.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/dms_rocketmq_instance) | resource |
+| [huaweicloud_dms_rocketmq_topic.main](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/dms_rocketmq_topic) | resource |
+| [huaweicloud_availability_zones.zones](https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/data-sources/availability_zones) | data source |
+
+## Inputs
+
+| Name | Description | Type | Default | Required |
+|------|-------------|------|---------|:--------:|
+| [availability\_zones](#input\_availability\_zones) | Specifies the AZ name, if omitted, AZ calculates automatically | `list(string)` | `[]` | no |
+| [broker\_num](#input\_broker\_num) | Specifies the broker numbers | `number` | `1` | no |
+| [consumer\_groups](#input\_consumer\_groups) | RocketMQ Consumers groups:
* `key` - name of the group;
* `enabled` - specifies the consumer group is enabled or not;
* `broadcast` - specifies whether to broadcast of the consumer group;
* `brokers` - specifies the list of associated brokers of the consumer group;
* `retry_max_times` - specifies the maximum number of retry times. |
map(object({| `{}` | no | +| [description](#input\_description) | Specifies the description of the DMS RocketMQ instance | `string` | `null` | no | +| [enable\_acl](#input\_enable\_acl) | Specifies whether access control is enabled | `bool` | `false` | no | +| [enable\_publicip](#input\_enable\_publicip) | Specifies whether to enable public access | `bool` | `false` | no | +| [engine\_version](#input\_engine\_version) | Specifies the version of the RocketMQ engine | `string` | `"4.8.0"` | no | +| [flavor\_id](#input\_flavor\_id) | Specifies the instance flavor id:
enabled = optional(bool, true)
broadcast = optional(bool, true)
brokers = optional(list(string), ["broker-0"])
retry_max_times = optional(number, 3)
}))
map(object({| `{}` | no | +| [vpc\_id](#input\_vpc\_id) | Specifies the ID of a VPC | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [broker\_address](#output\_broker\_address) | Indicates the service data address | +| [id](#output\_id) | Specifies a resource ID in UUID format | +| [namesrv\_address](#output\_namesrv\_address) | Indicates the metadata address | +| [node\_num](#output\_node\_num) | Indicates the node quantity | +| [specification](#output\_specification) | Indicates the instance specification | +| [status](#output\_status) | Indicates the status of the DMS RocketMQ instance | +| [type](#output\_type) | Indicates the DMS RocketMQ instance type | + \ No newline at end of file diff --git a/examples/.placeholder b/examples/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/examples/one_broker/main.tf b/examples/one_broker/main.tf new file mode 100644 index 0000000..cebe6d0 --- /dev/null +++ b/examples/one_broker/main.tf @@ -0,0 +1,50 @@ +provider "huaweicloud" { + region = "ap-southeast-3" +} + +module "vpc" { + source = "cloud-labs-infra/vpc/huaweicloud" + version = "1.0.0" + + name = "dev01" +} + +module "secgroup_rocketmq" { + source = "cloud-labs-infra/security-group/huaweicloud" + version = "1.0.0" + + name = "dev01" + name_postfix = "postgres" + + rules = { + "Egress Allow All" = { + direction = "egress" + remote_ip_prefix = "0.0.0.0/0" + }, + "Ingress Allow to the VPC" = { + direction = "ingress" + remote_ip_prefix = module.vpc.vpc_cidr + }, + } +} + +module "rocketmq" { + source = "cloud-labs-infra/dms-rocketmq/huaweicloud" + version = "1.0.0" + + name = "dev01" + vpc_id = module.vpc.vpc_id + subnet_id = module.vpc.private_subnets_ids[0] + security_group_id = module.secgroup_rocketmq.id + + topics = { + TST1 = {} + TST2 = { + queue_num = 16 + total_read_queue_num = 6 + } + TST3 = { + brokers = ["broker-0"] + } + } +} diff --git a/examples/one_broker/versions.tf b/examples/one_broker/versions.tf new file mode 100644 index 0000000..af0509e --- /dev/null +++ b/examples/one_broker/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "~> 1.4" + + required_providers { + huaweicloud = { + source = "huaweicloud/huaweicloud" + version = "~>1.47" + } + } +} diff --git a/main.tf b/main.tf index e69de29..385342d 100644 --- a/main.tf +++ b/main.tf @@ -0,0 +1,65 @@ +data "huaweicloud_availability_zones" "zones" { + region = var.region +} + + +locals { + name = var.name_postfix == null ? format("%s-rocketmq", var.name) : format("%s-rocketmq-%s", var.name, var.name_postfix) + availability_zones = length(var.availability_zones) == 0 ? slice(data.huaweicloud_availability_zones.zones.names, 0, var.single_az ? 1 : 3) : var.availability_zones + +} + + +resource "huaweicloud_dms_rocketmq_instance" "main" { + name = local.name + description = var.description + region = var.region + engine_version = var.engine_version + storage_space = var.storage_space + vpc_id = var.vpc_id + subnet_id = var.subnet_id + security_group_id = var.security_group_id + availability_zones = local.availability_zones + flavor_id = var.flavor_id + storage_spec_code = var.storage_spec_code + ssl_enable = var.ssl_enable + ipv6_enable = var.ipv6_enable + enable_publicip = var.enable_publicip + broker_num = var.broker_num + enable_acl = var.enable_acl + + tags = var.tags +} + + +resource "huaweicloud_dms_rocketmq_topic" "main" { + for_each = var.topics + + instance_id = huaweicloud_dms_rocketmq_instance.main.id + name = each.key + region = var.region + queue_num = each.value.queue_num + permission = each.value.permission + total_write_queue_num = each.value.total_write_queue_num + total_read_queue_num = each.value.total_read_queue_num + + dynamic "brokers" { + for_each = each.value.brokers + content { + name = brokers.value + } + } +} + + +resource "huaweicloud_dms_rocketmq_consumer_group" "main" { + for_each = var.consumer_groups + + instance_id = huaweicloud_dms_rocketmq_instance.main.id + name = each.key + region = var.region + enabled = each.value.enabled + broadcast = each.value.broadcast + brokers = each.value.brokers + retry_max_times = each.value.retry_max_times +} diff --git a/outputs.tf b/outputs.tf index e69de29..47d0b08 100644 --- a/outputs.tf +++ b/outputs.tf @@ -0,0 +1,34 @@ +output "id" { + description = "Specifies a resource ID in UUID format" + value = huaweicloud_dms_rocketmq_instance.main.id +} + +output "status" { + description = "Indicates the status of the DMS RocketMQ instance" + value = huaweicloud_dms_rocketmq_instance.main.status +} + +output "type" { + description = "Indicates the DMS RocketMQ instance type" + value = huaweicloud_dms_rocketmq_instance.main.type +} + +output "specification" { + description = "Indicates the instance specification" + value = huaweicloud_dms_rocketmq_instance.main.specification +} + +output "node_num" { + description = "Indicates the node quantity" + value = huaweicloud_dms_rocketmq_instance.main.node_num +} + +output "broker_address" { + description = "Indicates the service data address" + value = huaweicloud_dms_rocketmq_instance.main.broker_address +} + +output "namesrv_address" { + description = "Indicates the metadata address" + value = huaweicloud_dms_rocketmq_instance.main.namesrv_address +} diff --git a/variables.tf b/variables.tf index e69de29..1e6d594 100644 --- a/variables.tf +++ b/variables.tf @@ -0,0 +1,185 @@ +variable "name" { + description = "Specifies the name of the DMS RocketMQ instance" + type = string + nullable = false +} + +variable "name_postfix" { + description = "Specifies the name postfix of the DMS RocketMQ instance" + type = string + default = null +} + +variable "description" { + description = "Specifies the description of the DMS RocketMQ instance" + 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 "vpc_id" { + description = "Specifies the ID of a VPC" + type = string + nullable = false +} + +variable "subnet_id" { + description = "Specifies the ID of a subnet" + type = string + nullable = false +} + +variable "security_group_id" { + description = "Specifies the ID of a security group" + type = string + nullable = false +} + +variable "engine_version" { + description = "Specifies the version of the RocketMQ engine" + type = string + default = "4.8.0" + validation { + condition = contains(["4.8.0"], var.engine_version) + error_message = "At the moment only '4.8.0' version is available." + } +} + +variable "storage_space" { + description = "Specifies the message storage capacity, Unit: GB" + type = number + default = 300 + validation { + condition = 300 <= var.storage_space && var.storage_space <= 3000 + error_message = "Value range: 300-3000." + } +} + +variable "single_az" { + description = <
queue_num = optional(number, 8)
permission = optional(string, "all")
total_read_queue_num = optional(number, null)
total_write_queue_num = optional(number, null)
brokers = optional(list(string), ["broker-0"])
}))