Skip to content

Commit

Permalink
fix updating service networking connections (hashicorp#871)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and danawillow committed Jun 21, 2019
1 parent 3fb0c8d commit 2541600
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions google-beta/resource_service_networking_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,39 @@ 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.
op, err := config.clientServiceNetworking.Services.Connections.Patch(parentService+"/connections/-", connection).UpdateMask("reservedPeeringRanges").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 2541600

Please sign in to comment.