Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ module "my_instance" {
| <a name="input_additional_volume_ids"></a> [additional_volume_ids](#input_additional_volume_ids) | Additional volumes attached to the server. Updates to this field will trigger a stop/start of the server. | `list(string)` | `[]` | no |
| <a name="input_boot_type"></a> [boot_type](#input_boot_type) | The boot Type of the server. Default to 'local'. Possible values are: 'local', 'bootscript' or 'rescue'. | `string` | `"local"` | no |
| <a name="input_bootscript_id"></a> [bootscript_id](#input_bootscript_id) | ID of the bootscript to use (set boot_type to bootscript). | `string` | `null` | no |
| <a name="input_dns_zone"></a> [dns_zone](#input_dns_zone) | Domain name of the instance. If set, instance IPs will be registered in the matching DNS zone. | `string` | `null` | no |
| <a name="input_domainname"></a> [domainname](#input_domainname) | Domain name of the instance. If set, instance IPs will be registered in the matching DNS zone. | `string` | `null` | no |
| <a name="input_enable_ipv6"></a> [enable_ipv6](#input_enable_ipv6) | Determines if IPv6 is enabled for the server. | `bool` | `false` | no |
| <a name="input_enable_public_ipv4"></a> [enable_public_ipv4](#input_enable_public_ipv4) | Determines if a public IPv4 will be attached to the server. | `bool` | `false` | no |
| <a name="input_hostname"></a> [hostname](#input_hostname) | Name of the instance. If not set, it will be randomly generated by Scaleway. | `string` | `null` | no |
| <a name="input_instance_type"></a> [instance_type](#input_instance_type) | Commercial type of the server. Default to 'DEV1-S'. Updates to this field will recreate a new resource. | `string` | `"DEV1-S"` | no |
| <a name="input_name"></a> [name](#input_name) | Name of the instance. If not set, it will be randomly generated by Scaleway. | `string` | `null` | no |
| <a name="input_placement_group_id"></a> [placement_group_id](#input_placement_group_id) | ID of the placement group the server is attached to. | `string` | `null` | no |
| <a name="input_private_networks"></a> [private_networks](#input_private_networks) | Private networks associated with the server. | `list(string)` | `[]` | no |
| <a name="input_project_id"></a> [project_id](#input_project_id) | ID of the project the namespace is associated with. Ressource will be created in the project set at the provider level if null. | `string` | `null` | no |
Expand Down
16 changes: 8 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ moved {
}

locals {
requested_fqdn = (var.name != null && var.dns_zone != null) ? format("%s.%s", var.name, var.dns_zone) : var.name
effective_hostname = var.dns_zone != null ? trimsuffix(trimsuffix(scaleway_instance_server.this.name, var.dns_zone), ".") : scaleway_instance_server.this.name
effective_fqdn = var.dns_zone != null ? format("%s.%s", local.effective_hostname, var.dns_zone) : local.effective_hostname
requested_fqdn = (var.hostname != null && var.domainname != null) ? format("%s.%s", var.hostname, var.domainname) : var.hostname
effective_hostname = var.domainname != null ? trimsuffix(trimsuffix(scaleway_instance_server.this.name, var.domainname), ".") : scaleway_instance_server.this.name
effective_fqdn = var.domainname != null ? format("%s.%s", local.effective_hostname, var.domainname) : local.effective_hostname
}

resource "scaleway_instance_ip" "this" {
Expand All @@ -17,7 +17,7 @@ resource "scaleway_instance_ip" "this" {
}

resource "scaleway_instance_ip_reverse_dns" "this" {
count = var.enable_public_ipv4 && (var.dns_zone != null) ? 1 : 0
count = var.enable_public_ipv4 && (var.domainname != null) ? 1 : 0

ip_id = scaleway_instance_ip.this[count.index].id
reverse = local.effective_fqdn
Expand Down Expand Up @@ -61,19 +61,19 @@ resource "scaleway_instance_server" "this" {
}

resource "scaleway_domain_record" "ip4" {
count = var.dns_zone != null ? 1 : 0
count = var.domainname != null ? 1 : 0

data = var.enable_public_ipv4 ? scaleway_instance_server.this.public_ip : scaleway_instance_server.this.private_ip
dns_zone = var.dns_zone
dns_zone = var.domainname
name = local.effective_hostname
type = "A"
}

resource "scaleway_domain_record" "ip6" {
count = var.dns_zone != null && var.enable_ipv6 && var.state != "stopped" ? 1 : 0
count = var.domainname != null && var.enable_ipv6 && var.state != "stopped" ? 1 : 0

data = scaleway_instance_server.this.ipv6_address
dns_zone = var.dns_zone
dns_zone = var.domainname
name = local.effective_hostname
type = "AAAA"
}
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ variable "instance_type" {
}

# Instance settings
variable "name" {
variable "hostname" {
type = string
description = "Name of the instance. If not set, it will be randomly generated by Scaleway."
default = null
}

variable "dns_zone" {
variable "domainname" {
type = string
description = "Domain name of the instance. If set, instance IPs will be registered in the matching DNS zone."
default = null
Expand Down