Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jan 27, 2022
1 parent 8052f47 commit c03cde6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cloudflare/resource_cloudflare_ipsec_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ func resourceCloudflareIPsecTunnel() *schema.Resource {
func resourceCloudflareIPsecTunnelCreate(d *schema.ResourceData, meta interface{}) error {
accountID := d.Get("account_id").(string)
client := meta.(*cloudflare.API)
client.AccountID = accountID

newTunnel, err := client.CreateMagicTransitIPsecTunnels(context.Background(), accountID, []cloudflare.MagicTransitIPsecTunnel{
IPsecTunnelFromResource(d),
})

if err != nil {
return errors.Wrap(err, fmt.Sprintf("error creating IPSec tunnel %s", d.Get("name").(string)))
return fmt.Errorf("error creating IPSec tunnel %s: %w", d.Get("name").(string), err)
}

d.SetId(newTunnel[0].ID)
Expand All @@ -43,20 +42,20 @@ func resourceCloudflareIPsecTunnelCreate(d *schema.ResourceData, meta interface{
}

func resourceCloudflareIPsecTunnelImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*cloudflare.API)
attributes := strings.SplitN(d.Id(), "/", 2)

if len(attributes) != 2 {
return nil, fmt.Errorf("invalid id (\"%s\") specified, should be in format \"accountID/tunnelID\"", d.Id())
return nil, errors.New(fmt.Sprintf("invalid id (\"%s\") specified, should be in format \"accountID/tunnelID\"", d.Id()))
}

accountID, tunnelID := attributes[0], attributes[1]
d.SetId(tunnelID)
d.Set("account_id", accountID)
client.AccountID = accountID

resourceCloudflareIPsecTunnelRead(d, meta)

readErr := resourceCloudflareIPsecTunnelRead(d, meta)
if readErr != nil {
return nil, readErr
}
return []*schema.ResourceData{d}, nil
}

Expand All @@ -72,7 +71,7 @@ func resourceCloudflareIPsecTunnelRead(d *schema.ResourceData, meta interface{})
d.SetId("")
return nil
}
return errors.Wrap(err, fmt.Sprintf("error reading IPsec tunnel ID %q", d.Id()))
return fmt.Errorf("error reading IPsec tunnel ID %q: %w", d.Id(), err)
}

d.Set("name", tunnel.Name)
Expand Down

0 comments on commit c03cde6

Please sign in to comment.