opentofu/builtin/providers/aws/resource_aws_lightsail_domain.go
Paul Stack c69e325a1a provider/aws: Add support for AWS Lightsail Domain (#10637)
```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSLightsailDomain_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/12/09 15:19:58 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSLightsailDomain_ -timeout 120m
=== RUN   TestAccAWSLightsailDomain_basic
--- PASS: TestAccAWSLightsailDomain_basic (16.28s)
=== RUN   TestAccAWSLightsailDomain_disappears
--- PASS: TestAccAWSLightsailDomain_disappears (12.71s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws29.015s
```
2016-12-09 17:56:48 +00:00

80 lines
1.8 KiB
Go

package aws
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/lightsail"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceAwsLightsailDomain() *schema.Resource {
return &schema.Resource{
Create: resourceAwsLightsailDomainCreate,
Read: resourceAwsLightsailDomainRead,
Delete: resourceAwsLightsailDomainDelete,
Schema: map[string]*schema.Schema{
"domain_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceAwsLightsailDomainCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lightsailconn
_, err := conn.CreateDomain(&lightsail.CreateDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
})
if err != nil {
return err
}
d.SetId(d.Get("domain_name").(string))
return resourceAwsLightsailDomainRead(d, meta)
}
func resourceAwsLightsailDomainRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lightsailconn
resp, err := conn.GetDomain(&lightsail.GetDomainInput{
DomainName: aws.String(d.Id()),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "NotFoundException" {
log.Printf("[WARN] Lightsail Domain (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
return err
}
return err
}
d.Set("arn", resp.Domain.Arn)
return nil
}
func resourceAwsLightsailDomainDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lightsailconn
_, err := conn.DeleteDomain(&lightsail.DeleteDomainInput{
DomainName: aws.String(d.Id()),
})
if err != nil {
return err
}
return nil
}