Skip to content

Commit

Permalink
add network update support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirendersingh19 committed Feb 9, 2022
1 parent fa07b64 commit e194227
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ibm/service/power/resource_ibm_pi_network.go
Expand Up @@ -34,6 +34,7 @@ func ResourceIBMPINetwork() *schema.Resource {

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Update: schema.DefaultTimeout(60 * time.Minute),
Delete: schema.DefaultTimeout(60 * time.Minute),
},

Expand Down Expand Up @@ -181,7 +182,37 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta
}

func resourceIBMPINetworkUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return nil
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
}

cloudInstanceID, networkID, err := splitID(d.Id())
if err != nil {
return diag.FromErr(err)
}

gateway := d.Get(helpers.PINetworkGateway).(string)
networkdns := flex.ExpandStringList((d.Get(helpers.PINetworkDNS).(*schema.Set)).List())
networkC := st.NewIBMPINetworkClient(ctx, sess, cloudInstanceID)

//update body
body := &models.NetworkUpdate{}
body.Gateway = &gateway
body.DNSServers = networkdns

// check for name change
if d.HasChange(helpers.PINetworkName) {
name := d.Get(helpers.PINetworkName).(string)
body.Name = &name
}

_, err = networkC.Update(networkID, body)
if err != nil {
return diag.Errorf("failed to update network name: %v", err)
}

return resourceIBMPINetworkRead(ctx, d, meta)
}

func resourceIBMPINetworkDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/pi_network.html.markdown
Expand Up @@ -44,6 +44,7 @@ resource "ibm_pi_network" "power_networks" {
The `ibm_pi_network` provides the following [Timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options:

- **create** - (Default 60 minutes) Used for creating a network.
- **update** - (Default 60 minutes) Used for updating a network.
- **delete** - (Default 60 minutes) Used for deleting a network.

## Argument reference
Expand Down

0 comments on commit e194227

Please sign in to comment.