scaleway / terraform-provider-scaleway

Terraform Scaleway provider
https://www.terraform.io/docs/providers/scaleway/
Mozilla Public License 2.0
199 stars 125 forks source link

private_ip is null for scaleway_instance_server resource #2772

Open gmalfray opened 1 month ago

gmalfray commented 1 month ago

Terraform Version

Terraform v1.9.7

Affected Resource(s)

Terraform Configuration Files

resource "scaleway_instance_server" "proxy" {
  type       = "DEV1-S"
  project_id = var.project_id
  count      = var.nbproxy
  name       = "${var.basename_proxy}${count.index + 1}${var.domain}"
  image      = "debian_bookworm"
  zone       = "fr-par-2"
  user_data = {
    cloud-init = data.template_file.userdataproxy.rendered
  }
  private_network {
    pn_id = data.scaleway_vpc_private_network.pvn-pra-plop.private_network_id
  }
}

Debug Output

"private_ip" = tostring(null)
"private_network" = tolist([
  {
    "mac_address" = "02:00:00:2f:c8:4f"
    "pn_id" = "fr-par/c079e90b-4b31-4e1a-9af7-7f6bcbb1d5fd"
    "pnic_id" = "bc2f70f6-68ac-498e-b6f8-f1dec36f62db"
    "status" = "available"
    "zone" = "fr-par"
  },
])

Expected Behavior

The private_ip field should return the private IP address of the instance once it is connected to the specified private network

Actual Behavior

The private_ip field is null in the output, even though the instance is successfully created and attached to the private network.

Steps to Reproduce

Define a scaleway_instance_server resource with a private network. Run terraform apply. Observe that the private_ip field in the output is null.

Additional Context

The Scaleway instance is being created in the fr-par-2 zone. The issue occurs even though the instance is correctly attached to the private network, as indicated by the network. A private IP address is indeed assigned to the resource.

References

No response

gmalfray commented 1 month ago

I'm replying to myself: private_ip is deprecated (https://www.scaleway.com/en/developers/api/instance/#path-instances-list-all-instances-query-privateip). The solution is to create the resource scaleway_instance_private_nic and then load data "scaleway_ipam_ip".

resource "scaleway_instance_server" "proxy" {
  type       = "DEV1-S"
  project_id = var.project_id
  count      = var.nbproxy
  name       = "${var.basename_proxy}${count.index + 1}.${var.domain}"
  image      = var.image
  zone       = "fr-par-2"
  user_data = {
    cloud-init = data.template_file.userdataproxy.rendered
  }
}
resource "scaleway_instance_private_nic" "proxy" {
  count              = var.nbproxy
  server_id          = scaleway_instance_server.proxy[count.index].id
  private_network_id = data.scaleway_vpc_private_network.pvn-pra-gdest.private_network_id
}
data "scaleway_ipam_ip" "by_id_proxy" {
  count = var.nbproxy
  resource {
    id   = scaleway_instance_private_nic.proxy[count.index].id
    type = "instance_private_nic"
  }
  type = "ipv4"
}
resource "scaleway_domain_record" "proxy" {
  count    = var.nbproxy
  dns_zone = var.domain
  name     = "${var.basename_proxy}${count.index + 1}"
  type     = "A"
  data     = data.scaleway_ipam_ip.by_id_proxy[count.index].address
  ttl      = 3600
}
Simbud-7 commented 1 day ago

Thanks for the feedback, I have the same issue but didn't see the deprecation here: https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/data-sources/instance_server#private_ip-2 Indeed, it's indicated in the API spec