mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
e272cb2243
Fixes failing acceptance test: ``` $ make testacc TEST=./builtin/providers/digitalocean TESTARGS='-run=TestAccDigitalOceanVolume_Droplet' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/20 11:38:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/digitalocean -v -run=TestAccDigitalOceanVolume_Droplet -timeout 120m === RUN TestAccDigitalOceanVolume_Droplet --- PASS: TestAccDigitalOceanVolume_Droplet (57.38s) PASS ok github.com/hashicorp/terraform/builtin/providers/digitalocean 57.411s ``` Also removes all redundant type declarations in the digitalocean package.
90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
package digitalocean
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/digitalocean/godo"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func resourceDigitalOceanDomain() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: resourceDigitalOceanDomainCreate,
|
|
Read: resourceDigitalOceanDomainRead,
|
|
Delete: resourceDigitalOceanDomainDelete,
|
|
Importer: &schema.ResourceImporter{
|
|
State: schema.ImportStatePassthrough,
|
|
},
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"name": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
ForceNew: true,
|
|
},
|
|
|
|
"ip_address": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
ForceNew: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func resourceDigitalOceanDomainCreate(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*godo.Client)
|
|
|
|
// Build up our creation options
|
|
|
|
opts := &godo.DomainCreateRequest{
|
|
Name: d.Get("name").(string),
|
|
IPAddress: d.Get("ip_address").(string),
|
|
}
|
|
|
|
log.Printf("[DEBUG] Domain create configuration: %#v", opts)
|
|
domain, _, err := client.Domains.Create(opts)
|
|
if err != nil {
|
|
return fmt.Errorf("Error creating Domain: %s", err)
|
|
}
|
|
|
|
d.SetId(domain.Name)
|
|
log.Printf("[INFO] Domain Name: %s", domain.Name)
|
|
|
|
return resourceDigitalOceanDomainRead(d, meta)
|
|
}
|
|
|
|
func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*godo.Client)
|
|
|
|
domain, resp, err := client.Domains.Get(d.Id())
|
|
if err != nil {
|
|
// If the domain is somehow already destroyed, mark as
|
|
// successfully gone
|
|
if resp.StatusCode == 404 {
|
|
d.SetId("")
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("Error retrieving domain: %s", err)
|
|
}
|
|
|
|
d.Set("name", domain.Name)
|
|
|
|
return nil
|
|
}
|
|
|
|
func resourceDigitalOceanDomainDelete(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*godo.Client)
|
|
|
|
log.Printf("[INFO] Deleting Domain: %s", d.Id())
|
|
_, err := client.Domains.Delete(d.Id())
|
|
if err != nil {
|
|
return fmt.Errorf("Error deleting Domain: %s", err)
|
|
}
|
|
|
|
d.SetId("")
|
|
return nil
|
|
}
|