Skip to content

Commit

Permalink
r/aws_amplify_domain_association: Building with Plugin SDK v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jun 3, 2021
1 parent 49a5ea0 commit c2d6be3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 60 deletions.
44 changes: 18 additions & 26 deletions aws/resource_aws_amplify_domain_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAwsAmplifyDomainAssociation() *schema.Resource {
Expand All @@ -24,27 +24,27 @@ func resourceAwsAmplifyDomainAssociation() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"app_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"arn": {
Type: schema.TypeString,
Computed: true,
},

"domain_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"enable_auto_sub_domain": {
Type: schema.TypeBool,
Optional: true,
},
"sub_domain_settings": {
Type: schema.TypeList,

"sub_domain_setting": {
Type: schema.TypeSet,
Required: true,
MaxItems: 255,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"branch_name": {
Expand All @@ -58,6 +58,7 @@ func resourceAwsAmplifyDomainAssociation() *schema.Resource {
},
},
},

// non-API
"wait_for_verification": {
Type: schema.TypeBool,
Expand All @@ -80,14 +81,10 @@ func resourceAwsAmplifyDomainAssociationCreate(d *schema.ResourceData, meta inte
DomainName: aws.String(d.Get("domain_name").(string)),
}

if v, ok := d.GetOk("sub_domain_settings"); ok {
if v, ok := d.GetOk("sub_domain_setting"); ok {
params.SubDomainSettings = expandAmplifySubDomainSettings(v.([]interface{}))
}

if v, ok := d.GetOk("enable_auto_sub_domain"); ok {
params.EnableAutoSubDomain = aws.Bool(v.(bool))
}

resp, err := conn.CreateDomainAssociation(params)
if err != nil {
return fmt.Errorf("Error creating Amplify DomainAssociation: %s", err)
Expand Down Expand Up @@ -130,10 +127,9 @@ func resourceAwsAmplifyDomainAssociationRead(d *schema.ResourceData, meta interf
d.Set("app_id", app_id)
d.Set("arn", resp.DomainAssociation.DomainAssociationArn)
d.Set("domain_name", resp.DomainAssociation.DomainName)
if err := d.Set("sub_domain_settings", flattenAmplifySubDomainSettings(resp.DomainAssociation.SubDomains)); err != nil {
return fmt.Errorf("error setting sub_domain_settings: %s", err)
if err := d.Set("sub_domain_setting", flattenAmplifySubDomainSettings(resp.DomainAssociation.SubDomains)); err != nil {
return fmt.Errorf("error setting sub_domain_setting: %s", err)
}
d.Set("enable_auto_sub_domain", resp.DomainAssociation.EnableAutoSubDomain)

return nil
}
Expand All @@ -151,12 +147,8 @@ func resourceAwsAmplifyDomainAssociationUpdate(d *schema.ResourceData, meta inte
DomainName: aws.String(domain_name),
}

if d.HasChange("sub_domain_settings") {
params.SubDomainSettings = expandAmplifySubDomainSettings(d.Get("sub_domain_settings").([]interface{}))
}

if d.HasChange("enable_auto_sub_domain") {
params.EnableAutoSubDomain = aws.Bool(d.Get("enable_auto_sub_domain").(bool))
if d.HasChange("sub_domain_setting") {
params.SubDomainSettings = expandAmplifySubDomainSettings(d.Get("sub_domain_setting").([]interface{}))
}

_, err := conn.UpdateDomainAssociation(params)
Expand Down
14 changes: 7 additions & 7 deletions aws/resource_aws_amplify_domain_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccAWSAmplifyDomainAssociation_basic(t *testing.T) {
Expand All @@ -31,9 +31,9 @@ func TestAccAWSAmplifyDomainAssociation_basic(t *testing.T) {
testAccCheckAWSAmplifyDomainAssociationExists(resourceName, &domain),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile("^arn:[^:]+:amplify:[^:]+:[^:]+:apps/[^/]+/domains/[^/]+$")),
resource.TestCheckResourceAttr(resourceName, "domain_name", domainName),
resource.TestCheckResourceAttr(resourceName, "sub_domain_settings.#", "1"),
resource.TestCheckResourceAttr(resourceName, "sub_domain_settings.0.branch_name", "master"),
resource.TestCheckResourceAttr(resourceName, "sub_domain_settings.0.prefix", ""),
resource.TestCheckResourceAttr(resourceName, "sub_domain_setting.#", "1"),
resource.TestCheckResourceAttr(resourceName, "sub_domain_setting.0.branch_name", "master"),
resource.TestCheckResourceAttr(resourceName, "sub_domain_setting.0.prefix", ""),
),
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@ resource "aws_amplify_domain_association" "test" {
app_id = aws_amplify_app.test.id
domain_name = "%s"
sub_domain_settings {
sub_domain_setting {
branch_name = aws_amplify_branch.test.branch_name
prefix = ""
}
Expand Down
53 changes: 26 additions & 27 deletions website/docs/r/amplify_domain_association.html.markdown
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
---
subcategory: "Amplify"
subcategory: "Amplify Console"
layout: "aws"
page_title: "AWS: aws_amplify_domain_association"
description: |-
Provides an Amplify domain association resource.
Provides an Amplify Domain Association resource.
---

# Resource: aws_amplify_domain_association

Provides an Amplify domain association resource.
Provides an Amplify Domain Association resource.

## Example Usage

```hcl
resource "aws_amplify_app" "app" {
```terraform
resource "aws_amplify_app" "example" {
name = "app"
// Setup redirect from https://example.com to https://www.example.com
custom_rules {
# Setup redirect from https://example.com to https://www.example.com
custom_rule {
source = "https://example.com"
status = "302"
target = "https://www.example.com"
}
}
resource "aws_amplify_branch" "master" {
app_id = "${aws_amplify_app.app.id}"
app_id = aws_amplify_app.example.id
branch_name = "master"
}
resource "aws_amplify_domain_association" "app" {
app_id = "${aws_amplify_app.app.id}"
resource "aws_amplify_domain_association" "example" {
app_id = aws_amplify_app.example.id
domain_name = "example.com"
// https://example.com
sub_domain_settings {
branch_name = "${aws_amplify_branch.master.branch_name}"
# https://example.com
sub_domain_setting {
branch_name = aws_amplify_branch.master.branch_name
prefix = ""
}
// https://www.example.com
sub_domain_settings {
branch_name = "${aws_amplify_branch.master.branch_name}"
# https://www.example.com
sub_domain_setting {
branch_name = aws_amplify_branch.master.branch_name
prefix = "www"
}
}
Expand All @@ -51,27 +51,26 @@ resource "aws_amplify_domain_association" "app" {

The following arguments are supported:

* `app_id` - (Required) Unique Id for an Amplify App.
* `domain_name` - (Required) Domain name for the Domain Association.
* `sub_domain_settings` - (Required) Setting structure for the Subdomain. A `sub_domain_settings` block is documented below.
* `enable_auto_sub_domain` - (Optional) Enables automated creation of Subdomains for branches. (Currently not supported)
* `app_id` - (Required) The unique ID for an Amplify app.
* `domain_name` - (Required) The domain name for the domain association.
* `sub_domain_setting` - (Required) The setting for the subdomain. Documented below.
* `wait_for_verification` - (Optional) If enabled, the resource will wait for the domain association status to change to PENDING_DEPLOYMENT or AVAILABLE. Setting this to false will skip the process. Default: true.

A `sub_domain_settings` block supports the following arguments:
The `sub_domain_setting` configuration block supports the following arguments:

* `branch_name` - (Required) Branch name setting for the Subdomain.
* `prefix` - (Required) Prefix setting for the Subdomain.
* `branch_name` - (Required) The branch name setting for the subdomain.
* `prefix` - (Required) The prefix setting for the subdomain.

## Attribute Reference
## Attributes Reference

The following attributes are exported:
In addition to all arguments above, the following attributes are exported:

* `arn` - ARN for the Domain Association.
* `arn` - The Amazon Resource Name (ARN) for the domain association.

## Import

Amplify domain association can be imported using `app_id` and `domain_name`, e.g.

```
$ terraform import aws_amplify_domain_association.app d2ypk4k47z8u6/domains/example.com
$ terraform import aws_amplify_domain_association.app d2ypk4k47z8u6/example.com
```

0 comments on commit c2d6be3

Please sign in to comment.