Skip to content

Commit

Permalink
chore: refactor to latest SDK style
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsalmon committed Jan 17, 2023
1 parent b96a250 commit 6a4eda1
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 67 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/beevik/etree v1.1.0
github.com/google/go-cmp v0.5.9
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.20.0
github.com/hashicorp/aws-sdk-go-base v1.1.0
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.21
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.22
github.com/hashicorp/awspolicyequivalence v1.6.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkE
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.44.180 h1:VLZuAHI9fa/3WME5JjpVjcPCNfpGHVMiHx8sLHWhMgI=
github.com/aws/aws-sdk-go v1.44.180/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.16.3/go.mod h1:ytwTPBG6fXTZLxxeeCCWj2/EMYp/xDUgX+OET6TLNNU=
Expand Down Expand Up @@ -142,6 +143,7 @@ github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI
github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4=
github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand Down Expand Up @@ -173,6 +175,8 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.20.0 h1:xc1OYpWvNo6dhnzemfjwtbNxeu3Ag4Wr6yT8BOo0/q0=
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.20.0/go.mod h1:cdTE6F2pCKQobug+RqRaQp7Kz9hIEqiSvpPmb6E5G1w=
github.com/hashicorp/aws-sdk-go-base v1.1.0 h1:27urM3JAp6v+Oj/Ea5ULZwuFPK9cO1RUdEpV+rNdSAc=
github.com/hashicorp/aws-sdk-go-base v1.1.0/go.mod h1:2fRjWDv3jJBeN6mVWFHV6hFTNeFBx2gpDLQaZNxUVAY=
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.21 h1:kqzKaJ8bj/e9PEmBCWYxx77dLnIyd04V1Glt608XdCY=
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.21/go.mod h1:pWKwlzGC5N/VajQA21CRjoSDkTNMVL5iAJio4eRrAZU=
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.22 h1:YBfNDAQ67HR2LY5mWUP2GzGVPK8M41+SEo8QhurcdJM=
Expand Down Expand Up @@ -245,6 +249,7 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand Down Expand Up @@ -371,6 +376,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down
1 change: 0 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ func New(ctx context.Context) (*schema.Provider, error) {

"aws_fsx_openzfs_snapshot": fsx.DataSourceOpenzfsSnapshot(),

"aws_globalaccelerator_accelerator": globalaccelerator.DataSourceAccelerator(),
"aws_globalaccelerator_custom_routing_accelerator": globalaccelerator.DataSourceCustomRoutingAccelerator(),

"aws_glue_catalog_table": glue.DataSourceCatalogTable(),
Expand Down
53 changes: 39 additions & 14 deletions internal/service/globalaccelerator/custom_routing_accelerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ func ResourceCustomRoutingAccelerator() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"attributes": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"flow_logs_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"flow_logs_s3_bucket": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 255),
},
"flow_logs_s3_prefix": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 255),
},
},
},
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -90,7 +115,7 @@ func ResourceCustomRoutingAccelerator() *schema.Resource {
}

func resourceCustomRoutingAcceleratorCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))

Expand Down Expand Up @@ -120,7 +145,7 @@ func resourceCustomRoutingAcceleratorCreate(d *schema.ResourceData, meta interfa
}

