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

fix updating service networking connections #3887

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions google/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