From be1ab03dd1f449dd3b6c896c4cf10d52c3228080 Mon Sep 17 00:00:00 2001 From: weikaolun Date: Mon, 29 Mar 2021 16:40:40 -0400 Subject: [PATCH] feat(networks): Add delete functionality. --- go.mod | 2 +- go.sum | 2 ++ .../resource_network.go | 24 +++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 65fb9a1..7951b5c 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 47c499b..0ccb26b 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/src/terraform-provider-paperspace/resource_network.go b/src/terraform-provider-paperspace/resource_network.go index a0c1c5e..728b903 100644 --- a/src/terraform-provider-paperspace/resource_network.go +++ b/src/terraform-provider-paperspace/resource_network.go @@ -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" ) @@ -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 { @@ -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 { @@ -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,