Skip to content

Commit

Permalink
Fix some error found in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrojnm committed Jun 7, 2020
1 parent a456dad commit 05ec3ec
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 98 deletions.
9 changes: 4 additions & 5 deletions civo/datasource_dns_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Data source to get from the api a specific domain
Expand Down Expand Up @@ -39,17 +40,15 @@ func dataSourceDnsDomainNameRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] Getting the domain by id")
domain, err := apiClient.FindDNSDomain(id.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive domain: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive domain: %s", err)
}

foundDomain = domain
} else if name, ok := d.GetOk("name"); ok {
log.Printf("[INFO] Getting the domain by name")
image, err := apiClient.FindDNSDomain(name.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive domain: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive domain: %s", err)
}

foundDomain = image
Expand Down
9 changes: 4 additions & 5 deletions civo/datasource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Data source to get from the api a specific instance
Expand Down Expand Up @@ -105,17 +106,15 @@ func dataSourceInstanceRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] Getting the instance by id")
image, err := apiClient.FindInstance(id.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive instance: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive instance: %s", err)
}

foundImage = image
} else if hostname, ok := d.GetOk("hostname"); ok {
log.Printf("[INFO] Getting the instance by hostname")
image, err := apiClient.FindInstance(hostname.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive instance: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive instance: %s", err)
}

foundImage = image
Expand Down
9 changes: 4 additions & 5 deletions civo/datasource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Data source to get from the api a specific network
Expand Down Expand Up @@ -56,17 +57,15 @@ func dataSourceNetworkRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] Getting the network by id")
network, err := apiClient.FindNetwork(id.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive network: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive network: %s", err)
}

foundNetwork = network
} else if label, ok := d.GetOk("label"); ok {
log.Printf("[INFO] Getting the network by label")
network, err := apiClient.FindNetwork(label.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive network: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive network: %s", err)
}

foundNetwork = network
Expand Down
8 changes: 4 additions & 4 deletions civo/datasource_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package civo

import (
"fmt"
"log"
"time"

"github.com/civo/civogo"
"github.com/gorhill/cronexpr"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
"time"
)

// Data source to get from the api a specific snapshot
Expand Down Expand Up @@ -92,8 +93,7 @@ func dataSourceSnapshotRead(d *schema.ResourceData, m interface{}) error {

snapShot, err := apiClient.FindSnapshot(searchBy)
if err != nil {
fmt.Errorf("[ERR] failed to retrive snapshot: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive snapshot: %s", err)
}

d.SetId(snapShot.ID)
Expand Down
6 changes: 3 additions & 3 deletions civo/datasource_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Data source to get from the api a specific ssh key
Expand Down Expand Up @@ -50,8 +51,7 @@ func dataSourceSSHKeyRead(d *schema.ResourceData, m interface{}) error {

sshKey, err := apiClient.FindSSHKey(searchBy)
if err != nil {
fmt.Errorf("[ERR] failed to retrive network: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive network: %s", err)
}

d.SetId(sshKey.ID)
Expand Down
9 changes: 4 additions & 5 deletions civo/datasource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Data source to get from the api a specific domain
Expand Down Expand Up @@ -56,17 +57,15 @@ func dataSourceVolumeRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] Getting the volume by id")
volume, err := apiClient.FindVolume(id.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive volume: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive volume: %s", err)
}

foundVolume = volume
} else if name, ok := d.GetOk("name"); ok {
log.Printf("[INFO] Getting the volume by name")
volume, err := apiClient.FindVolume(name.(string))
if err != nil {
fmt.Errorf("[ERR] failed to retrive volume: %s", err)
return err
return fmt.Errorf("[ERR] failed to retrive volume: %s", err)
}

foundVolume = volume
Expand Down
6 changes: 3 additions & 3 deletions civo/resource_dns_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

// Dns Domain resource, with this we can create and manage DNS Domain
Expand Down Expand Up @@ -42,8 +43,7 @@ func resourceDnsDomainNameCreate(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] Creating the domain %s", d.Get("name").(string))
dnsDomain, err := apiClient.CreateDNSDomain(d.Get("name").(string))
if err != nil {
fmt.Errorf("failed to create a new domains: %s", err)
return err
return fmt.Errorf("failed to create a new domains: %s", err)
}

d.SetId(dnsDomain.ID)
Expand Down
6 changes: 3 additions & 3 deletions civo/resource_dns_domain_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

// Constant all possible DNS Record
Expand Down Expand Up @@ -129,8 +130,7 @@ func resourceDnsDomainRecordCreate(d *schema.ResourceData, m interface{}) error
log.Printf("[INFO] Creating the domain record %s", d.Get("name").(string))
dnsDomainRecord, err := apiClient.CreateDNSRecord(d.Get("domain_id").(string), config)
if err != nil {
fmt.Errorf("[ERR] failed to create a new domain record: %s", err)
return err
return fmt.Errorf("[ERR] failed to create a new domain record: %s", err)
}

d.SetId(dnsDomainRecord.ID)
Expand Down
6 changes: 3 additions & 3 deletions civo/resource_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package civo

import (
"fmt"
"log"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

// Firewall resource with this we can create and manage all firewall
Expand Down Expand Up @@ -39,8 +40,7 @@ func resourceFirewallCreate(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] creating a new firewall %s", d.Get("name").(string))
firewall, err := apiClient.NewFirewall(d.Get("name").(string))
if err != nil {
fmt.Errorf("[ERR] failed to create a new firewall: %s", err)
return err
return fmt.Errorf("[ERR] failed to create a new firewall: %s", err)
}

d.SetId(firewall.ID)
Expand Down
16 changes: 7 additions & 9 deletions civo/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package civo

import (
"fmt"
"log"
"strings"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
"strings"
)

// The instance resource represents an object of type instances
Expand Down Expand Up @@ -127,8 +128,7 @@ func resourceInstanceCreate(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] configuring the instance %s", d.Get("hostname").(string))
config, err := apiClient.NewInstanceConfig()
if err != nil {
fmt.Errorf("[ERR] failed to create a new config: %s", err)
return err
return fmt.Errorf("[ERR] failed to create a new config: %s", err)
}

config.Hostname = d.Get("hostname").(string)
Expand Down Expand Up @@ -176,8 +176,7 @@ func resourceInstanceCreate(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] creating the instance %s", d.Get("hostname").(string))
instance, err := apiClient.CreateInstance(config)
if err != nil {
fmt.Errorf("[ERR] failed to create instance: %s", err)
return err
return fmt.Errorf("[ERR] failed to create instance: %s", err)
}

d.SetId(instance.ID)
Expand Down Expand Up @@ -227,10 +226,9 @@ func resourceInstanceRead(d *schema.ResourceData, m interface{}) error {
log.Printf("[INFO] retriving the instance %s", d.Id())
resp, err := apiClient.GetInstance(d.Id())
if err != nil {
// check if the instance no longer exists.
fmt.Errorf("[ERR] instance (%s) not found", d.Id())
d.SetId("")
return nil
// check if the instance no longer exists.
return fmt.Errorf("[ERR] instance (%s) not found", d.Id())
}

d.Set("hostname", resp.Hostname)
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ require (
github.com/hashicorp/go-hclog v0.12.1 // indirect
github.com/hashicorp/go-plugin v1.1.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.3.0 // indirect
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect
github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect
github.com/hashicorp/terraform-config-inspect v0.0.0-20200210163047-f7d8399e1194 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.8.0
github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136 // indirect
Expand Down
Loading

0 comments on commit 05ec3ec

Please sign in to comment.