diff --git a/modules/ionos-lan-and-firewall/README.md b/modules/ionos-lan-and-firewall/README.md new file mode 100644 index 0000000..576a427 --- /dev/null +++ b/modules/ionos-lan-and-firewall/README.md @@ -0,0 +1,40 @@ + + +## Providers + +| Name | Version | +|------|---------| +| [ionoscloud](#provider\_ionoscloud) | 6.4.18 | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [datacenter_id](#input\_datacenter_id) | n/a | `string` | n/a | yes | +| [name](#input\_name) | n/a | `string` | n/a | yes | +| [server_id](#input\_server_ids) | n/a | `string` | n/a | yes | +| [ports](#input\_ports) | n/a | `list` | n/a | yes | +| [is_public](#input\_is_public) | n/a | `bool` | n/a | yes | + + +## Outputs + +| Name | Description | +|------|-------------| +| [lan_id](lan\_id) | n/a | +| [nic_id](nic\_id) | n/a | +## Requirements + +| Name | Version | +|------|---------| +| [ionoscloud](#requirement\_ionoscloud) | 6.4.18 | +## Resources + +| Name | Type | +|------|------| +| [ionoscloud_firewall.range_rule](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/firewall) | resource | +| [ionoscloud_firewall.rule](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/firewall) | resource | +| [ionoscloud_ipblock.public_ip](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/ipblock) | resource | +| [ionoscloud_lan.basic_vm_server_lan](https://registry.terraform.io/providers/ionos-cloud/ionoscloud/6.4.18/docs/resources/lan) | resource | + + \ No newline at end of file diff --git a/modules/ionos-lan-and-firewall/data.tf b/modules/ionos-lan-and-firewall/data.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/ionos-lan-and-firewall/locals.tf b/modules/ionos-lan-and-firewall/locals.tf new file mode 100644 index 0000000..139597f --- /dev/null +++ b/modules/ionos-lan-and-firewall/locals.tf @@ -0,0 +1,2 @@ + + diff --git a/modules/ionos-lan-and-firewall/main.tf b/modules/ionos-lan-and-firewall/main.tf new file mode 100644 index 0000000..1b1c1e4 --- /dev/null +++ b/modules/ionos-lan-and-firewall/main.tf @@ -0,0 +1,30 @@ +# Create a LAN ( private or public ) + resource "ionoscloud_lan" "lan" { + datacenter_id = var.datacenter_id + public = var.is_public + name = format( "%s-%s",var.name,"intern-connection-lan") + } + +# Create a NIC for the basic VM and connect it to the LAN +resource "ionoscloud_nic" "nic" { + datacenter_id = var.datacenter_id + server_id = var.server_id + dhcp = true + lan = ionoscloud_lan.lan.id + firewall_active = true + +} + +# Add The Ports The VM +resource "ionoscloud_firewall" "rule" { + count = length(var.ports) + datacenter_id = var.datacenter_id + server_id = var.server_id + nic_id = ionoscloud_nic.nic.id + protocol = var.ports[count.index]["protocol"] + name = var.ports[count.index]["name"] + port_range_start = var.ports[count.index]["port"] + port_range_end = var.ports[count.index]["port"] + source_ip = lookup(var.ports[count.index], "source_ip", null) +} + diff --git a/modules/ionos-lan-and-firewall/output.tf b/modules/ionos-lan-and-firewall/output.tf new file mode 100644 index 0000000..f0b12c3 --- /dev/null +++ b/modules/ionos-lan-and-firewall/output.tf @@ -0,0 +1,9 @@ +output "lan_id" { + description = "The id of the lan created" + value = ionoscloud_lan.lan.id +} + +output "nic_id" { + description = "The id of the nic created" + value = ionoscloud_nic.nic.id +} diff --git a/modules/ionos-lan-and-firewall/variables.tf b/modules/ionos-lan-and-firewall/variables.tf new file mode 100644 index 0000000..8b886ca --- /dev/null +++ b/modules/ionos-lan-and-firewall/variables.tf @@ -0,0 +1,25 @@ +variable "datacenter_id" { + description = "The Datacenter id" + type = string +} + +variable "name" { + description = "The name given for the module" + type = string +} + +variable "server_id" { + description = "The Server id for the lan" + type = string +} + +variable "ports" { + description = "List of Ports toprovided to rule" + type = list +} + +variable "is_public" { + description = "The Type of lan is public (true) or private (false)" + type = bool + default = false +} \ No newline at end of file diff --git a/modules/ionos-lan-and-firewall/versions.tf b/modules/ionos-lan-and-firewall/versions.tf new file mode 100644 index 0000000..b247aca --- /dev/null +++ b/modules/ionos-lan-and-firewall/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + ionoscloud = { + source = "ionos-cloud/ionoscloud" + version = "6.4.18" + } + } +}