From 8562f54511d233e8984927cf61d0920c9154f601 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Sat, 27 Jun 2020 20:15:35 -0400 Subject: [PATCH 1/2] add extra logging --- src/terraform-provider-paperspace/client.go | 4 ++++ .../datasource_network.go | 9 ++++++++- .../datasource_template.go | 11 ++++++++++- src/terraform-provider-paperspace/datasource_user.go | 11 +++++++++-- src/terraform-provider-paperspace/resource_machine.go | 9 ++++++++- src/terraform-provider-paperspace/resource_script.go | 11 ++++++++++- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/terraform-provider-paperspace/client.go b/src/terraform-provider-paperspace/client.go index 93169e0..9505c67 100644 --- a/src/terraform-provider-paperspace/client.go +++ b/src/terraform-provider-paperspace/client.go @@ -98,6 +98,8 @@ func (c *ClientConfig) Client() (paperspaceClient PaperspaceClient, err error) { transport.Set("ps_client_name", "terraform-provider-paperspace") client.Transport = transport + log.Printf("[DEBUG] Paperspace client transport %v", transport) + paperspaceClient = PaperspaceClient{ APIKey: c.APIKey, APIHost: c.APIHost, @@ -105,6 +107,8 @@ func (c *ClientConfig) Client() (paperspaceClient PaperspaceClient, err error) { HttpClient: client, } + log.Printf("[DEBUG] Paperspace client config %v", paperspaceClient) + return paperspaceClient, nil } diff --git a/src/terraform-provider-paperspace/datasource_network.go b/src/terraform-provider-paperspace/datasource_network.go index 084a3ad..a25643c 100644 --- a/src/terraform-provider-paperspace/datasource_network.go +++ b/src/terraform-provider-paperspace/datasource_network.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "net/http/httputil" "net/url" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -79,6 +80,11 @@ func dataSourceNetworkRead(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error constructing GetNetworks request: %s", err) } + requestDump, err := httputil.DumpRequest(req, true) + if err != nil { + return fmt.Errorf("Error constructing GetNetwork request: %s", err) + } + log.Print("[INFO] Request:", string(requestDump)) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { @@ -92,7 +98,8 @@ func dataSourceNetworkRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Error reading paperspace network: networks not found") } if statusCode != 200 { - return fmt.Errorf("Error reading paperspace network: Response: %s", resp.Body) + responseDump, _ := httputil.DumpResponse(resp, true) + return fmt.Errorf("Error reading paperspace network: Response: %s", string(responseDump)) } var f interface{} diff --git a/src/terraform-provider-paperspace/datasource_template.go b/src/terraform-provider-paperspace/datasource_template.go index b279608..94c8dc3 100644 --- a/src/terraform-provider-paperspace/datasource_template.go +++ b/src/terraform-provider-paperspace/datasource_template.go @@ -5,8 +5,10 @@ import ( "fmt" "log" "net/http" + "net/http/httputil" "net/url" + "github.com/davecgh/go-spew/spew" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -87,7 +89,13 @@ func dataSourceTemplateRead(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error constructing GetTemplates request: %s", err) } + requestDump, err := httputil.DumpRequest(req, true) + if err != nil { + return fmt.Errorf("Error constructing GetTemplates request: %s", err) + } + log.Print("[INFO] Request:", string(requestDump)) + spew.Sdump(paperspaceClient) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { return fmt.Errorf("Error reading paperspace template: %s", err) @@ -100,7 +108,8 @@ func dataSourceTemplateRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Error reading paperspace template: templates not found") } if statusCode != 200 { - return fmt.Errorf("Error reading paperspace template: Response: %s", resp.Body) + responseDump, _ := httputil.DumpResponse(resp, true) + return fmt.Errorf("Error reading paperspace template: Response: %s", string(responseDump)) } var f interface{} diff --git a/src/terraform-provider-paperspace/datasource_user.go b/src/terraform-provider-paperspace/datasource_user.go index d31e3a5..fcaaa9e 100644 --- a/src/terraform-provider-paperspace/datasource_user.go +++ b/src/terraform-provider-paperspace/datasource_user.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "net/http/httputil" "net/url" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -71,6 +72,11 @@ func dataSourceUserRead(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error constructing GetUsers request: %s", err) } + requestDump, err := httputil.DumpRequest(req, true) + if err != nil { + return fmt.Errorf("Error constructing GetUsers request: %s", err) + } + log.Print("[INFO] Request:", string(requestDump)) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { @@ -84,7 +90,8 @@ func dataSourceUserRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Error reading paperspace user: users not found") } if statusCode != 200 { - return fmt.Errorf("Error reading paperspace user: Response: %s", resp.Body) + responseDump, _ := httputil.DumpResponse(resp, true) + return fmt.Errorf("Error reading paperspace user: Response: %s", string(responseDump)) } var f interface{} @@ -92,7 +99,7 @@ func dataSourceUserRead(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error decoding GetUsers response body: %s", err) } - LogHttpResponse("paperspace dataSourceTemplateRead", req.URL, resp, f, err) + LogHttpResponse("paperspace dataSourceUserRead", req.URL, resp, f, err) mpa := f.([]interface{}) if len(mpa) > 1 { diff --git a/src/terraform-provider-paperspace/resource_machine.go b/src/terraform-provider-paperspace/resource_machine.go index ed4af61..b4de668 100644 --- a/src/terraform-provider-paperspace/resource_machine.go +++ b/src/terraform-provider-paperspace/resource_machine.go @@ -33,9 +33,10 @@ func resourceMachineCreate(d *schema.ResourceData, m interface{}) error { body.AppendAsIfSet(d, "user_id", "userId") body.AppendAsIfSet(d, "team_id", "teamId") body.AppendAsIfSet(d, "script_id", "scriptId") + body.AppendAsIfSet(d, "network_id", "networkId") + body.AppendAsIfSet(d, "cluster_id", "clusterId") // fields not tested when this project was picked back up for https://github.com/Paperspace/terraform-provider-paperspace/pull/3 - body.AppendAsIfSet(d, "network_id", "networkId") body.AppendIfSet(d, "email") body.AppendIfSet(d, "password") body.AppendAsIfSet(d, "firstname", "firstName") @@ -87,6 +88,7 @@ func resourceMachineCreate(d *schema.ResourceData, m interface{}) error { SetResDataFrom(d, body, "team_id", "teamId") SetResDataFrom(d, body, "script_id", "scriptId") SetResDataFrom(d, body, "dt_last_run", "dtLastRun") + SetResDataFrom(d, body, "cluster_id", "clusterId") d.SetId(id) @@ -128,6 +130,7 @@ func resourceMachineRead(d *schema.ResourceData, m interface{}) error { SetResDataFrom(d, mp, "team_id", "teamId") SetResDataFrom(d, mp, "script_id", "scriptId") SetResDataFrom(d, mp, "dt_last_run", "dtLastRun") + SetResDataFrom(d, mp, "cluster_id", "clusterId") return nil } @@ -310,6 +313,10 @@ func resourceMachine() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "cluster_id": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(5 * time.Minute), diff --git a/src/terraform-provider-paperspace/resource_script.go b/src/terraform-provider-paperspace/resource_script.go index 3de3539..1110059 100644 --- a/src/terraform-provider-paperspace/resource_script.go +++ b/src/terraform-provider-paperspace/resource_script.go @@ -6,7 +6,9 @@ import ( "fmt" "log" "net/http" + "net/http/httputil" + "github.com/davecgh/go-spew/spew" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -38,6 +40,11 @@ func resourceScriptCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return fmt.Errorf("Error constructing CreateScript request: %s", err) } + requestDump, err := httputil.DumpRequest(req, true) + if err != nil { + return fmt.Errorf("Error constructing CreateScript request: %s", err) + } + log.Print("[INFO] Request:", string(requestDump)) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { @@ -48,7 +55,8 @@ func resourceScriptCreate(d *schema.ResourceData, m interface{}) error { statusCode := resp.StatusCode log.Printf("[INFO] paperspace resourceScriptCreate StatusCode: %v", statusCode) if statusCode != 200 { - return fmt.Errorf("Error creating paperspace script: Response: %s", resp.Body) + responseDump, _ := httputil.DumpResponse(resp, true) + return fmt.Errorf("Error reading paperspace script: Response: %s", string(responseDump)) } var f interface{} @@ -91,6 +99,7 @@ func resourceScriptRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Error constructing GetScript request: %s", err) } + spew.Sdump(paperspaceClient) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { return fmt.Errorf("Error completing GetScript request: %s", err) From a5147b449a1a55e4333a0cdda8c33d30d62d5037 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Sat, 27 Jun 2020 20:19:22 -0400 Subject: [PATCH 2/2] fixup! add extra logging --- src/terraform-provider-paperspace/datasource_template.go | 2 -- src/terraform-provider-paperspace/resource_script.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/terraform-provider-paperspace/datasource_template.go b/src/terraform-provider-paperspace/datasource_template.go index 94c8dc3..f7a6278 100644 --- a/src/terraform-provider-paperspace/datasource_template.go +++ b/src/terraform-provider-paperspace/datasource_template.go @@ -8,7 +8,6 @@ import ( "net/http/httputil" "net/url" - "github.com/davecgh/go-spew/spew" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -95,7 +94,6 @@ func dataSourceTemplateRead(d *schema.ResourceData, m interface{}) error { } log.Print("[INFO] Request:", string(requestDump)) - spew.Sdump(paperspaceClient) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { return fmt.Errorf("Error reading paperspace template: %s", err) diff --git a/src/terraform-provider-paperspace/resource_script.go b/src/terraform-provider-paperspace/resource_script.go index 1110059..3bca720 100644 --- a/src/terraform-provider-paperspace/resource_script.go +++ b/src/terraform-provider-paperspace/resource_script.go @@ -8,7 +8,6 @@ import ( "net/http" "net/http/httputil" - "github.com/davecgh/go-spew/spew" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -99,7 +98,6 @@ func resourceScriptRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("Error constructing GetScript request: %s", err) } - spew.Sdump(paperspaceClient) resp, err := paperspaceClient.HttpClient.Do(req) if err != nil { return fmt.Errorf("Error completing GetScript request: %s", err)