Skip to content

Commit 66f6d9b

Browse files
stonejtopjian
authored andcommitted
Support for availability_zone_hints for networks (terraform-provider-openstack#196)
* vendor: Updating Gophercloud * Support for availability_zone_hints for networks This allows users to associate an availability zone with their resources so that the resources get high availability. * Add error check for availability_zone_hints List * Change availability_zone_hints to type TypeList Based on some code digging and some empirical tests the availability_zone_hints is a List. The documentation here is not crystal clear. Ref: https://github.com/openstack/neutron/blob/4a128494ae4d7d9d0223dad136e858b7ead83122/neutron/objects/network.py#L190 https://git.openstack.org/cgit/openstack/oslo.versionedobjects/tree/oslo_versionedobjects/fields.py#n1117 https://git.openstack.org/cgit/openstack/oslo.versionedobjects/tree/oslo_versionedobjects/fields.py#n634 * Fix resource to use TypeList. * Remove Set when changed to TypeList. Also fixed error check to use short version.
1 parent 9c0236f commit 66f6d9b

7 files changed

Lines changed: 149 additions & 47 deletions

File tree

‎openstack/data_source_openstack_networking_network_v2.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func dataSourceNetworkingNetworkV2() *schema.Resource {
5656
Type: schema.TypeString,
5757
Computed: true,
5858
},
59+
"availability_zone_hints": &schema.Schema{
60+
Type: schema.TypeList,
61+
Computed: true,
62+
Elem: &schema.Schema{Type: schema.TypeString},
63+
},
5964
},
6065
}
6166
}
@@ -116,6 +121,10 @@ func dataSourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{})
116121

117122
network := refinedNetworks[0]
118123

124+
if err = d.Set("availability_zone_hints", network.AvailabilityZoneHints); err != nil {
125+
log.Printf("[DEBUG] Unable to set availability_zone_hints: %s", err)
126+
}
127+
119128
log.Printf("[DEBUG] Retrieved Network %s: %+v", network.ID, network)
120129
d.SetId(network.ID)
121130

‎openstack/resource_openstack_networking_network_v2.go‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func resourceNetworkingNetworkV2() *schema.Resource {
8888
Optional: true,
8989
ForceNew: true,
9090
},
91+
"availability_zone_hints": &schema.Schema{
92+
Type: schema.TypeList,
93+
Computed: true,
94+
ForceNew: true,
95+
Optional: true,
96+
Elem: &schema.Schema{Type: schema.TypeString},
97+
},
9198
},
9299
}
93100
}
@@ -101,8 +108,9 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
101108

102109
createOpts := NetworkCreateOpts{
103110
networks.CreateOpts{
104-
Name: d.Get("name").(string),
105-
TenantID: d.Get("tenant_id").(string),
111+
Name: d.Get("name").(string),
112+
TenantID: d.Get("tenant_id").(string),
113+
AvailabilityZoneHints: resourceNetworkingNetworkAvailabilityZoneHintsV2(d),
106114
},
107115
MapValueSpecs(d),
108116
}
@@ -184,6 +192,10 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e
184192
d.Set("tenant_id", n.TenantID)
185193
d.Set("region", GetRegion(d, config))
186194

195+
if err := d.Set("availability_zone_hints", n.AvailabilityZoneHints); err != nil {
196+
log.Printf("[DEBUG] unable to set availability_zone_hints: %s", err)
197+
}
198+
187199
return nil
188200
}
189201

@@ -277,6 +289,15 @@ func resourceNetworkingNetworkV2Segments(d *schema.ResourceData) (providerSegmen
277289
return
278290
}
279291

292+
func resourceNetworkingNetworkAvailabilityZoneHintsV2(d *schema.ResourceData) []string {
293+
rawAZH := d.Get("availability_zone_hints").([]interface{})
294+
azh := make([]string, len(rawAZH))
295+
for i, raw := range rawAZH {
296+
azh[i] = raw.(string)
297+
}
298+
return azh
299+
}
300+
280301
func waitForNetworkActive(networkingClient *gophercloud.ServiceClient, networkId string) resource.StateRefreshFunc {
281302
return func() (interface{}, string, error) {
282303
n, err := networks.Get(networkingClient, networkId).Extract()

‎vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/doc.go‎

Lines changed: 64 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/requests.go‎

Lines changed: 15 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/networks/results.go‎

Lines changed: 31 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/vendor.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,10 @@
535535
"revisionTime": "2017-05-24T13:09:59Z"
536536
},
537537
{
538-
"checksumSHA1": "zKOhFTL5BDZPMC58ZzZkryjskno=",
538+
"checksumSHA1": "YnP/P8Tr8hHw+NVZ/KegcGCbK0I=",
539539
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/networks",
540-
"revision": "0f64da0e36de86a0ca1a8f2fc1b0570a0d3f7504",
541-
"revisionTime": "2017-03-10T01:59:53Z"
540+
"revision": "4d2733c962898d8cd68456bd275aee64256cd2a1",
541+
"revisionTime": "2017-12-08T16:30:52Z"
542542
},
543543
{
544544
"checksumSHA1": "68RL/R3cHJvkHPNZmu0GW4xd4cY=",

‎website/docs/d/networking_network_v2.html.markdown‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ data "openstack_networking_network_v2" "network" {
3434

3535
* `tenant_id` - (Optional) The owner of the network.
3636

37+
* `availability_zone_hints` - (Optional) The availability zone candidates for the network.
38+
39+
3740
## Attributes Reference
3841

3942
`id` is set to the ID of the found network. In addition, the following attributes
@@ -44,3 +47,4 @@ are exported:
4447
* `region` - See Argument Reference above.
4548
* `shared` - (Optional) Specifies whether the network resource can be accessed
4649
by any tenant or not.
50+
* `availability_zone_hints` - (Optional) The availability zone candidates for the network.

0 commit comments

Comments
 (0)