Skip to content

Commit

Permalink
feat(networks): Add delete functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-welch committed Mar 29, 2021
1 parent b7b29ca commit be1ab03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/Paperspace/terraform-paperspace-provider

require (
github.com/Paperspace/paperspace-go v0.3.2
github.com/Paperspace/paperspace-go v1.0.0
github.com/davecgh/go-spew v1.1.1
github.com/hashicorp/terraform-plugin-sdk v1.13.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbf
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Paperspace/paperspace-go v1.0.0 h1:OkC31Qu9YctaOeuGhBvowvffyq16SX/wv1qISjBsFcE=
github.com/Paperspace/paperspace-go v1.0.0/go.mod h1:dtV/8NzfKc0mPp8zw6Gu2mUvWL5wvOYp/BV+0oaqoc0=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
24 changes: 12 additions & 12 deletions src/terraform-provider-paperspace/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"time"

"github.com/Paperspace/paperspace-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
Expand Down Expand Up @@ -35,7 +36,6 @@ func updateNetworkSchema(d *schema.ResourceData, network Network, name string) {
d.Set("name", name)
d.Set("netmask", network.Netmask)
d.Set("network", network.Network)
d.Set("vlan_id", network.VlanID)
}

func resourceNetworkCreate(d *schema.ResourceData, m interface{}) error {
Expand Down Expand Up @@ -96,14 +96,21 @@ func resourceNetworkRead(d *schema.ResourceData, m interface{}) error {
}

func resourceNetworkUpdate(d *schema.ResourceData, m interface{}) error {
// TODO: implement; api doesn't exist yet
return resourceNetworkRead(d, m)
}

func resourceNetworkDelete(d *schema.ResourceData, m interface{}) error {
// TODO: implement; api doesn't exist yet
d.SetId("")
return nil
paperspaceClient := newPaperspaceClient(m)
return resource.Retry(d.Timeout(schema.TimeoutDefault), func() *resource.RetryError {
if err := paperspaceClient.DeleteNetwork(d.Id(), paperspace.NetworkDeleteParams{}); err != nil {
if ErrNotFound(err) {
return resource.NonRetryableError(nil)
}
return resource.RetryableError(err)
}

return resource.NonRetryableError(nil)
})
}

func resourceNetwork() *schema.Resource {
Expand Down Expand Up @@ -143,13 +150,6 @@ func resourceNetwork() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"vlan_id": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
// name is not on the network schema but rather part of what we're calling here
// the "named network response", which comes from /getNetworks and includes the
// network and its name as joined with the network_owners table.
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down

0 comments on commit be1ab03

Please sign in to comment.