diff --git a/examples/dns/main.tf b/examples/dns/main.tf index e16fe23..19d078e 100644 --- a/examples/dns/main.tf +++ b/examples/dns/main.tf @@ -72,6 +72,7 @@ data "opentelekomcloud_vpc_subnet_v1" "subnet" { module "dns" { source = "../../modules/dns" + dns_zone_settings = local.local_dns_settings default_tags_set = var.default_tags_set } diff --git a/examples/vpc-peering/README.md b/examples/vpc-peering/README.md new file mode 100644 index 0000000..49dbd63 --- /dev/null +++ b/examples/vpc-peering/README.md @@ -0,0 +1,48 @@ +# VPC Peering + +Configuration in this directory creates a 2 Peering connections and one of them will be accepted in second project. +Second project aliased in `settings.tf` also you should know `project_ids` and `vpc_ids` of peered projects which put in `peering.auto.tfvars`. + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example will create resources which can cost money. Run `terraform destroy` when you don't need these resources. + +## Requirements + +| Name | Version | +| ---------------------------------------------------------------------------------------------- |-----------| +| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [opentelekomcloud](#requirement\_opentelekomcloud) | >= 1.23.9 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|-----------------------------------------------------------------------|------------------------------------------------------------------|---------| +| [vpc-peering](#module\_vpc-peering) | "opentelekomcloud/modules/opentelekomcloud//modules/vpc-peering" | 0.0.2 | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------------------------------------------------------------------------------------------------------------|----------------------------------| +| [peering\_connection\_ids](#output\_peering\_connection\_ids) | The Ids of created Zones | +| [peering\_accepter\_ids](#output\_peering\_accepter\_ids) | The Names of created Record sets | diff --git a/examples/vpc-peering/main.tf b/examples/vpc-peering/main.tf new file mode 100644 index 0000000..93b4cf4 --- /dev/null +++ b/examples/vpc-peering/main.tf @@ -0,0 +1,78 @@ +/*================================= +PEERING VARIABLES +==================================*/ +variable "requester_vpc_peering_settings" { + default = {} + description = "Map of peering properties" +} + +variable "accepter_vpc_peering_settings" { + default = {} + description = "Map of peering accepter properties" +} + +variable "main_vpc" { + default = "subnet-do-not-delete-pls" + description = "Subnet for Peering." +} +/*================================= +PEERING LOCALS +==================================*/ + +locals { + local_requester_vpc_peering_settings = { + "REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1" = { + peer_tenant_id = var.requester_vpc_peering_settings["REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1"]["peer_tenant_id"] # FIRST PROJECT + peer_vpc_id = var.requester_vpc_peering_settings["REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1"]["peer_vpc_id"] # VPC ID TO PEER FROM FIRST PROJECT + vpc_id = data.opentelekomcloud_vpc_subnet_v1.subnet.vpc_id + } + "REQUESTER_PROJECT_2_TO_ACCEPTER_PROJECT_2" = { + peer_tenant_id = var.requester_vpc_peering_settings["REQUESTER_PROJECT_2_TO_ACCEPTER_PROJECT_2"]["peer_tenant_id"] # SECOND PROJECT + peer_vpc_id = var.requester_vpc_peering_settings["REQUESTER_PROJECT_2_TO_ACCEPTER_PROJECT_2"]["peer_vpc_id"] # VPC ID TO PEER FROM SECOND PROJECT + vpc_id = data.opentelekomcloud_vpc_subnet_v1.subnet.vpc_id + } + } + requester_vpc_peering_settings = merge(var.requester_vpc_peering_settings, local.local_requester_vpc_peering_settings) +} +locals { + local_accepter_vpc_peering_settings = { + "ACCEPTER_PROJECT_1-WITH-REQUESTER_PROJECT_1" = { + peer_vpc_connection_id = module.peering-requester.peering_connections["REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1"].id + is_accept = true + } + } + accepter_vpc_peering_settings = merge(var.accepter_vpc_peering_settings, local.local_accepter_vpc_peering_settings) +} +/*================================= +PEERING MODULES +==================================*/ +data "opentelekomcloud_vpc_subnet_v1" "subnet" { + name = var.main_vpc +} + +module "peering-requester" { + source = "../../modules/vpc-peering" + + requester_vpc_peering_settings = local.requester_vpc_peering_settings +} + +module "peering-accepter" { + source = "../../modules/vpc-peering" + + accepter_vpc_peering_settings = local.accepter_vpc_peering_settings + + providers = { + opentelekomcloud = opentelekomcloud.second + } +} +/*================================= +PEERING OUTPUTS +==================================*/ + +output "peering_connection_ids" { + value = { for k, v in module.peering-requester.peering_connections : k => v.id } +} + +output "peering_accepter_ids" { + value = { for k, v in module.peering-accepter.peering_accepters : k => v.id } +} diff --git a/examples/vpc-peering/peering.auto.tfvars b/examples/vpc-peering/peering.auto.tfvars new file mode 100644 index 0000000..b831bc2 --- /dev/null +++ b/examples/vpc-peering/peering.auto.tfvars @@ -0,0 +1,23 @@ +/*================================= +PEERING PREPARED MAP +==================================*/ + +requester_vpc_peering_settings = { + "REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1" = { + peer_tenant_id = "5dd3c0b24cdc4d31952c49589182a80d" + peer_vpc_id = "a82d8c31-1f1b-4d55-bd45-e01ec3de417c" + vpc_id = "REWRITE_IN_LOCALS" + } + "REQUESTER_PROJECT_2_TO_ACCEPTER_PROJECT_2" = { + peer_tenant_id = "5dd3c0b24cdc4d31952c49589182a90d" + peer_vpc_id = "a82d8c31-t6nh-4d55-bd45-e01ec3de417c" + vpc_id = "REWRITE_IN_LOCALS" + } +} + +accepter_vpc_peering_settings = { + "ACCEPTER_PROJECT_1-WITH-REQUESTER_PROJECT_1" = { + peer_vpc_connection_id = "REWRITE_IN_LOCALS" + is_accept = true + } +} diff --git a/examples/vpc-peering/versions.tf b/examples/vpc-peering/versions.tf new file mode 100644 index 0000000..17ed1db --- /dev/null +++ b/examples/vpc-peering/versions.tf @@ -0,0 +1,19 @@ +terraform { + required_providers { + opentelekomcloud = { + source = "opentelekomcloud/opentelekomcloud" + version = ">=1.34.4" + } + } +} + +# Configure the OpenTelekomCloud Main Provider +provider "opentelekomcloud" { + cloud = "terraform" +} + +# Configure the OpenTelekomCloud Second Provider for another project +provider "opentelekomcloud" { + alias = "second" + cloud = "dmd" +} diff --git a/modules/vpc-peering/README.md b/modules/vpc-peering/README.md new file mode 100644 index 0000000..9ec946f --- /dev/null +++ b/modules/vpc-peering/README.md @@ -0,0 +1,125 @@ +# OpenTelekomCloud VPC Peering Terraform module + +![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/opentelekomcloud/terraform-opentelekomcloud-modules) +![Build (latest by date)](https://zuul.otc-service.com/api/tenant/eco/badge?project=opentelekomcloud/terraform-opentelekomcloud-modules&pipeline=check&branch=main) + +_This module aims to create a module to create and accept peering connection on OpenTelekomCloud provider._ + +_These types of resources are supported:_ + +* [Connection](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/vpc_peering_v2) +* [Accepter](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/vpc_peering_accepter_v2) + + +## Where to find module documentations + +You can find different documentations versioned by terraform registry [here](https://registry.terraform.io/modules/opentelekomcloud/modules/opentelekomcloud/latest). + +## Terraform versions + +Terraform 0.13 or higher. + +## Usage + +```hcl +requester_vpc_peering_settings = { + "REQUESTER_PROJECT_1_TO_ACCEPTER_PROJECT_1" = { + peer_tenant_id = "5dd3c0b24cdc4d31952c49589182a80d" + peer_vpc_id = "a82d8c31-1f1b-4d55-bd45-e01ec3de417c" + vpc_id = "a82d8c31-1f1b-8889-bd45-e01ec3de417c" + } + "REQUESTER_PROJECT_2_TO_ACCEPTER_PROJECT_2" = { + peer_tenant_id = "5dd3c0b24cdc4d31952c49589182a90d" + peer_vpc_id = "a82d8c31-t6nh-4d55-bd45-e01ec3de417c" + vpc_id = "a82d8c31-1f1b-8889-bd45-e01ec3de417c" + } +} + +accepter_vpc_peering_settings = { + "ACCEPTER_PROJECT_1-WITH-REQUESTER_PROJECT_1" = { + peer_vpc_connection_id = "3a9f8c14-a523-4736-beb6-b6275a52388a" + is_accept = true + } +} + +variable "requester_vpc_peering_settings" { + default = {} + description = "Map of peering properties" +} + +variable "accepter_vpc_peering_settings" { + default = {} + description = "Map of peering accepter properties" +} + +variable "main_vpc" { + default = "subnet-do-not-delete-pls" + description = "Subnet for Peering." +} + +module "peering" { + source = "../../modules/vpc-peering" + + requester_vpc_peering_settings = var.requester_vpc_peering_settings + accepter_vpc_peering_settings = var.accepter_vpc_peering_settings +} +``` + +## Examples + +* [DNS](https://github.com/opentelekomcloud/terraform-opentelekomcloud-modules/blob/main/examples/vpc-peering) + +## Requirements + +| Name | Version | +| ---------------------------------------------------------------------------------------------- |-----------| +| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [opentelekomcloud](#requirement\_opentelekomcloud) | >= 1.23.9 | + +## Modules + +No modules. + +## Resources + +| Name | Type | Count | +|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-----------| +| [opentelekomcloud_vpc_peering_connection_v2.peering-connection](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/vpc_peering_v2) | resource | 1 or more | +| [opentelekomcloud_vpc_peering_connection_accepter_v2.peering-connection-accepter](https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/resources/vpc_peering_accepter_v2) | resource | 1 or more | + +## Inputs + +| Name | Description | Type | Default | Required | +|------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|---------------|---------|:--------:| +| [requester\_vpc\_peering\_settings](#input\_requester\_vpc\_peering\_settings) | Map of peering settings. | `map(object)` | `{}` | no | +| [accepter\_vpc\_peering\_settings](#input\_accepter\_vpc\_peering\_settings) | Map of peering accepter settings. | `map(object)` | `{}` | no | + +### requester_vpc_peering_settings + +| Name | Description | Type | Default | Required | +|----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|----------|---------|:--------:| +| [peer\_tenant\_id](#input\_peer\_tenant\_id) | Specifies the ID of the project to which a VPC involved in the VPC peering connection belongs. | `string` | `null` | yes | +| [peer\_vpc\_id](#input\_peer\_vpc\_id) | Receiver VPC ID. | `string` | `null` | yes | +| [vpc\_id](#input\_vpc\_id) | Requester VPC ID. | `string` | `null` | yes | + +### accepter_vpc_peering_settings + +| Name | Description | Type | Default | Required | +|------------------------------------------------------------------------------------------------------------|------------------------------------------|----------|---------|:--------:| +| [peer\_vpc\_connection\_id](#input\_peer\_vpc\_connection\_id) | Specifies the VPC peering connection ID. | `string` | `null` | yes | +| [is\_accept](#input\_is\_accept) | Accept connection or not | `bool` | `null` | yes | + +## Outputs + +| Name | Description | +|-----------------------------------------------------------------------------------|---------------------------------| +| [zones](#output\_peering\_connections) | The all VPC Peering connections | +| [recordsets](#output\_peering\_accepters) | The all VPC Peering accepters | + +## Authors + +Module managed by [Anton Sidelnikov](https://github.com/anton-sidelnikov). + +## License + +Apache 2 Licensed. See LICENSE for full details. diff --git a/modules/vpc-peering/outputs.tf b/modules/vpc-peering/outputs.tf new file mode 100644 index 0000000..b0cbc44 --- /dev/null +++ b/modules/vpc-peering/outputs.tf @@ -0,0 +1,10 @@ +/*================================= +OUTPUTS +==================================*/ +output "peering_connections" { + value = opentelekomcloud_vpc_peering_connection_v2.peering-connection +} + +output "peering_accepters" { + value = opentelekomcloud_vpc_peering_connection_accepter_v2.peering-connection-accepter +} diff --git a/modules/vpc-peering/peering.tf b/modules/vpc-peering/peering.tf new file mode 100644 index 0000000..9bc77f9 --- /dev/null +++ b/modules/vpc-peering/peering.tf @@ -0,0 +1,16 @@ +/*================================= +RESOURCES +#==================================*/ +resource "opentelekomcloud_vpc_peering_connection_v2" "peering-connection" { + for_each = var.requester_vpc_peering_settings + name = each.key + peer_vpc_id = each.value["peer_vpc_id"] + vpc_id = each.value["vpc_id"] + peer_tenant_id = each.value["peer_tenant_id"] +} + +resource "opentelekomcloud_vpc_peering_connection_accepter_v2" "peering-connection-accepter" { + for_each = var.accepter_vpc_peering_settings + vpc_peering_connection_id = each.value["peer_vpc_connection_id"] + accept = each.value["is_accept"] +} diff --git a/modules/vpc-peering/variables.tf b/modules/vpc-peering/variables.tf new file mode 100644 index 0000000..4c2e440 --- /dev/null +++ b/modules/vpc-peering/variables.tf @@ -0,0 +1,47 @@ +/*================================= +VARIABLES +==================================*/ +variable "requester_vpc_peering_settings" { + default = { + /* Example variable value: + peering_name_1 = { + peer_tenant_id = "accepter_tenant_id_1" + peer_vpc_id = "accepter_vpc_id_1" + vpc_id = "requester_vpc_id_1" + } # Example value 1 + + peering_name_2 = { + peer_tenant_id = "accepter_tenant_id_2" + peer_vpc_id = "accepter_vpc_id_2" + vpc_id = "requester_vpc_id_2" + } # Example value 2 + */ + } + type = map(object({ + peer_tenant_id = string + peer_vpc_id = string + vpc_id = string + })) + description = "Map of peering settings (current values in top level vars file)" +} + +variable "accepter_vpc_peering_settings" { + default = { + /* Examples + peering_name_1 = { + peer_vpc_connection_id = "peer_vpc_connection_id_1" + is_accept = true + } # Example value 1 + + peering_name_2 = { + peer_vpc_connection_id = "peer_vpc_connection_id_2" + is_accept = true + } # Example value 2 + */ + } + type = map(object({ + peer_vpc_connection_id = string + is_accept = bool + })) + description = "Map of peering accepter settings (current values in top level vars file)" +} diff --git a/modules/vpc-peering/versions.tf b/modules/vpc-peering/versions.tf new file mode 100644 index 0000000..ff7929d --- /dev/null +++ b/modules/vpc-peering/versions.tf @@ -0,0 +1,11 @@ +/*================================= +PROVIDER SETTINGS +==================================*/ +terraform { + required_providers { + opentelekomcloud = { + source = "opentelekomcloud/opentelekomcloud" + version = ">=1.34.4" + } + } +}