github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/resource_aws_lightsail_domain.go (about) 1 package aws 2 3 import ( 4 "log" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/aws/awserr" 8 "github.com/aws/aws-sdk-go/service/lightsail" 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func resourceAwsLightsailDomain() *schema.Resource { 13 return &schema.Resource{ 14 Create: resourceAwsLightsailDomainCreate, 15 Read: resourceAwsLightsailDomainRead, 16 Delete: resourceAwsLightsailDomainDelete, 17 18 Schema: map[string]*schema.Schema{ 19 "domain_name": { 20 Type: schema.TypeString, 21 Required: true, 22 ForceNew: true, 23 }, 24 "arn": { 25 Type: schema.TypeString, 26 Computed: true, 27 }, 28 }, 29 } 30 } 31 32 func resourceAwsLightsailDomainCreate(d *schema.ResourceData, meta interface{}) error { 33 conn := meta.(*AWSClient).lightsailconn 34 _, err := conn.CreateDomain(&lightsail.CreateDomainInput{ 35 DomainName: aws.String(d.Get("domain_name").(string)), 36 }) 37 38 if err != nil { 39 return err 40 } 41 42 d.SetId(d.Get("domain_name").(string)) 43 44 return resourceAwsLightsailDomainRead(d, meta) 45 } 46 47 func resourceAwsLightsailDomainRead(d *schema.ResourceData, meta interface{}) error { 48 conn := meta.(*AWSClient).lightsailconn 49 resp, err := conn.GetDomain(&lightsail.GetDomainInput{ 50 DomainName: aws.String(d.Id()), 51 }) 52 53 if err != nil { 54 if awsErr, ok := err.(awserr.Error); ok { 55 if awsErr.Code() == "NotFoundException" { 56 log.Printf("[WARN] Lightsail Domain (%s) not found, removing from state", d.Id()) 57 d.SetId("") 58 return nil 59 } 60 return err 61 } 62 return err 63 } 64 65 d.Set("arn", resp.Domain.Arn) 66 return nil 67 } 68 69 func resourceAwsLightsailDomainDelete(d *schema.ResourceData, meta interface{}) error { 70 conn := meta.(*AWSClient).lightsailconn 71 _, err := conn.DeleteDomain(&lightsail.DeleteDomainInput{ 72 DomainName: aws.String(d.Id()), 73 }) 74 75 if err != nil { 76 return err 77 } 78 return nil 79 }