cloudstack-terraform-provider icon indicating copy to clipboard operation
cloudstack-terraform-provider copied to clipboard

**Error when creating private gateway**

Open lwsa-leonardosouza opened this issue 9 months ago • 5 comments

Error when creating private gateway

I tested the module for creating private gateways. When executing the creation action below, I receive the following error message:

CloudStack API error 431 (CSExceptionErrorCode: 4350): One of vlanId and associatedNetworkId must be specified

I tried creating the private gateway through the UI, and it worked successfully. Here's the code I used to create the resource:

Code for creating resources using project scope:

resource "cloudstack_vpc" "vpc" {
  name         = var.vpc_name
  display_text = "VPC created by the module"
  cidr         = var.vpc_cidr
  zone         = var.zone_id
  vpc_offering = var.vpc_offering
  project      = var.project != "" ? var.project : null
  network_domain = var.network_domain 
}

resource "cloudstack_network" "network" {
  name             = var.network_name
  display_text     = var.network_display_text
  network_offering = var.network_offering
  zone             = var.zone
  cidr             = var.cidr
  vpc_id           = var.vpc_id 
  network_domain   = var.network_domain != "" ? var.network_domain : null
  acl_id           = var.acl_id != null ? var.acl_id : null
  project          = var.project != "" ? var.project : null
}

resource "cloudstack_network_acl" "acl" {

  name        = var.acl_name
  vpc_id      = module.vpc.id
  description = var.vpc_desc
  project     = var.project
}


resource "cloudstack_private_gateway" "pvgateway" {
  gateway                   =  var.gateway
  ip_address               =  var.ip_address
  netmask                   =  var.netmask
  vlan                          =  var.vlan != "" ? var.vlan : null
  vpc_id                      =  module.vpc.id
  acl_id                       =  var.acl_id != "" ? var.acl_id : null
  physical_network_id = var.physical_network_id != "" ? var.physical_network_id : null
}

I`ve tried same example from repository, but didn't work:

resource "cloudstack_private_gateway" "default" {
  gateway    = "10.0.0.1"
  ip_address = "10.0.0.2"
  netmask    = "255.255.255.252"
  vlan       = "200"
  vpc_id     = "76f6e8dc-07e3-4971-b2a2-8831b0cc4cb4"
}

lwsa-leonardosouza avatar Apr 25 '25 08:04 lwsa-leonardosouza

Hello, @lwsa-leonardosouza

Do the credentials configured in your cloudstack provider belong to a Root Admin account?

If so, could you verify whether the var.vlan input variable is defined? Additionally, it would be interesting to check what value the Management Server is receiving for the vlan attribute in the createPrivateGateway API call.

resource "cloudstack_private_gateway" "pvgateway" {
  gateway                   =  var.gateway
  ip_address               =  var.ip_address
  netmask                   =  var.netmask
  vlan                          =  var.vlan != "" ? var.vlan : null
  vpc_id                      =  module.vpc.id
  acl_id                       =  var.acl_id != "" ? var.acl_id : null
  physical_network_id = var.physical_network_id != "" ? var.physical_network_id : null
}

As mentioned on the private gateway module documentation, it is only possible to create private gateways through Terraform using Root Admin credentials. This requirement exists because, currently, the Apache CloudStack provider only supports the vlan parameter; the associatednetworkid is not supported. Since non-root admins accounts do not have access to infrastructure details, the vlan parameter is not available for them.

We can create a new issue to support the associatednetworkid parameter. What do you guys think?


I`ve tried same example from repository, but didn't work:

This example seems to be missing the acl_id attribute. I executed it, with the credentials of a Root Admin account and with the acl_id defined, and it worked as expected. I'll open a PR to update the documentation example.

bernardodemarco avatar Apr 25 '25 14:04 bernardodemarco

@bernardodemarco Can you create a PR to update the documentation for this issue

kiranchavala avatar May 12 '25 10:05 kiranchavala

@kiranchavala, yes, I'll open it later today

bernardodemarco avatar May 12 '25 11:05 bernardodemarco

@kiranchavala, I've just opened the PR, see #180.

As for the following quote present in my first reply (see https://github.com/apache/cloudstack-terraform-provider/issues/172#issuecomment-2830583776):

We can create a new issue to support the associatednetworkid parameter. What do you guys think?

I noticed that we already have an issue mapped to address that, see #105.

bernardodemarco avatar May 12 '25 23:05 bernardodemarco

Thanks @bernardodemarco

kiranchavala avatar May 14 '25 11:05 kiranchavala

Closing the issue as #180 solves it

kiranchavala avatar Sep 16 '25 12:09 kiranchavala