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

regions_attributes of ovh_cloud_project_network_private does not contain all regions #281

Closed
fl42 opened this issue Aug 4, 2022 · 3 comments

Comments

@fl42
Copy link

fl42 commented Aug 4, 2022

Hello,

Terraform Version

Terraform v1.2.6
on linux_amd64
+ provider registry.terraform.io/ovh/ovh v0.19.1

Affected Resource(s)

  • ovh_cloud_project_network_private

Terraform Configuration Files

resource "ovh_cloud_project_network_private" "vnet" {
   service_name = var.service_name
   name         = "test"
   vlan_id      = 2
   regions      = ["GRA7", "SBG5"]
}

resource "ovh_cloud_project_network_private_subnet" "vnet_subnet_gra" {
   service_name = var.service_name
   network_id   = ovh_cloud_project_network_private.vnet.id
   region       = "GRA7"
   start        = "10.0.0.2"
   end          = "10.0.0.100"
   network      = "10.0.0.0/24"
   dhcp         = false
   no_gateway   = false
}

resource "ovh_cloud_project_network_private_subnet" "vnet_subnet_sbg" {
   service_name = var.service_name
   network_id   = ovh_cloud_project_network_private.vnet.id
   region       = "SBG5"
   start        = "10.0.1.2"
   end          = "10.0.1.100"
   network      = "10.0.1.0/24"
   dhcp         = false
   no_gateway   = false
}
output "regions_attributes" {
  value = ovh_cloud_project_network_private.vnet.regions_attributes
}

Debug Output

ovh_cloud_project_network_private.vnet: Refreshing state... [id=pn-xxx]
2022-08-04T09:43:08.632+0200 [INFO]  provider.terraform-provider-ovh_v0.19.1: 2022/08/04 09:43:08 [DEBUG] Will read public cloud private network for project: xxx, id: pn-xxx: timestamp=2022-08-04T09:43:08.632+0200
2022-08-04T09:43:08.632+0200 [INFO]  provider.terraform-provider-ovh_v0.19.1: 2022/08/04 09:43:08 [DEBUG] OVH API Request Details:
---[ REQUEST ]---------------------------------------
GET /1.0/cloud/project/xxx/network/private/pn-xxx HTTP/1.1
[...]


-----------------------------------------------------: timestamp=2022-08-04T09:43:08.632+0200
2022-08-04T09:43:10.499+0200 [INFO]  provider.terraform-provider-ovh_v0.19.1: 2022/08/04 09:43:10 [DEBUG] OVH API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 200 OK
[...]

10f
{
 "id": "pn-xxx",
 "name": "xxx",
 "vlanId": 2,
 "regions": [
  {
   "region": "SBG5",
   "status": "ACTIVE",
   "openstackId": "xxx"
  },
  {
   "region": "GRA7",
   "status": "ACTIVE",
   "openstackId": "xxx"
  }
 ],
 "type": "private",
 "status": "ACTIVE"
}
0


-----------------------------------------------------: timestamp=2022-08-04T09:43:10.498+0200
2022-08-04T09:43:10.499+0200 [INFO]  provider.terraform-provider-ovh_v0.19.1: 2022/08/04 09:43:10 [DEBUG] Read Public Cloud Private Network Id: pn-xxx, Status: ACTIVE, Name: xxx, Vlanid: 2, Type: private, Regions: [Status:ACTIVE, Region: SBG5 Status:ACTIVE, Region: GRA7]: timestamp=2022-08-04T09:43:10.499+0200
2022-08-04T09:43:10.500+0200 [WARN]  Provider "registry.terraform.io/ovh/ovh" produced an unexpected new value for ovh_cloud_project_network_private.vnet during refresh.
      - .regions_status: planned set element cty.ObjectVal(map[string]cty.Value{"region":cty.StringVal("GRA7"), "status":cty.StringVal("ACTIVE")}) does not correlate with any element in actual
      - .regions_attributes: planned set element cty.ObjectVal(map[string]cty.Value{"openstackid":cty.StringVal("xxx"), "region":cty.StringVal("GRA7"), "status":cty.StringVal("ACTIVE")}) does not correlate with any element in actual
2022-08-04T09:43:10.502+0200 [INFO]  ReferenceTransformer: reference not found: "var.service_name"
2022-08-04T09:43:10.502+0200 [DEBUG] ReferenceTransformer: "ovh_cloud_project_network_private_subnet.vnet_subnet_gra" references: []
2022-08-04T09:43:10.502+0200 [INFO]  ReferenceTransformer: reference not found: "var.service_name"
2022-08-04T09:43:10.502+0200 [DEBUG] ReferenceTransformer: "ovh_cloud_project_network_private_subnet.vnet_subnet_sbg" references: []

The OVH API returns the expected result (all regions).
The root cause may be related to this part:

2022-08-04T09:43:10.500+0200 [WARN]  Provider "registry.terraform.io/ovh/ovh" produced an unexpected new value for ovh_cloud_project_network_private.vnet during refresh.
      - .regions_status: planned set element cty.ObjectVal(map[string]cty.Value{"region":cty.StringVal("GRA7"), "status":cty.StringVal("ACTIVE")}) does not correlate with any element in actual
      - .regions_attributes: planned set element cty.ObjectVal(map[string]cty.Value{"openstackid":cty.StringVal("xxx"), "region":cty.StringVal("GRA7"), "status":cty.StringVal("ACTIVE")}) does not correlate with any element in actual

Expected Behavior

regions_attributes should contain all regions defined in regions key

Actual Behavior

regions_attributes contains only one region (not always the same)

Outputs:

regions_attributes = toset([
  {
    "openstackid" = "xxx"
    "region" = "SBG5"
    "status" = "ACTIVE"
  },
])

Steps to Reproduce

  1. terraform apply

References

Could be related to #254

@jbpin
Copy link

jbpin commented Aug 8, 2022

I confirm I've the same behaviour here. The result always have 1 item and it's not always the same.

@MircoT
Copy link
Contributor

MircoT commented Aug 10, 2022

I had the same problem. I wrote a workaround, but I'm still investigating.

TL;DR

The main problem is that the region_attributes is a TypeSet without a hashing function.

In fact, if you change the type to TypeList there is no problem and the regions are filled correctly. Also, I tested the current type (TypeSet) adding a custom hashing function:

"regions_attributes": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"status": {
				Type:     schema.TypeString,
				Required: true,
			},

			"region": {
				Type:     schema.TypeString,
				Computed: true,
			},

			"openstackid": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
	Set: helpers.HashMapRegionAttributes,

The hashing function is the following:

func HashMapRegionAttributes(v interface{}) int {
	curMap := v.(map[string]interface{})
	builder := strings.Builder{}

	for _, key := range []string{"status", "region", "openstackid"} {
		curString := curMap[key]
		builder.WriteString(curString.(string))
	}

	return schema.HashString(builder.String())
}

With this custom hashing function, the problem doesn't occur anymore.

Probably, tomorrow I'll make a PR to update this thing. For the moment, I hope that these details are helpful.

PS: the problem is the same with the deprecated field regions_status...

@yomovh
Copy link
Contributor

yomovh commented Jan 26, 2023

fixed in 0.20 => closing

@yomovh yomovh closed this as completed Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants