Skip to content

Commit

Permalink
Refactor resources to new formating after hashicorp#21306
Browse files Browse the repository at this point in the history
  • Loading branch information
abebars committed Oct 29, 2021
1 parent 47a62db commit 3c53e68
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 329 deletions.
62 changes: 0 additions & 62 deletions aws/internal/service/connect/waiter/waiter.go

This file was deleted.

4 changes: 4 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ func Provider() *schema.Provider {

"aws_cognito_user_pools": cognitoidp.DataSourceUserPools(),

"aws_connect_bot_association": connect.DataSourceBotAssociation(),
"aws_connect_contact_flow": connect.DataSourceContactFlow(),
"aws_connect_instance": connect.DataSourceInstance(),
"aws_connect_lambda_function_association": connect.DataSourceLambdaFunctionAssociation(),

"aws_cur_report_definition": cur.DataSourceReportDefinition(),

Expand Down Expand Up @@ -926,8 +928,10 @@ func Provider() *schema.Provider {
"aws_config_organization_managed_rule": config.ResourceOrganizationManagedRule(),
"aws_config_remediation_configuration": config.ResourceRemediationConfiguration(),

"aws_connect_bot_association": connect.ResourceBotAssociation(),
"aws_connect_contact_flow": connect.ResourceContactFlow(),
"aws_connect_instance": connect.ResourceInstance(),
"aws_connect_lambda_function_association": connect.ResourceLambdaFunctionAssociation(),

"aws_cur_report_definition": cur.ResourceReportDefinition(),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aws
package connect

import (
"context"
Expand All @@ -14,21 +14,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
tfconnect "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect/waiter"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func resourceAwsConnectBotAssociation() *schema.Resource {
func ResourceBotAssociation() *schema.Resource {
return &schema.Resource{
CreateContext: resourceAwsConnectBotAssociationCreate,
ReadContext: resourceAwsConnectBotAssociationRead,
UpdateContext: resourceAwsConnectBotAssociationRead,
DeleteContext: resourceAwsConnectBotAssociationDelete,
CreateContext: resourceBotAssociationCreate,
ReadContext: resourceBotAssociationRead,
UpdateContext: resourceBotAssociationRead,
DeleteContext: resourceBotAssociationDelete,
Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
instanceID, name, region, err := resourceAwsConnectBotV1AssociationParseID(d.Id())
instanceID, name, region, err := resourceBotV1AssociationParseID(d.Id())
if err != nil {
return nil, err
}
Expand All @@ -41,8 +39,8 @@ func resourceAwsConnectBotAssociation() *schema.Resource {
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(waiter.ConnectBotAssociationCreateTimeout),
Delete: schema.DefaultTimeout(waiter.ConnectBotAssociationDeleteTimeout),
Create: schema.DefaultTimeout(connectBotAssociationCreateTimeout),
Delete: schema.DefaultTimeout(connectBotAssociationDeleteTimeout),
},
Schema: map[string]*schema.Schema{
/*
Expand Down Expand Up @@ -85,8 +83,8 @@ func resourceAwsConnectBotAssociation() *schema.Resource {
}
}

func resourceAwsConnectBotAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*AWSClient).connectconn
func resourceBotAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).ConnectConn

input := &connect.AssociateBotInput{
InstanceId: aws.String(d.Get("instance_id").(string)),
Expand Down Expand Up @@ -131,17 +129,17 @@ func resourceAwsConnectBotAssociationCreate(ctx context.Context, d *schema.Resou
}

d.SetId(lbaId)
return resourceAwsConnectBotAssociationRead(ctx, d, meta)
return resourceBotAssociationRead(ctx, d, meta)
}

func resourceAwsConnectBotAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*AWSClient).connectconn
func resourceBotAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).ConnectConn
instanceID := d.Get("instance_id")
name := d.Get("bot_name")

lexBot, err := finder.BotAssociationV1ByNameWithContext(ctx, conn, instanceID.(string), name.(string))
lexBot, err := FindBotAssociationV1ByNameWithContext(ctx, conn, instanceID.(string), name.(string))

if isAWSErr(err, tfconnect.BotAssociationStatusNotFound, "") || errors.Is(err, tfresource.ErrEmptyResult) {
if tfawserr.ErrMessageContains(err, BotAssociationStatusNotFound, "") || errors.Is(err, tfresource.ErrEmptyResult) {
log.Printf("[WARN] Connect Bot V1 Association (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
Expand Down Expand Up @@ -177,10 +175,10 @@ func resourceAwsConnectBotAssociationRead(ctx context.Context, d *schema.Resourc
return nil
}

func resourceAwsConnectBotAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*AWSClient).connectconn
func resourceBotAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).ConnectConn

instanceID, name, region, err := resourceAwsConnectBotV1AssociationParseID(d.Id())
instanceID, name, region, err := resourceBotV1AssociationParseID(d.Id())

if err != nil {
return diag.FromErr(err)
Expand All @@ -205,7 +203,7 @@ func resourceAwsConnectBotAssociationDelete(ctx context.Context, d *schema.Resou
return nil
}

func resourceAwsConnectBotV1AssociationParseID(id string) (string, string, string, error) {
func resourceBotV1AssociationParseID(id string) (string, string, string, error) {
parts := strings.SplitN(id, ":", 3)

if len(parts) != 3 || parts[0] == "" || parts[1] == "" || parts[2] == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aws
package connect

import (
"context"
Expand All @@ -7,10 +7,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect/finder"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

func dataSourceAwsConnectBotAssociation() *schema.Resource {
func DataSourceBotAssociation() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAwsConnectLexBotAssociationRead,
Schema: map[string]*schema.Schema{
Expand All @@ -33,11 +33,11 @@ func dataSourceAwsConnectBotAssociation() *schema.Resource {
}

func dataSourceAwsConnectLexBotAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*AWSClient).connectconn
conn := meta.(*conns.AWSClient).ConnectConn
instanceID := d.Get("instance_id")
name := d.Get("bot_name")

lexBot, err := finder.BotAssociationV1ByNameWithContext(ctx, conn, instanceID.(string), name.(string))
lexBot, err := FindBotAssociationV1ByNameWithContext(ctx, conn, instanceID.(string), name.(string))
if err != nil {
return diag.FromErr(fmt.Errorf("error finding Connect Bot V1 Association by name (%s): %w", name, err))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aws
package connect

import (
"context"
Expand All @@ -8,28 +8,29 @@ import (
"testing"

"github.com/aws/aws-sdk-go/service/connect"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
sdkacctest "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"
tfconnect "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/connect/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func TestAccAwsConnectBotAssociationDataSource_basic(t *testing.T) {
rName := acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)
rName2 := acctest.RandomWithPrefix("resource-test-terraform")
func TestAccBotAssociationDataSource_basic(t *testing.T) {
rName := sdkacctest.RandStringFromCharSet(8, sdkacctest.CharSetAlpha)
rName2 := sdkacctest.RandomWithPrefix("resource-test-terraform")
resourceName := "aws_connect_bot_association.test"
datasourceName := "data.aws_connect_bot_association.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, connect.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccAwsConnectBotAssociationDataSourceDestroy,
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccBotAssociationDataSourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsConnectBotAssociationDataSourceConfigBasic(rName, rName2),
Config: testAccBotAssociationDataSourceConfigBasic(rName, rName2),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "instance_id", resourceName, "instance_id"),
resource.TestCheckResourceAttrPair(datasourceName, "bot_name", resourceName, "bot_name"),
Expand All @@ -40,7 +41,7 @@ func TestAccAwsConnectBotAssociationDataSource_basic(t *testing.T) {
})
}

func testAccAwsConnectBotAssociationDataSourceDestroy(s *terraform.State) error {
func testAccBotAssociationDataSourceDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_connect_bot_association" {
continue
Expand All @@ -49,16 +50,16 @@ func testAccAwsConnectBotAssociationDataSourceDestroy(s *terraform.State) error
if rs.Primary.ID == "" {
return fmt.Errorf("Connect Connect Bot V1 Association ID not set")
}
instanceID, name, _, err := resourceAwsConnectBotV1AssociationParseID(rs.Primary.ID)
instanceID, name, _, err := resourceBotV1AssociationParseID(rs.Primary.ID)
if err != nil {
return err
}

conn := testAccProvider.Meta().(*AWSClient).connectconn
conn := acctest.Provider.Meta().(*conns.AWSClient).ConnectConn

lexBot, err := finder.BotAssociationV1ByNameWithContext(context.Background(), conn, instanceID, name)
lexBot, err := FindBotAssociationV1ByNameWithContext(context.Background(), conn, instanceID, name)

if isAWSErr(err, tfconnect.BotAssociationStatusNotFound, "") || errors.Is(err, tfresource.ErrEmptyResult) {
if tfawserr.ErrCodeEquals(err, BotAssociationStatusNotFound, "") || errors.Is(err, tfresource.ErrEmptyResult) {
log.Printf("[DEBUG] Connect Bot V1 Association (%s) not found, has been removed from state", name)
return nil
}
Expand All @@ -74,7 +75,7 @@ func testAccAwsConnectBotAssociationDataSourceDestroy(s *terraform.State) error
return nil
}

func testAccAwsConnectBotAssociationDataSourceBaseConfig(rName string, rName2 string) string {
func testAccBotAssociationDataSourceBaseConfig(rName string, rName2 string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
Expand Down Expand Up @@ -127,8 +128,8 @@ resource "aws_connect_bot_association" "test" {
`, rName, rName2)
}

func testAccAwsConnectBotAssociationDataSourceConfigBasic(rName string, rName2 string) string {
return fmt.Sprintf(testAccAwsConnectBotAssociationDataSourceBaseConfig(rName, rName2) + `
func testAccBotAssociationDataSourceConfigBasic(rName string, rName2 string) string {
return fmt.Sprintf(testAccBotAssociationDataSourceBaseConfig(rName, rName2) + `
data "aws_connect_bot_association" "test" {
instance_id = aws_connect_instance.test.id
bot_name = aws_connect_bot_association.test.bot_name
Expand Down
Loading

0 comments on commit 3c53e68

Please sign in to comment.