diff --git a/.changelog/27057.txt b/.changelog/27057.txt new file mode 100644 index 00000000000..6c2a244f578 --- /dev/null +++ b/.changelog/27057.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +data-source/aws_appmesh_virtual_gateway: Add new data-source for the aws_appmesh_virtual_gateway +``` diff --git a/GNUmakefile b/GNUmakefile index 7b8c16ed0bb..b2ab0c0a940 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -90,7 +90,7 @@ docs-lint: echo "Unexpected misspelling found in docs files."; \ echo "To automatically fix the misspelling, run 'make docs-lint-fix' and commit the changes."; \ exit 1) - @docker run --platform linux/amd64 --rm -v $(PWD):/markdown 06kellyjac/markdownlint-cli docs/ || (echo; \ + @docker run --rm -v $(PWD):/markdown 06kellyjac/markdownlint-cli docs/ || (echo; \ echo "Unexpected issues found in docs Markdown files."; \ echo "To apply any automatic fixes, run 'make docs-lint-fix' and commit the changes."; \ exit 1) @@ -319,7 +319,7 @@ website-lint: echo "Unexpected mispelling found in website files."; \ echo "To automatically fix the misspelling, run 'make website-lint-fix' and commit the changes."; \ exit 1) - @docker run --rm --platform linux/amd64 -v $(PWD):/markdown 06kellyjac/markdownlint-cli website/docs/ || (echo; \ + @docker run --rm -v $(PWD):/markdown 06kellyjac/markdownlint-cli website/docs/ || (echo; \ echo "Unexpected issues found in website Markdown files."; \ echo "To apply any automatic fixes, run 'make website-lint-fix' and commit the changes."; \ exit 1) diff --git a/internal/service/appmesh/service_package_gen.go b/internal/service/appmesh/service_package_gen.go index 144c11dec7e..68644616c74 100644 --- a/internal/service/appmesh/service_package_gen.go +++ b/internal/service/appmesh/service_package_gen.go @@ -25,6 +25,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceMesh, TypeName: "aws_appmesh_mesh", }, + { + Factory: DataSourceVirtualGateway, + TypeName: "aws_appmesh_virtual_gateway", + }, { Factory: DataSourceVirtualService, TypeName: "aws_appmesh_virtual_service", diff --git a/internal/service/appmesh/virtual_gateway_data_source.go b/internal/service/appmesh/virtual_gateway_data_source.go index b3f0450966e..2d8bbb8ffe9 100644 --- a/internal/service/appmesh/virtual_gateway_data_source.go +++ b/internal/service/appmesh/virtual_gateway_data_source.go @@ -5,19 +5,22 @@ package appmesh // know about it. import ( - "fmt" + "context" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/appmesh" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" ) +// @SDKDataSource("aws_appmesh_virtual_gateway") func DataSourceVirtualGateway() *schema.Resource { return &schema.Resource{ - Read: dataSourceVirtualGatewayRead, + ReadWithoutTimeout: dataSourceVirtualGatewayRead, Schema: map[string]*schema.Schema{ "name": { @@ -508,9 +511,9 @@ func DataSourceVirtualGateway() *schema.Resource { } -func dataSourceVirtualGatewayRead(d *schema.ResourceData, meta interface{}) error { - - conn := meta.(*conns.AWSClient).AppMeshConn +func dataSourceVirtualGatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).AppMeshConn() ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig req := &appmesh.DescribeVirtualGatewayInput{ @@ -521,10 +524,9 @@ func dataSourceVirtualGatewayRead(d *schema.ResourceData, meta interface{}) erro if v, ok := d.GetOk("mesh_owner"); ok { req.MeshOwner = aws.String(v.(string)) } - - resp, err := conn.DescribeVirtualGateway(req) + resp, err := conn.DescribeVirtualGatewayWithContext(ctx, req) if err != nil { - return fmt.Errorf("error reading App Mesh Virtual Gateway: %s", err) + return sdkdiag.AppendErrorf(diags, "error reading App Mesh Virtual Gateway: %s", err) } arn := aws.StringValue(resp.VirtualGateway.Metadata.Arn) @@ -541,17 +543,17 @@ func dataSourceVirtualGatewayRead(d *schema.ResourceData, meta interface{}) erro err = d.Set("spec", flattenVirtualGatewaySpec(resp.VirtualGateway.Spec)) if err != nil { - return fmt.Errorf("error setting spec: %s", err) + return sdkdiag.AppendErrorf(diags, "error setting spec: %s", err) } - tags, err := ListTags(conn, arn) + tags, err := ListTags(ctx, conn, arn) if err != nil { - return fmt.Errorf("error listing tags for App Mesh Virtual Service (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "error listing tags for App Mesh Virtual Service (%s): %s", arn, err) } if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "error setting tags: %s", err) } return nil diff --git a/internal/service/appmesh/virtual_gateway_data_source_test.go b/internal/service/appmesh/virtual_gateway_data_source_test.go index 96a334edf7a..36b879e0199 100644 --- a/internal/service/appmesh/virtual_gateway_data_source_test.go +++ b/internal/service/appmesh/virtual_gateway_data_source_test.go @@ -12,16 +12,17 @@ import ( ) func TestAccAppMeshVirtualGatewayDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_basic(rName, vgName), @@ -41,16 +42,17 @@ func TestAccAppMeshVirtualGatewayDataSource_basic(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_backendDefaults(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_backendDefaults(rName, vgName), @@ -72,16 +74,17 @@ func TestAccAppMeshVirtualGatewayDataSource_backendDefaults(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_backendDefaultsUpdated(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_backendDefaultsUpdated(rName, vgName), @@ -104,16 +107,17 @@ func TestAccAppMeshVirtualGatewayDataSource_backendDefaultsUpdated(t *testing.T) } func TestAccAppMeshVirtualGatewayDataSource_backendDefaultsCertificate(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_backendDefaultsCertificate(rName, vgName), @@ -137,16 +141,17 @@ func TestAccAppMeshVirtualGatewayDataSource_backendDefaultsCertificate(t *testin } func TestAccAppMeshVirtualGatewayDataSource_listenerConnectionPool(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_listenerConnectionPool(rName, vgName), @@ -167,16 +172,17 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerConnectionPool(t *testing.T) } func TestAccAppMeshVirtualGatewayDataSource_listenerConnectionPoolUpdated(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_listenerConnectionPoolUpdated(rName, vgName), @@ -198,16 +204,17 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerConnectionPoolUpdated(t *tes } func TestAccAppMeshVirtualGatewayDataSource_listenerHealthChecks(t *testing.T) { + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_listenerHealthChecks(rName, vgName), @@ -233,7 +240,7 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerHealthChecks(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_listenerTLSACM(t *testing.T) { - + ctx := acctest.Context(t) var ca acmpca.CertificateAuthority acmCAResourceName := "aws_acmpca_certificate_authority.test" domain := acctest.RandomDomainName() @@ -244,17 +251,17 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerTLSACM(t *testing.T) { vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ // We need to create and activate the CA before issuing a certificate. { Config: testAccVirtualGatewayDataSourceConfig_rootCA(domain), Check: resource.ComposeTestCheckFunc( - acctest.CheckACMPCACertificateAuthorityExists(acmCAResourceName, &ca), - acctest.CheckACMPCACertificateAuthorityActivateRootCA(&ca), + acctest.CheckACMPCACertificateAuthorityExists(ctx, acmCAResourceName, &ca), + acctest.CheckACMPCACertificateAuthorityActivateRootCA(ctx, &ca), ), }, { @@ -277,17 +284,17 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerTLSACM(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_listenerTLSFile(t *testing.T) { - + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_listenerTLSFile(rName, vgName), @@ -310,17 +317,17 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerTLSFile(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_listenerValidation(t *testing.T) { - + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_listenerValidation(rName, vgName), @@ -344,7 +351,7 @@ func TestAccAppMeshVirtualGatewayDataSource_listenerValidation(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_logging(t *testing.T) { - + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" @@ -352,10 +359,10 @@ func TestAccAppMeshVirtualGatewayDataSource_logging(t *testing.T) { path := "/tmp/access.log" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_logging(rName, vgName, path), @@ -376,17 +383,17 @@ func TestAccAppMeshVirtualGatewayDataSource_logging(t *testing.T) { } func TestAccAppMeshVirtualGatewayDataSource_tags(t *testing.T) { - + ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appmesh_virtual_gateway.test" dataSourceName := "data.aws_appmesh_virtual_gateway.test" vgName := fmt.Sprintf("tf-acc-test-%d-mesh-local", sdkacctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(appmesh.EndpointsID, t) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, appmesh.EndpointsID) }, ErrorCheck: acctest.ErrorCheck(t, appmesh.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckMeshDestroy, + CheckDestroy: testAccCheckMeshDestroy(ctx), Steps: []resource.TestStep{ { Config: testAccVirtualGatewayDataSourceConfig_tags(rName, vgName, "key1", "value1"), diff --git a/website/docs/d/appmesh_virtual_gateway.html.markdown b/website/docs/d/appmesh_virtual_gateway.html.markdown index d4196685a09..439597ff310 100644 --- a/website/docs/d/appmesh_virtual_gateway.html.markdown +++ b/website/docs/d/appmesh_virtual_gateway.html.markdown @@ -35,7 +35,6 @@ data "aws_appmesh_virtual_gateway" "test" { The following arguments are required: - * `name` - (Required) Name of the virtual gateway. * `mesh_name` - (Required) Name of the service mesh in which the virtual gateway exists. * `mesh_owner` - (Optional) AWS account ID of the service mesh's owner. @@ -44,7 +43,6 @@ The following arguments are required: In addition to all arguments above, the following attributes are exported: - * `arn` - ARN of the virtual gateway. * `created_date` - Creation date of the virtual gateway. * `last_updated_date` - Last update date of the virtual gateway.