Skip to content

Commit

Permalink
fix updating service networking connections
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
danawillow authored and modular-magician committed Jun 19, 2019
1 parent 5fca8af commit 02a0d7d
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions google/resource_service_networking_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,42 @@ func resourceServiceNetworkingConnectionRead(d *schema.ResourceData, meta interf
return nil
}

// NOTE(craigatgoogle): The API for this resource doesn't define an update, however the behavior
// of Create serves as a de facto update by overwriting connections with the duplicate
// tuples: (network/service).
func resourceServiceNetworkingConnectionUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceServiceNetworkingConnectionCreate(d, meta)
config := meta.(*Config)

connectionId, err := parseConnectionId(d.Id())
if err != nil {
return fmt.Errorf("Failed to find Service Networking Connection, err: %s", err)
}

parentService := formatParentService(connectionId.Service)

if d.HasChange("reserved_peering_ranges") {
network := d.Get("network").(string)
serviceNetworkingNetworkName, err := retrieveServiceNetworkingNetworkName(d, config, network)
if err != nil {
return fmt.Errorf("Failed to find Service Networking Connection, err: %s", err)
}

connection := &servicenetworking.Connection{
Network: serviceNetworkingNetworkName,
ReservedPeeringRanges: convertStringArr(d.Get("reserved_peering_ranges").([]interface{})),
}

// The API docs don't specify that you can do connections/-, but that's what gcloud does,
// and it's easier than grabbing the connection name. The docs also mention an update mask,
// but manual testing shows that by putting both the network and ranges in the request,
// it only updates the peering for that network (rather than overwriting everything). This
// also matches gcloud's behavior.
op, err := config.clientServiceNetworking.Services.Connections.Patch(parentService+"/connections/-", connection).Force(true).Do()
if err != nil {
return err
}
if err := serviceNetworkingOperationWait(config, op, "Update Service Networking Connection"); err != nil {
return err
}
}
return resourceServiceNetworkingConnectionRead(d, meta)
}

// NOTE(craigatgoogle): This resource doesn't have a defined Delete method, however an un-documented
Expand Down

0 comments on commit 02a0d7d

Please sign in to comment.