Skip to content

Commit

Permalink
Fixed error in all this files
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrojnm committed Jun 7, 2020
1 parent 05ec3ec commit 0bb5787
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 108 deletions.
8 changes: 4 additions & 4 deletions civo/datasource_dns_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

// Data source to get from the api a specific domain
// dataSourceDnsDomainName data source to get from the api a specific domain
// using the id or the name of the domain
func dataSourceDnsDomainName() *schema.Resource {
func dataSourceDNSDomainNamego() *schema.Resource {
return &schema.Resource{
Read: dataSourceDnsDomainNameRead,
Read: dataSourceDNSDomainNameRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand All @@ -31,7 +31,7 @@ func dataSourceDnsDomainName() *schema.Resource {
}
}

func dataSourceDnsDomainNameRead(d *schema.ResourceData, m interface{}) error {
func dataSourceDNSDomainNameRead(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

var foundDomain *civogo.DNSDomain
Expand Down
7 changes: 4 additions & 3 deletions civo/datasource_dns_domain_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package civo

import (
"fmt"

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

// Data source to get from the api a specific domain record
// using the id or the name of the domain
func dataSourceDnsDomainRecord() *schema.Resource {
func dataSourceDNSDomainRecord() *schema.Resource {
return &schema.Resource{
Read: dataSourceDnsDomainRecordRead,
Read: dataSourceDNSDomainRecordRead,
Schema: map[string]*schema.Schema{
"domain_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -56,7 +57,7 @@ func dataSourceDnsDomainRecord() *schema.Resource {
}
}

func dataSourceDnsDomainRecordRead(d *schema.ResourceData, m interface{}) error {
func dataSourceDNSDomainRecordRead(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)
domain := d.Get("domain_id").(string)
name := d.Get("name").(string)
Expand Down
16 changes: 9 additions & 7 deletions civo/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package civo

import (
"fmt"

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

// Civo cloud provider
// Provider Civo cloud provider
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
Expand All @@ -23,8 +24,8 @@ func Provider() terraform.ResourceProvider {
"civo_instances_size": dataSourceInstancesSize(),
"civo_instances": dataSourceInstances(),
"civo_instance": dataSourceInstance(),
"civo_dns_domain_name": dataSourceDnsDomainName(),
"civo_dns_domain_record": dataSourceDnsDomainRecord(),
"civo_dns_domain_name": dataSourceDNSDomainNamego(),
"civo_dns_domain_record": dataSourceDNSDomainRecord(),
"civo_network": dataSourceNetwork(),
"civo_volume": dataSourceVolume(),
"civo_loadbalancer": dataSourceLoadBalancer(),
Expand All @@ -36,8 +37,8 @@ func Provider() terraform.ResourceProvider {
"civo_network": resourceNetwork(),
"civo_volume": resourceVolume(),
"civo_volume_attachment": resourceVolumeAttachment(),
"civo_dns_domain_name": resourceDnsDomainName(),
"civo_dns_domain_record": resourceDnsDomainRecord(),
"civo_dns_domain_name": resourceDNSDomainName(),
"civo_dns_domain_record": resourceDNSDomainRecord(),
"civo_firewall": resourceFirewall(),
"civo_firewall_rule": resourceFirewallRule(),
"civo_loadbalancer": resourceLoadBalancer(),
Expand All @@ -55,7 +56,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
if token, ok := d.GetOk("token"); ok {
client, _ := civogo.NewClient(token.(string))
return client, nil
} else {
return nil, fmt.Errorf("[ERR] token not found")
}

return nil, fmt.Errorf("[ERR] token not found")

}
26 changes: 13 additions & 13 deletions civo/resource_dns_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Dns Domain resource, with this we can create and manage DNS Domain
func resourceDnsDomainName() *schema.Resource {
func resourceDNSDomainName() *schema.Resource {
fmt.Print()
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -25,19 +25,19 @@ func resourceDnsDomainName() *schema.Resource {
Computed: true,
},
},
Create: resourceDnsDomainNameCreate,
Read: resourceDnsDomainNameRead,
Update: resourceDnsDomainNameUpdate,
Delete: resourceDnsDomainNameDelete,
Create: resourceDNSDomainNameCreate,
Read: resourceDNSDomainNameRead,
Update: resourceDNSDomainNameUpdate,
Delete: resourceDNSDomainNameDelete,
//Exists: resourceExistsItem,
Importer: &schema.ResourceImporter{
State: resourceDnsDomainImport,
State: resourceDNSDomainImport,
},
}
}

// function to create a new domain in your account
func resourceDnsDomainNameCreate(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainNameCreate(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] Creating the domain %s", d.Get("name").(string))
Expand All @@ -48,11 +48,11 @@ func resourceDnsDomainNameCreate(d *schema.ResourceData, m interface{}) error {

d.SetId(dnsDomain.ID)

return resourceDnsDomainNameRead(d, m)
return resourceDNSDomainNameRead(d, m)
}

// function to read a domain from your account
func resourceDnsDomainNameRead(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainNameRead(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] retriving the domain %s", d.Get("name").(string))
Expand All @@ -73,7 +73,7 @@ func resourceDnsDomainNameRead(d *schema.ResourceData, m interface{}) error {
}

// function to update a specific domain
func resourceDnsDomainNameUpdate(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainNameUpdate(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] Searching the domain %s", d.Get("name").(string))
Expand All @@ -94,11 +94,11 @@ func resourceDnsDomainNameUpdate(d *schema.ResourceData, m interface{}) error {

}

return resourceDnsDomainNameRead(d, m)
return resourceDNSDomainNameRead(d, m)
}

// function to delete a specific domain
func resourceDnsDomainNameDelete(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainNameDelete(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] Searching the domain to %s", d.Get("name").(string))
Expand All @@ -118,7 +118,7 @@ func resourceDnsDomainNameDelete(d *schema.ResourceData, m interface{}) error {
}

// custom import to able add a main domain to the terraform
func resourceDnsDomainImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
func resourceDNSDomainImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] Searching the domain %s", d.Get("name").(string))
Expand Down
34 changes: 17 additions & 17 deletions civo/resource_dns_domain_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const (
DNSRecordTypeTXT = "txt"
)

// Dns domain record resource with this we can create and manage DNS Domain
func resourceDnsDomainRecord() *schema.Resource {
// DNS domain record resource with this we can create and manage DNS Domain
func resourceDNSDomainRecord() *schema.Resource {
fmt.Print()
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -82,19 +82,19 @@ func resourceDnsDomainRecord() *schema.Resource {
Computed: true,
},
},
Create: resourceDnsDomainRecordCreate,
Read: resourceDnsDomainRecordRead,
Update: resourceDnsDomainRecordUpdate,
Delete: resourceDnsDomainRecordDelete,
Create: resourceDNSDomainRecordCreate,
Read: resourceDNSDomainRecordRead,
Update: resourceDNSDomainRecordUpdate,
Delete: resourceDNSDomainRecordDelete,
//Exists: resourceExistsItem,
Importer: &schema.ResourceImporter{
State: resourceDnsDomainRecordImport,
State: resourceDNSDomainRecordImport,
},
}
}

// function to create a new record for the main domain
func resourceDnsDomainRecordCreate(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainRecordCreate(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] configuring the domain record %s", d.Get("name").(string))
Expand Down Expand Up @@ -135,11 +135,11 @@ func resourceDnsDomainRecordCreate(d *schema.ResourceData, m interface{}) error

d.SetId(dnsDomainRecord.ID)

return resourceDnsDomainRecordRead(d, m)
return resourceDNSDomainRecordRead(d, m)
}

// function to read a dns domain record
func resourceDnsDomainRecordRead(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainRecordRead(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] retriving the domain record %s", d.Get("name").(string))
Expand Down Expand Up @@ -167,7 +167,7 @@ func resourceDnsDomainRecordRead(d *schema.ResourceData, m interface{}) error {
}

// function to update a dns domain record
func resourceDnsDomainRecordUpdate(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainRecordUpdate(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

resp, err := apiClient.GetDNSRecord(d.Get("domain_id").(string), d.Id())
Expand Down Expand Up @@ -206,11 +206,11 @@ func resourceDnsDomainRecordUpdate(d *schema.ResourceData, m interface{}) error
return fmt.Errorf("[ERR] an error occurred while renamed the domain record %s, %s", d.Id(), err)
}

return resourceDnsDomainRecordRead(d, m)
return resourceDNSDomainRecordRead(d, m)
}

//function to delete a dns domain record
func resourceDnsDomainRecordDelete(d *schema.ResourceData, m interface{}) error {
func resourceDNSDomainRecordDelete(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*civogo.Client)

log.Printf("[INFO] Searching the domain record %s", d.Get("name").(string))
Expand All @@ -229,16 +229,16 @@ func resourceDnsDomainRecordDelete(d *schema.ResourceData, m interface{}) error
}

// custom import to able to add a main domain to the terraform
func resourceDnsDomainRecordImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
func resourceDNSDomainRecordImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
apiClient := m.(*civogo.Client)

domainId, DomainRecordId, err := resourceCommonParseId(d.Id())
domainID, DomainRecordID, err := resourceCommonParseID(d.Id())
if err != nil {
return nil, err
}

log.Printf("[INFO] retriving the domain record %s", DomainRecordId)
resp, err := apiClient.GetDNSRecord(domainId, DomainRecordId)
log.Printf("[INFO] retriving the domain record %s", DomainRecordID)
resp, err := apiClient.GetDNSRecord(domainID, DomainRecordID)
if err != nil {
if resp != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions civo/resource_firewall_rule.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"
)

// Firewall Rule resource represent you can create and manage all firewall rules
Expand Down Expand Up @@ -160,13 +161,13 @@ func resourceFirewallRuleDelete(d *schema.ResourceData, m interface{}) error {
func resourceFirewallRuleImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
apiClient := m.(*civogo.Client)

firewallId, firewallRuleId, err := resourceCommonParseId(d.Id())
firewallID, firewallRuleID, err := resourceCommonParseID(d.Id())
if err != nil {
return nil, err
}

log.Printf("[INFO] retriving the firewall rule %s", firewallRuleId)
resp, err := apiClient.FindFirewallRule(firewallId, firewallRuleId)
log.Printf("[INFO] retriving the firewall rule %s", firewallRuleID)
resp, err := apiClient.FindFirewallRule(firewallID, firewallRuleID)
if err != nil {
if resp != nil {
return nil, err
Expand Down
40 changes: 20 additions & 20 deletions civo/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,28 @@ func resourceInstanceCreate(d *schema.ResourceData, m interface{}) error {

if resp.Status != "ACTIVE" {
return resource.RetryableError(fmt.Errorf("[ERR] expected instance to be created but was in state %s", resp.Status))
} else {
/*
Once the instance is created, we check if the object firewall_id,
if it is, then we set the firewall id to the instances
*/
if attr, ok := d.GetOk("firewall_id"); ok {
_, errInstance := apiClient.SetInstanceFirewall(instance.ID, attr.(string))
if errInstance != nil {
return resource.NonRetryableError(fmt.Errorf("[ERR] failed to set firewall to the instance: %s", errInstance))
}
}

/*
Once the instance is created, we check if the object firewall_id,
if it is, then we set the firewall id to the instances
*/
if attr, ok := d.GetOk("firewall_id"); ok {
_, errInstance := apiClient.SetInstanceFirewall(instance.ID, attr.(string))
if errInstance != nil {
return resource.NonRetryableError(fmt.Errorf("[ERR] failed to set firewall to the instance: %s", errInstance))
}
}

/*
Once the instance is created, we check if the object notes,
if it is, then we add the note to the instances
*/
if attr, ok := d.GetOk("notes"); ok {
resp.Notes = attr.(string)
_, errInstance := apiClient.UpdateInstance(resp)
if errInstance != nil {
return resource.NonRetryableError(fmt.Errorf("[ERR] failed to set note to the instance: %s", errInstance))
}
/*
Once the instance is created, we check if the object notes,
if it is, then we add the note to the instances
*/
if attr, ok := d.GetOk("notes"); ok {
resp.Notes = attr.(string)
_, errInstance := apiClient.UpdateInstance(resp)
if errInstance != nil {
return resource.NonRetryableError(fmt.Errorf("[ERR] failed to set note to the instance: %s", errInstance))
}
}

Expand Down
7 changes: 6 additions & 1 deletion civo/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package civo

import (
"fmt"
"log"

"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"
)

// Kubernetes Cluster resource, with this you can manage all cluster from terraform
Expand Down Expand Up @@ -219,6 +220,10 @@ func resourceKubernetesClusterRead(d *schema.ResourceData, m interface{}) error
log.Printf("[INFO] retrieving the kubernetes cluster %s", d.Id())
resp, err := apiClient.FindKubernetesCluster(d.Id())
if err != nil {
if resp != nil {
d.SetId("")
return nil
}
return fmt.Errorf("[ERR] failed to find the kubernets cluster: %s", err)
}

Expand Down
Loading

0 comments on commit 0bb5787

Please sign in to comment.