if v, ok := d.GetOk("attributes"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input := expandGlobalAcceleratorUpdateAcceleratorAttributesInput(v.([]interface{})[0].(map[string]interface{}))
input := expandUpdateAcceleratorAttributesInput(v.([]interface{})[0].(map[string]interface{}))
input.AcceleratorArn = aws.String(d.Id())

log.Printf("[DEBUG] Updating Global Accelerator Accelerator attributes: %s", input)
Expand All @@ -137,7 +162,7 @@ func resourceCustomRoutingAcceleratorCreate(d *schema.ResourceData, meta interfa
}

func resourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

Expand All @@ -155,11 +180,11 @@ func resourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interface

d.Set("enabled", accelerator.Enabled)
d.Set("dns_name", accelerator.DnsName)
d.Set("hosted_zone_id", globalAcceleratorRoute53ZoneID)
d.Set("hosted_zone_id", route53ZoneID)
d.Set("name", accelerator.Name)
d.Set("ip_address_type", accelerator.IpAddressType)

if err := d.Set("ip_sets", flattenGlobalAcceleratorIpSets(accelerator.IpSets)); err != nil {
if err := d.Set("ip_sets", flattenIPSets(accelerator.IpSets)); err != nil {
return fmt.Errorf("error setting ip_sets: %w", err)
}

Expand All @@ -169,7 +194,7 @@ func resourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interface
return fmt.Errorf("error reading Global Accelerator Custom Routing Accelerator (%s) attributes: %w", d.Id(), err)
}

if err := d.Set("attributes", []interface{}{flattenGlobalAcceleratorCustomRoutingAcceleratorAttributes(acceleratorAttributes)}); err != nil {
if err := d.Set("attributes", []interface{}{flattenCustomRoutingAcceleratorAttributes(acceleratorAttributes)}); err != nil {
return fmt.Errorf("error setting attributes: %w", err)
}

Expand All @@ -193,7 +218,7 @@ func resourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interface
}

func resourceCustomRoutingAcceleratorUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn()

if d.HasChanges("name", "ip_address_type", "enabled") {
input := &globalaccelerator.UpdateCustomRoutingAcceleratorInput{
Expand All @@ -220,9 +245,9 @@ func resourceCustomRoutingAcceleratorUpdate(d *schema.ResourceData, meta interfa
o, n := d.GetChange("attributes")
if len(o.([]interface{})) > 0 && o.([]interface{})[0] != nil {
if len(n.([]interface{})) > 0 && n.([]interface{})[0] != nil {
oInput := expandGlobalAcceleratorUpdateCustomRoutingAcceleratorAttributesInput(o.([]interface{})[0].(map[string]interface{}))
oInput := expandUpdateCustomRoutingAcceleratorAttributesInput(o.([]interface{})[0].(map[string]interface{}))
oInput.AcceleratorArn = aws.String(d.Id())
nInput := expandGlobalAcceleratorUpdateCustomRoutingAcceleratorAttributesInput(n.([]interface{})[0].(map[string]interface{}))
nInput := expandUpdateCustomRoutingAcceleratorAttributesInput(n.([]interface{})[0].(map[string]interface{}))
nInput.AcceleratorArn = aws.String(d.Id())

// To change flow logs bucket and prefix attributes while flows are enabled, first disable flow logs.
Expand Down Expand Up @@ -263,7 +288,7 @@ func resourceCustomRoutingAcceleratorUpdate(d *schema.ResourceData, meta interfa
}

func resourceCustomRoutingAcceleratorDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn()

{
input := &globalaccelerator.UpdateCustomRoutingAcceleratorInput{
Expand Down Expand Up @@ -307,10 +332,10 @@ func resourceCustomRoutingAcceleratorDelete(d *schema.ResourceData, meta interfa
return nil
}

func expandGlobalAcceleratorUpdateCustomRoutingAcceleratorAttributesInput(tfMap map[string]interface{}) *globalaccelerator.UpdateCustomRoutingAcceleratorAttributesInput {
return (*globalaccelerator.UpdateCustomRoutingAcceleratorAttributesInput)(expandGlobalAcceleratorUpdateAcceleratorAttributesInput(tfMap))
func expandUpdateCustomRoutingAcceleratorAttributesInput(tfMap map[string]interface{}) *globalaccelerator.UpdateCustomRoutingAcceleratorAttributesInput {
return (*globalaccelerator.UpdateCustomRoutingAcceleratorAttributesInput)(expandUpdateAcceleratorAttributesInput(tfMap))
}

func flattenGlobalAcceleratorCustomRoutingAcceleratorAttributes(apiObject *globalaccelerator.CustomRoutingAcceleratorAttributes) map[string]interface{} {
return flattenGlobalAcceleratorAcceleratorAttributes((*globalaccelerator.AcceleratorAttributes)(apiObject))
func flattenCustomRoutingAcceleratorAttributes(apiObject *globalaccelerator.CustomRoutingAcceleratorAttributes) map[string]interface{} {
return flattenAcceleratorAttributes((*globalaccelerator.AcceleratorAttributes)(apiObject))
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func DataSourceCustomRoutingAccelerator() *schema.Resource {
}

func dataSourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn
conn := meta.(*conns.AWSClient).GlobalAcceleratorConn()
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

var results []*globalaccelerator.CustomRoutingAccelerator
Expand Down Expand Up @@ -127,17 +127,17 @@ func dataSourceCustomRoutingAcceleratorRead(d *schema.ResourceData, meta interfa
d.Set("arn", accelerator.AcceleratorArn)
d.Set("enabled", accelerator.Enabled)
d.Set("dns_name", accelerator.DnsName)
d.Set("hosted_zone_id", globalAcceleratorRoute53ZoneID)
d.Set("hosted_zone_id", route53ZoneID)
d.Set("name", accelerator.Name)
d.Set("ip_address_type", accelerator.IpAddressType)
d.Set("ip_sets", flattenGlobalAcceleratorIpSets(accelerator.IpSets))
d.Set("ip_sets", flattenIPSets(accelerator.IpSets))

acceleratorAttributes, err := FindCustomRoutingAcceleratorAttributesByARN(conn, d.Id())
if err != nil {
return fmt.Errorf("error reading Global Accelerator Custom Routing Accelerator (%s) attributes: %w", d.Id(), err)
}

if err := d.Set("attributes", []interface{}{flattenGlobalAcceleratorCustomRoutingAcceleratorAttributes(acceleratorAttributes)}); err != nil {
if err := d.Set("attributes", []interface{}{flattenCustomRoutingAcceleratorAttributes(acceleratorAttributes)}); err != nil {
return fmt.Errorf("error setting attributes: %w", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TestAccGlobalAcceleratorCustomRoutingAcceleratorDataSource_basic(t *testing
dataSourceName2 := "data.aws_globalaccelerator_custom_routing_accelerator.test_by_name"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheckGlobalAccelerator(t) },
ErrorCheck: acctest.ErrorCheck(t, globalaccelerator.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckGlobalAcceleratorCustomRoutingAcceleratorDestroy,
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, globalaccelerator.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckGlobalAcceleratorCustomRoutingAcceleratorDestroy,
Steps: []resource.TestStep{
{
Config: testAccGlobalAcceleratorCustomRoutingAcceleratorDataSourceConfig(resourceName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestAccGlobalAcceleratorCustomRoutingAccelerator_basic(t *testing.T) {
dnsNameRegex := regexp.MustCompile(`^a[a-f0-9]{16}\.awsglobalaccelerator\.com$`)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheckGlobalAccelerator(t) },
ErrorCheck: acctest.ErrorCheck(t, globalaccelerator.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckGlobalAcceleratorCustomRoutingAcceleratorDestroy,
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, globalaccelerator.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckGlobalAcceleratorCustomRoutingAcceleratorDestroy,
Steps: []resource.TestStep{
{
Config: testAccGlobalAcceleratorCustomRoutingAcceleratorConfig(rName),
Expand Down Expand Up @@ -62,7 +62,7 @@ resource "aws_globalaccelerator_custom_routing_accelerator" "test" {

func testAccCheckGlobalAcceleratorCustomRoutingAcceleratorExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).GlobalAcceleratorConn
conn := acctest.Provider.Meta().(*conns.AWSClient).GlobalAcceleratorConn()

rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -84,7 +84,7 @@ func testAccCheckGlobalAcceleratorCustomRoutingAcceleratorExists(name string) re
}

func testAccCheckGlobalAcceleratorCustomRoutingAcceleratorDestroy(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).GlobalAcceleratorConn
conn := acctest.Provider.Meta().(*conns.AWSClient).GlobalAcceleratorConn()

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_globalaccelerator_custom_routing_accelerator" {
Expand Down

0 comments on commit 6a4eda1

Please sign in to comment.