Skip to content

Commit

Permalink
added module for creating a lan and firewall rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabat committed Jul 30, 2024
1 parent 5ed88c5 commit 1bea32a
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
40 changes: 40 additions & 0 deletions modules/ionos-lan-and-firewall/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- BEGIN_TF_DOCS -->

## Providers

| Name | Version |
|------|---------|
| <a name="provider_ionoscloud"></a> [ionoscloud](#provider\_ionoscloud) | 6.4.18 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_datacenter_id"></a> [datacenter_id](#input\_datacenter_id) | n/a | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | n/a | `string` | n/a | yes |
| <a name="input_server_id"></a> [server_id](#input\_server_ids) | n/a | `string` | n/a | yes |
| <a name="input_ports"></a> [ports](#input\_ports) | n/a | `list` | n/a | yes |
| <a name="input_is_public"></a> [is_public](#input\_is_public) | n/a | `bool` | n/a | yes |


## Outputs

| Name | Description |
|------|-------------|
| <a name="output_lan_id"></a> [lan_id](lan\_id) | n/a |
| <a name="output_nic_id"></a> [nic_id](nic\_id) | n/a |
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_ionoscloud"></a> [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 |

<!-- END_TF_DOCS -->
Empty file.
2 changes: 2 additions & 0 deletions modules/ionos-lan-and-firewall/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


30 changes: 30 additions & 0 deletions modules/ionos-lan-and-firewall/main.tf
Original file line number Diff line number Diff line change
@@ -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)
}

9 changes: 9 additions & 0 deletions modules/ionos-lan-and-firewall/output.tf
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions modules/ionos-lan-and-firewall/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions modules/ionos-lan-and-firewall/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
ionoscloud = {
source = "ionos-cloud/ionoscloud"
version = "6.4.18"
}
}
}

0 comments on commit 1bea32a

Please sign in to comment.