Skip to content

Commit afc822e

Browse files
authored
Merge pull request #513 from vmware/fix-update-network-ip-range
Fix updating network ip ranges
2 parents acf74cf + 5d2e62e commit afc822e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: vra/resource_network_ip_range.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func resourceNetworkIPRange() *schema.Resource {
100100
}
101101

102102
func resourceNetworkIPRangeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
103-
log.Printf("Starting to create vra_network_profile resource")
103+
log.Printf("Starting to create vra_network_ip_range resource")
104104
apiClient := m.(*Client).apiClient
105105

106106
name := d.Get("name").(string)
@@ -129,7 +129,7 @@ func resourceNetworkIPRangeCreate(ctx context.Context, d *schema.ResourceData, m
129129
networkIPRangeSpecification.Description = v.(string)
130130
}
131131

132-
log.Printf("[DEBUG] create network ip rangee: %#v", networkIPRangeSpecification)
132+
log.Printf("[DEBUG] Creating vra_network_ip_range with specification: %#v", networkIPRangeSpecification)
133133

134134
createNetworkIPRangeCreated, err := apiClient.NetworkIPRange.CreateInternalNetworkIPRange(network_ip_range.NewCreateInternalNetworkIPRangeParams().WithBody(&networkIPRangeSpecification))
135135
if err != nil {
@@ -144,7 +144,7 @@ func resourceNetworkIPRangeCreate(ctx context.Context, d *schema.ResourceData, m
144144
}
145145

146146
func resourceNetworkIPRangeRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
147-
log.Printf("Reading the vra_network_profile resource with name %s", d.Get("name"))
147+
log.Printf("Reading the vra_network_ip_range resource with name %s", d.Get("name"))
148148
apiClient := m.(*Client).apiClient
149149

150150
id := d.Id()
@@ -171,6 +171,9 @@ func resourceNetworkIPRangeRead(_ context.Context, d *schema.ResourceData, m int
171171
fabricNetworkIds = append(fabricNetworkIds, strings.TrimPrefix(fabricNetworkLink, "/iaas/api/fabric-networks/"))
172172
}
173173
d.Set("fabric_network_ids", fabricNetworkIds)
174+
} else if fabricNetworkLink, ok := networkIPRange.Links["fabric-network"]; ok {
175+
fabricNetworkIds := []string{strings.TrimPrefix(fabricNetworkLink.Href, "/iaas/api/fabric-networks/")}
176+
d.Set("fabric_network_ids", fabricNetworkIds)
174177
}
175178

176179
if err := d.Set("links", flattenLinks(networkIPRange.Links)); err != nil {
@@ -187,15 +190,15 @@ func resourceNetworkIPRangeRead(_ context.Context, d *schema.ResourceData, m int
187190
}
188191

189192
func resourceNetworkIPRangeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
190-
log.Printf("Starting to Update vra_network_profile resource")
193+
log.Printf("Starting to update the vra_network_ip_range resource with name %s", d.Get("name"))
191194
apiClient := m.(*Client).apiClient
192195

193196
id := d.Id()
194197
name := d.Get("name").(string)
195198
endIPAddress := d.Get("end_ip_address").(string)
196199
startIPAddress := d.Get("start_ip_address").(string)
197200
fabricNetworkIDs := []string{}
198-
if v, ok := d.GetOk("fabricNetworkIDs"); ok {
201+
if v, ok := d.GetOk("fabric_network_ids"); ok {
199202
if !compareUnique(v.(*schema.Set).List()) {
200203
return diag.FromErr(errors.New("specified fabric_network_ids are not unique"))
201204
}
@@ -216,13 +219,13 @@ func resourceNetworkIPRangeUpdate(ctx context.Context, d *schema.ResourceData, m
216219
if v, ok := d.GetOk("description"); ok {
217220
networkIPRangeSpecification.Description = v.(string)
218221
}
219-
log.Printf("[DEBUG] update network ip range: %#v", networkIPRangeSpecification)
222+
log.Printf("[DEBUG] Updating vra_network_ip_range resource with specification: %#v", networkIPRangeSpecification)
220223

221224
_, err := apiClient.NetworkIPRange.UpdateInternalNetworkIPRange(network_ip_range.NewUpdateInternalNetworkIPRangeParams().WithID(id).WithBody(&networkIPRangeSpecification))
222225
if err != nil {
223226
return diag.FromErr(err)
224227
}
225-
log.Printf("finished Updating vra_network_profile resource")
228+
log.Printf("Finished updating the vra_network_ip_range resource with name %s", d.Get("name"))
226229
return resourceNetworkIPRangeRead(ctx, d, m)
227230

228231
}

0 commit comments

Comments
 (0)