Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: private network region_openstackId #197

Closed
rienafairefr opened this issue May 17, 2021 · 11 comments
Closed

Feature Request: private network region_openstackId #197

rienafairefr opened this issue May 17, 2021 · 11 comments
Labels

Comments

@rienafairefr
Copy link
Contributor

for private networks resources ovh_cloud_project_network_private, the openstackId of the network in a given region is given by the API, but not exposed by the terraform provider.

https://eu.api.ovh.com/console/#/cloud/project/%7BserviceName%7D/network/private#GET
regions is a list of objects, returning region_name/status/openstackId, and ovh_cloud_project_network_private.regions only gives the name of the region

@viktorgt
Copy link

Is any workaround available for terraform? I would like to create an ovh_cloud_project_kube resource with a private network, but it requires the openstackId of the network.

@rienafairefr
Copy link
Contributor Author

on the ovh_cloud_project_network_private there is a regions_attributes openstackid attribute available. So you can create the private_network with ovh_cloud_project_network_private, add a subnet with ovh_cloud_project_network_private_subnet, and it works.

resource "ovh_cloud_project_network_private" "network_prod" {
  service_name = var.ovh_project
  name         = "network-prod"

  vlan_id = 0
  regions = [var.ovh_region]
}

resource "ovh_cloud_project_network_private_subnet" "network_prod_subnet" {
  service_name = var.ovh_project
  network_id   = ovh_cloud_project_network_private.network_prod.id
  region       = var.ovh_region

  start      = "192.168.168.100"
  end        = "192.168.168.200"
  network    = "192.168.168.0/24"
  dhcp       = true
  no_gateway = true
}

resource "ovh_cloud_project_kube" "cluster-prod" {
  service_name       = var.ovh_project
  name               = "kube-cluster-prod"
  region             = var.ovh_region
  version            = "1.20"
  private_network_id = ovh_cloud_project_network_private.network_prod.regions_attributes.0.openstackid
}

@eirikbell
Copy link

eirikbell commented Oct 7, 2021

In which version of the provider is the workaround available?

From code in https://github.com/ovh/terraform-provider-ovh/blob/master/ovh/resource_cloud_project_network_private.go it seems it is no longer included in schema. and from https://github.com/ovh/terraform-provider-ovh/blob/master/ovh/types_cloud.go its clear that openstackId is not unmarshalled from the response from api:

type CloudProjectNetworkPrivateResponse struct {
	Id      string                              `json:"id"`
	Status  string                              `json:"status"`
	Vlanid  int                                 `json:"vlanId"`
	Name    string                              `json:"name"`
	Type    string                              `json:"type"`
	Regions []*CloudProjectNetworkPrivateRegion `json:"regions"`
}

type CloudProjectNetworkPrivateRegion struct {
	Status string `json:"status"`
	Region string `json:"region"`
}

Adding a OpenStackId string `json:"openstackId"` property to CloudProjectNetworkPrivateRegion and map it to a new schema element in func resourceCloudProjectNetworkPrivateRead in https://github.com/ovh/terraform-provider-ovh/blob/master/ovh/resource_cloud_project_network_private.go should do the trick.

Meanwhile, does anyone know of a workaround, is there perhaps a way to use openstack provider to do the private network creation?

@vepito
Copy link

vepito commented May 31, 2022

on the ovh_cloud_project_network_private there is a regions_attributes openstackid attribute available. So you can create the private_network with ovh_cloud_project_network_private, add a subnet with ovh_cloud_project_network_private_subnet, and it works.


resource "ovh_cloud_project_kube" "cluster-prod" {
  service_name       = var.ovh_project
  name               = "kube-cluster-prod"
  region             = var.ovh_region
  version            = "1.20"
  private_network_id = ovh_cloud_project_network_private.network_prod.regions_attributes.0.openstackid
}

This works fine with a single region, the id '0' matches your region.
I don't see how to do the same when several regions are used. Each region has its own attribute number (which I don't know) and openstackid

@rienafairefr
Copy link
Contributor Author

This works fine with a single region, the id '0' matches your region. I don't see how to do the same when several regions are used. Each region has its own attribute number (which I don't know) and openstackid

That'd be trickier, but achievable with latest terraform capabilities (for loop, with an if to find the correct element in the list where region=the value you want) AFAIK. Or, alternatively, loop over the regions_attributes attribute:
! untested:

resource "ovh_cloud_project_kube" "cluster-prod" {
  count = length(ovh_cloud_project_network_private.network_prod.regions_attributes)

  service_name       = var.ovh_project
  name               = "kube-cluster-prod"
  region             = var.ovh_region
  version            = "1.20"
  private_network_id = ovh_cloud_project_network_private.network_prod.regions_attributes[count.index].openstackid
}

Would be easier to read with a local region->openstackid map and a for_each.

@albundy83
Copy link

Here a good workaround:
private_network_id = tolist(ovh_cloud_project_network_private.network_prod.regions_attributes)[index(ovh_cloud_project_network_private.network_prod.regions_attributes.*.region, var.ovh_region)].openstackid

I have found the base here:

private_network_id = xxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx #ovh_cloud_project_network_private.network1.regions_attributes[index(ovh_cloud_project_network_private.network1.regions_attributes.*.region, "GRA7")].openstackid

But when I try (terraform v1.2.9 and OVH provider v0.21.0) I have this error:

Error: Invalid index
│
│   on kubernetes.tf line 15, in resource "ovh_cloud_project_kube" "mykube":
│   15:    private_network_id = ovh_cloud_project_network_private.network_prod.regions_attributes[index(ovh_cloud_project_network_private.network_prod.regions_attributes.*.region, var.ovh_region)].openstackid
│     ├────────────────
│     │ ovh_cloud_project_network_private.network_prod.regions_attributes is set of object with 1 element
│
│ Elements of a set are identified only by their value and don't have any separate index or key to select with, so it's only possible to perform operations across all elements of the set.

To fix it, I add the function tolist

@scraly
Copy link
Collaborator

scraly commented Sep 21, 2022

If you want to select the first element you can also use the one(...) method like this:

  private_network_id = one(ovh_cloud_project_network_private.network.regions_attributes[*].openstackid)

@scraly
Copy link
Collaborator

scraly commented Sep 21, 2022

Ot you can simply use tolist() function and the first index:

	private_network_id = tolist(ovh_cloud_project_network_private.network.regions_attributes[*].openstackid)[0]

@albundy83
Copy link

Nice, maybe we could update doc with your tips ?

@scraly
Copy link
Collaborator

scraly commented Sep 23, 2022

Yes, I added the tip and also several examples in the documentation.
It will be released in the v0.22.0 :-).

@amstuta
Copy link
Contributor

amstuta commented Mar 20, 2024

Seems the issue is fixed by the doc update, closing it.

@amstuta amstuta closed this as completed Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants