-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22487 from DrFaust92/appsync_domain_name
r/appsync_domain_name + association resources
- Loading branch information
Showing
13 changed files
with
993 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:new-resource | ||
aws_appsync_domain_name | ||
``` | ||
|
||
```release-note:new-resource | ||
aws_appsync_domain_name_api_association | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package appsync | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appsync" | ||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/tfresource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/verify" | ||
) | ||
|
||
func ResourceDomainName() *schema.Resource { | ||
|
||
return &schema.Resource{ | ||
Create: resourceDomainNameCreate, | ||
Read: resourceDomainNameRead, | ||
Update: resourceDomainNameUpdate, | ||
Delete: resourceDomainNameDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"appsync_domain_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"certificate_arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: verify.ValidARN, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"domain_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"hosted_zone_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceDomainNameCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
params := &appsync.CreateDomainNameInput{ | ||
CertificateArn: aws.String(d.Get("certificate_arn").(string)), | ||
Description: aws.String(d.Get("description").(string)), | ||
DomainName: aws.String(d.Get("domain_name").(string)), | ||
} | ||
|
||
resp, err := conn.CreateDomainName(params) | ||
if err != nil { | ||
return fmt.Errorf("error creating Appsync Domain Name: %w", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(resp.DomainNameConfig.DomainName)) | ||
|
||
return resourceDomainNameRead(d, meta) | ||
} | ||
|
||
func resourceDomainNameRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
domainName, err := FindDomainNameByID(conn, d.Id()) | ||
if domainName == nil && !d.IsNewResource() { | ||
log.Printf("[WARN] AppSync Domain Name (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Appsync Domain Name %q: %w", d.Id(), err) | ||
} | ||
|
||
d.Set("domain_name", domainName.DomainName) | ||
d.Set("description", domainName.Description) | ||
d.Set("certificate_arn", domainName.CertificateArn) | ||
d.Set("hosted_zone_id", domainName.HostedZoneId) | ||
d.Set("appsync_domain_name", domainName.AppsyncDomainName) | ||
|
||
return nil | ||
} | ||
|
||
func resourceDomainNameUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
params := &appsync.UpdateDomainNameInput{ | ||
DomainName: aws.String(d.Id()), | ||
} | ||
|
||
if d.HasChange("description") { | ||
params.Description = aws.String(d.Get("description").(string)) | ||
} | ||
|
||
_, err := conn.UpdateDomainName(params) | ||
if err != nil { | ||
return fmt.Errorf("error updating Appsync Domain Name %q: %w", d.Id(), err) | ||
} | ||
|
||
return resourceDomainNameRead(d, meta) | ||
|
||
} | ||
|
||
func resourceDomainNameDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
input := &appsync.DeleteDomainNameInput{ | ||
DomainName: aws.String(d.Id()), | ||
} | ||
|
||
err := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||
_, err := conn.DeleteDomainName(input) | ||
if tfawserr.ErrCodeEquals(err, appsync.ErrCodeConcurrentModificationException) { | ||
return resource.RetryableError(fmt.Errorf("deleting Appsync Domain Name %q: %w", d.Id(), err)) | ||
} | ||
if err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
return nil | ||
}) | ||
if tfresource.TimedOut(err) { | ||
_, err = conn.DeleteDomainName(input) | ||
} | ||
if err != nil { | ||
return fmt.Errorf("error deleting Appsync Domain Name %q: %w", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
120 changes: 120 additions & 0 deletions
120
internal/service/appsync/domain_name_api_association.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package appsync | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appsync" | ||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
) | ||
|
||
func ResourceDomainNameApiAssociation() *schema.Resource { | ||
|
||
return &schema.Resource{ | ||
Create: resourceDomainNameApiAssociationCreate, | ||
Read: resourceDomainNameApiAssociationRead, | ||
Update: resourceDomainNameApiAssociationUpdate, | ||
Delete: resourceDomainNameApiAssociationDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"api_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"domain_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceDomainNameApiAssociationCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
params := &appsync.AssociateApiInput{ | ||
ApiId: aws.String(d.Get("api_id").(string)), | ||
DomainName: aws.String(d.Get("domain_name").(string)), | ||
} | ||
|
||
resp, err := conn.AssociateApi(params) | ||
if err != nil { | ||
return fmt.Errorf("error creating Appsync Domain Name API Association: %w", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(resp.ApiAssociation.DomainName)) | ||
|
||
if err := waitDomainNameApiAssociation(conn, d.Id()); err != nil { | ||
return fmt.Errorf("error waiting for Appsync Domain Name API (%s) Association: %w", d.Id(), err) | ||
} | ||
|
||
return resourceDomainNameApiAssociationRead(d, meta) | ||
} | ||
|
||
func resourceDomainNameApiAssociationRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
association, err := FindDomainNameApiAssociationByID(conn, d.Id()) | ||
if association == nil && !d.IsNewResource() { | ||
log.Printf("[WARN] Appsync Domain Name API Association (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Appsync Domain Name API Association %q: %w", d.Id(), err) | ||
} | ||
|
||
d.Set("domain_name", association.DomainName) | ||
d.Set("api_id", association.ApiId) | ||
|
||
return nil | ||
} | ||
|
||
func resourceDomainNameApiAssociationUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
params := &appsync.AssociateApiInput{ | ||
ApiId: aws.String(d.Get("api_id").(string)), | ||
DomainName: aws.String(d.Get("domain_name").(string)), | ||
} | ||
|
||
_, err := conn.AssociateApi(params) | ||
if err != nil { | ||
return fmt.Errorf("error creating Appsync Domain Name API Association: %w", err) | ||
} | ||
|
||
if err := waitDomainNameApiAssociation(conn, d.Id()); err != nil { | ||
return fmt.Errorf("error waiting for Appsync Domain Name API (%s) Association: %w", d.Id(), err) | ||
} | ||
|
||
return resourceDomainNameApiAssociationRead(d, meta) | ||
} | ||
|
||
func resourceDomainNameApiAssociationDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).AppSyncConn | ||
|
||
input := &appsync.DisassociateApiInput{ | ||
DomainName: aws.String(d.Id()), | ||
} | ||
_, err := conn.DisassociateApi(input) | ||
if err != nil { | ||
if tfawserr.ErrCodeEquals(err, appsync.ErrCodeNotFoundException) { | ||
return nil | ||
} | ||
return fmt.Errorf("error deleting Appsync Domain Name API Association: %w", err) | ||
} | ||
|
||
if err := waitDomainNameApiDisassociation(conn, d.Id()); err != nil { | ||
return fmt.Errorf("error waiting for Appsync Domain Name API (%s) Disassociation: %w", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.