From af065742192acbccae76a79a3cd1ab33f714ff47 Mon Sep 17 00:00:00 2001 From: Lukas Hetzenecker Date: Fri, 24 Feb 2023 17:04:35 +0100 Subject: [PATCH 1/7] EC2: Add transitgateway_attachments Data Source --- internal/provider/provider.go | 1 + .../transitgateway_attachments_data_source.go | 68 ++++++ ...sitgateway_attachments_data_source_test.go | 208 ++++++++++++++++++ ...2_transitgateway_attachments.html.markdown | 37 ++++ 4 files changed, 314 insertions(+) create mode 100644 internal/service/ec2/transitgateway_attachments_data_source.go create mode 100644 internal/service/ec2/transitgateway_attachments_data_source_test.go create mode 100644 website/docs/d/ec2_transitgateway_attachments.html.markdown diff --git a/internal/provider/provider.go b/internal/provider/provider.go index da22cae1fdb9..0cc810ff870f 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -564,6 +564,7 @@ func New(ctx context.Context) (*schema.Provider, error) { "aws_ec2_spot_price": ec2.DataSourceSpotPrice(), "aws_ec2_transit_gateway": ec2.DataSourceTransitGateway(), "aws_ec2_transit_gateway_attachment": ec2.DataSourceTransitGatewayAttachment(), + "aws_ec2_transit_gateway_attachments": ec2.DataSourceTransitGatewayAttachments(), "aws_ec2_transit_gateway_connect": ec2.DataSourceTransitGatewayConnect(), "aws_ec2_transit_gateway_connect_peer": ec2.DataSourceTransitGatewayConnectPeer(), "aws_ec2_transit_gateway_dx_gateway_attachment": ec2.DataSourceTransitGatewayDxGatewayAttachment(), diff --git a/internal/service/ec2/transitgateway_attachments_data_source.go b/internal/service/ec2/transitgateway_attachments_data_source.go new file mode 100644 index 000000000000..dae9cc200963 --- /dev/null +++ b/internal/service/ec2/transitgateway_attachments_data_source.go @@ -0,0 +1,68 @@ +package ec2 + +import ( + "context" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "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" +) + +func DataSourceTransitGatewayAttachments() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourceTransitGatewayAttachmentsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(20 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter": DataSourceFiltersSchema(), + "tags": tftags.TagsSchemaComputed(), + }, + } +} + +func dataSourceTransitGatewayAttachmentsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).EC2Conn() + + input := &ec2.DescribeTransitGatewayAttachmentsInput{} + + input.Filters = append(input.Filters, BuildCustomFilterList( + d.Get("filter").(*schema.Set), + )...) + + if v, ok := d.GetOk("tags"); ok { + input.Filters = append(input.Filters, BuildTagFilterList( + Tags(tftags.New(ctx, v.(map[string]interface{}))), + )...) + } + + transitGatewayAttachments, err := FindTransitGatewayAttachments(ctx, conn, input) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading EC2 Transit Gateway Attachments: %s", err) + } + + var attachmentIDs []string + + for _, v := range transitGatewayAttachments { + attachmentIDs = append(attachmentIDs, aws.StringValue(v.TransitGatewayAttachmentId)) + } + + d.SetId(meta.(*conns.AWSClient).Region) + d.Set("ids", attachmentIDs) + + return diags +} diff --git a/internal/service/ec2/transitgateway_attachments_data_source_test.go b/internal/service/ec2/transitgateway_attachments_data_source_test.go new file mode 100644 index 000000000000..095d8d43a410 --- /dev/null +++ b/internal/service/ec2/transitgateway_attachments_data_source_test.go @@ -0,0 +1,208 @@ +package ec2_test +// **PLEASE DELETE THIS AND ALL TIP COMMENTS BEFORE SUBMITTING A PR FOR REVIEW!** +// +// TIP: ==== INTRODUCTION ==== +// Thank you for trying the skaff tool! +// +// You have opted to include these helpful comments. They all include "TIP:" +// to help you find and remove them when you're done with them. +// +// While some aspects of this file are customized to your input, the +// scaffold tool does *not* look at the AWS API and ensure it has correct +// function, structure, and variable names. It makes guesses based on +// commonalities. You will need to make significant adjustments. +// +// In other words, as generated, this is a rough outline of the work you will +// need to do. If something doesn't make sense for your situation, get rid of +// it. +// +// Remember to register this new data source in the provider +// (internal/provider/provider.go) once you finish. Otherwise, Terraform won't +// know about it. + +import ( + // TIP: ==== IMPORTS ==== + // This is a common set of imports but not customized to your code since + // your code hasn't been written yet. Make sure you, your IDE, or + // goimports -w fixes these imports. + // + // The provider linter wants your imports to be in two groups: first, + // standard library (i.e., "fmt" or "strings"), second, everything else. + // + // Also, AWS Go SDK v2 may handle nested structures differently than v1, + // using the services/ec2/types package. If so, you'll + // need to import types and reference the nested types, e.g., as + // types.. + "fmt" + "regexp" + "strings" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/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/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + + // TIP: You will often need to import the package that this test file lives + // in. Since it is in the "test" context, it must import the package to use + // any normal context constants, variables, or functions. + tfec2 "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// TIP: File Structure. The basic outline for all test files should be as +// follows. Improve this data source's maintainability by following this +// outline. +// +// 1. Package declaration (add "_test" since this is a test file) +// 2. Imports +// 3. Unit tests +// 4. Basic test +// 5. Disappears test +// 6. All the other tests +// 7. Helper functions (exists, destroy, check, etc.) +// 8. Functions that return Terraform configurations + + +// TIP: ==== UNIT TESTS ==== +// This is an example of a unit test. Its name is not prefixed with +// "TestAcc" like an acceptance test. +// +// Unlike acceptance tests, unit tests do not access AWS and are focused on a +// function (or method). Because of this, they are quick and cheap to run. +// +// In designing a data source's implementation, isolate complex bits from AWS bits +// so that they can be tested through a unit test. We encourage more unit tests +// in the provider. +// +// Cut and dry functions using well-used patterns, like typical flatteners and +// expanders, don't need unit testing. However, if they are complex or +// intricate, they should be unit tested. +func TestTransitgatewayAttachmentsExampleUnitTest(t *testing.T) { + testCases := []struct { + TestName string + Input string + Expected string + Error bool + }{ + { + TestName: "empty", + Input: "", + Expected: "", + Error: true, + }, + { + TestName: "descriptive name", + Input: "some input", + Expected: "some output", + Error: false, + }, + { + TestName: "another descriptive name", + Input: "more input", + Expected: "more output", + Error: false, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.TestName, func(t *testing.T) { + got, err := tfec2.FunctionFromDataSource(testCase.Input) + + if err != nil && !testCase.Error { + t.Errorf("got error (%s), expected no error", err) + } + + if err == nil && testCase.Error { + t.Errorf("got (%s) and no error, expected error", got) + } + + if got != testCase.Expected { + t.Errorf("got %s, expected %s", got, testCase.Expected) + } + }) + } +} + + +// TIP: ==== ACCEPTANCE TESTS ==== +// This is an example of a basic acceptance test. This should test as much of +// standard functionality of the data source as possible, and test importing, if +// applicable. We prefix its name with "TestAcc", the service, and the +// data source name. +// +// Acceptance test access AWS and cost money to run. +func TestAccEC2TransitgatewayAttachmentsDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + // TIP: This is a long-running test guard for tests that run longer than + // 300s (5 min) generally. + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var transitgatewayattachments ec2.DescribeTransitgatewayAttachmentsResponse + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_ec2_transitgateway_attachments.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(ec2.EndpointsID, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2EndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckTransitgatewayAttachmentsDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccTransitgatewayAttachmentsDataSourceConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckTransitgatewayAttachmentsExists(ctx, dataSourceName, &transitgatewayattachments), + resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), + resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), + resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ + "console_access": "false", + "groups.#": "0", + "username": "Test", + "password": "TestTest1234", + }), + acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "ec2", regexp.MustCompile(`transitgatewayattachments:+.`)), + ), + }, + }, + }) +} + +func testAccTransitgatewayAttachmentsDataSourceConfig_basic(rName, version string) string { + return fmt.Sprintf(` +data "aws_security_group" "test" { + name = %[1]q +} + +data "aws_ec2_transitgateway_attachments" "test" { + transitgateway_attachments_name = %[1]q + engine_type = "ActiveEC2" + engine_version = %[2]q + host_instance_type = "ec2.t2.micro" + security_groups = [aws_security_group.test.id] + authentication_strategy = "simple" + storage_type = "efs" + + logs { + general = true + } + + user { + username = "Test" + password = "TestTest1234" + } +} +`, rName, version) +} diff --git a/website/docs/d/ec2_transitgateway_attachments.html.markdown b/website/docs/d/ec2_transitgateway_attachments.html.markdown new file mode 100644 index 000000000000..0eb84aa70c55 --- /dev/null +++ b/website/docs/d/ec2_transitgateway_attachments.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "EC2 (Elastic Compute Cloud)" +layout: "aws" +page_title: "AWS: aws_ec2_transitgateway_attachments" +description: |- + Terraform data source for managing an AWS EC2 (Elastic Compute Cloud) Transitgateway Attachments. +--- + +# Data Source: aws_ec2_transitgateway_attachments + +Terraform data source for managing an AWS EC2 (Elastic Compute Cloud) Transitgateway Attachments. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_ec2_transitgateway_attachments" "example" { +} +``` + +## Argument Reference + +The following arguments are required: + +* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +The following arguments are optional: + +* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - ARN of the Transitgateway Attachments. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. From 47ac68756dbbc87f390f809335d77f74c7600167 Mon Sep 17 00:00:00 2001 From: Lukas Hetzenecker Date: Fri, 24 Feb 2023 20:43:12 +0100 Subject: [PATCH 2/7] Add tests and documentation --- .../transitgateway_attachments_data_source.go | 2 +- ...sitgateway_attachments_data_source_test.go | 214 ++++-------------- ..._transit_gateway_attachments.html.markdown | 60 +++++ 3 files changed, 99 insertions(+), 177 deletions(-) create mode 100644 website/docs/d/ec2_transit_gateway_attachments.html.markdown diff --git a/internal/service/ec2/transitgateway_attachments_data_source.go b/internal/service/ec2/transitgateway_attachments_data_source.go index dae9cc200963..98421cd669c4 100644 --- a/internal/service/ec2/transitgateway_attachments_data_source.go +++ b/internal/service/ec2/transitgateway_attachments_data_source.go @@ -27,7 +27,7 @@ func DataSourceTransitGatewayAttachments() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "filter": DataSourceFiltersSchema(), + "filter": CustomFiltersSchema(), "tags": tftags.TagsSchemaComputed(), }, } diff --git a/internal/service/ec2/transitgateway_attachments_data_source_test.go b/internal/service/ec2/transitgateway_attachments_data_source_test.go index 095d8d43a410..8c99b4bba616 100644 --- a/internal/service/ec2/transitgateway_attachments_data_source_test.go +++ b/internal/service/ec2/transitgateway_attachments_data_source_test.go @@ -1,208 +1,70 @@ package ec2_test -// **PLEASE DELETE THIS AND ALL TIP COMMENTS BEFORE SUBMITTING A PR FOR REVIEW!** -// -// TIP: ==== INTRODUCTION ==== -// Thank you for trying the skaff tool! -// -// You have opted to include these helpful comments. They all include "TIP:" -// to help you find and remove them when you're done with them. -// -// While some aspects of this file are customized to your input, the -// scaffold tool does *not* look at the AWS API and ensure it has correct -// function, structure, and variable names. It makes guesses based on -// commonalities. You will need to make significant adjustments. -// -// In other words, as generated, this is a rough outline of the work you will -// need to do. If something doesn't make sense for your situation, get rid of -// it. -// -// Remember to register this new data source in the provider -// (internal/provider/provider.go) once you finish. Otherwise, Terraform won't -// know about it. import ( - // TIP: ==== IMPORTS ==== - // This is a common set of imports but not customized to your code since - // your code hasn't been written yet. Make sure you, your IDE, or - // goimports -w fixes these imports. - // - // The provider linter wants your imports to be in two groups: first, - // standard library (i.e., "fmt" or "strings"), second, everything else. - // - // Also, AWS Go SDK v2 may handle nested structures differently than v1, - // using the services/ec2/types package. If so, you'll - // need to import types and reference the nested types, e.g., as - // types.. "fmt" - "regexp" - "strings" "testing" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2/types" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go/service/ec2" 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/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" - - // TIP: You will often need to import the package that this test file lives - // in. Since it is in the "test" context, it must import the package to use - // any normal context constants, variables, or functions. - tfec2 "github.com/hashicorp/terraform-provider-aws/internal/service/ec2" - "github.com/hashicorp/terraform-provider-aws/names" ) -// TIP: File Structure. The basic outline for all test files should be as -// follows. Improve this data source's maintainability by following this -// outline. -// -// 1. Package declaration (add "_test" since this is a test file) -// 2. Imports -// 3. Unit tests -// 4. Basic test -// 5. Disappears test -// 6. All the other tests -// 7. Helper functions (exists, destroy, check, etc.) -// 8. Functions that return Terraform configurations - - -// TIP: ==== UNIT TESTS ==== -// This is an example of a unit test. Its name is not prefixed with -// "TestAcc" like an acceptance test. -// -// Unlike acceptance tests, unit tests do not access AWS and are focused on a -// function (or method). Because of this, they are quick and cheap to run. -// -// In designing a data source's implementation, isolate complex bits from AWS bits -// so that they can be tested through a unit test. We encourage more unit tests -// in the provider. -// -// Cut and dry functions using well-used patterns, like typical flatteners and -// expanders, don't need unit testing. However, if they are complex or -// intricate, they should be unit tested. -func TestTransitgatewayAttachmentsExampleUnitTest(t *testing.T) { - testCases := []struct { - TestName string - Input string - Expected string - Error bool - }{ - { - TestName: "empty", - Input: "", - Expected: "", - Error: true, - }, - { - TestName: "descriptive name", - Input: "some input", - Expected: "some output", - Error: false, - }, - { - TestName: "another descriptive name", - Input: "more input", - Expected: "more output", - Error: false, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.TestName, func(t *testing.T) { - got, err := tfec2.FunctionFromDataSource(testCase.Input) - - if err != nil && !testCase.Error { - t.Errorf("got error (%s), expected no error", err) - } - - if err == nil && testCase.Error { - t.Errorf("got (%s) and no error, expected error", got) - } - - if got != testCase.Expected { - t.Errorf("got %s, expected %s", got, testCase.Expected) - } - }) - } -} - - -// TIP: ==== ACCEPTANCE TESTS ==== -// This is an example of a basic acceptance test. This should test as much of -// standard functionality of the data source as possible, and test importing, if -// applicable. We prefix its name with "TestAcc", the service, and the -// data source name. -// -// Acceptance test access AWS and cost money to run. -func TestAccEC2TransitgatewayAttachmentsDataSource_basic(t *testing.T) { +func TestAccTransitGatewayAttachmentsDataSource_Filter(t *testing.T) { ctx := acctest.Context(t) - // TIP: This is a long-running test guard for tests that run longer than - // 300s (5 min) generally. - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var transitgatewayattachments ec2.DescribeTransitgatewayAttachmentsResponse + dataSourceName := "data.aws_ec2_transit_gateway_attachments.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - dataSourceName := "data.aws_ec2_transitgateway_attachments.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(t) - acctest.PreCheckPartitionHasService(ec2.EndpointsID, t) - testAccPreCheck(ctx, t) - }, - ErrorCheck: acctest.ErrorCheck(t, names.EC2EndpointID), + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t); testAccPreCheckTransitGateway(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckTransitgatewayAttachmentsDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccTransitgatewayAttachmentsDataSourceConfig_basic(rName), + Config: testAccTransitGatewayAttachmentsDataSourceConfig_filter(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckTransitgatewayAttachmentsExists(ctx, dataSourceName, &transitgatewayattachments), - resource.TestCheckResourceAttr(dataSourceName, "auto_minor_version_upgrade", "false"), - resource.TestCheckResourceAttrSet(dataSourceName, "maintenance_window_start_time.0.day_of_week"), - resource.TestCheckTypeSetElemNestedAttrs(dataSourceName, "user.*", map[string]string{ - "console_access": "false", - "groups.#": "0", - "username": "Test", - "password": "TestTest1234", - }), - acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "ec2", regexp.MustCompile(`transitgatewayattachments:+.`)), + resource.TestCheckResourceAttr(dataSourceName, "ids.#", "1"), ), }, }, }) } -func testAccTransitgatewayAttachmentsDataSourceConfig_basic(rName, version string) string { - return fmt.Sprintf(` -data "aws_security_group" "test" { - name = %[1]q +func testAccTransitGatewayAttachmentsDataSourceConfig_filter(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` +resource "aws_ec2_transit_gateway" "test" { + tags = { + Name = %[1]q + } } -data "aws_ec2_transitgateway_attachments" "test" { - transitgateway_attachments_name = %[1]q - engine_type = "ActiveEC2" - engine_version = %[2]q - host_instance_type = "ec2.t2.micro" - security_groups = [aws_security_group.test.id] - authentication_strategy = "simple" - storage_type = "efs" +resource "aws_ec2_transit_gateway_vpc_attachment" "test" { + subnet_ids = aws_subnet.test[*].id + transit_gateway_id = aws_ec2_transit_gateway.test.id + vpc_id = aws_vpc.test.id - logs { - general = true + tags = { + Name = %[1]q } +} - user { - username = "Test" - password = "TestTest1234" +data "aws_ec2_transit_gateway_attachments" "test" { + filter { + name = "transit-gateway-id" + values = [aws_ec2_transit_gateway.test.id] } + + filter { + name = "resource-type" + values = ["vpc"] + } + + filter { + name = "resource-id" + values = [aws_vpc.test.id] + } + + depends_on = [aws_ec2_transit_gateway_vpc_attachment.test] } -`, rName, version) +`, rName)) } diff --git a/website/docs/d/ec2_transit_gateway_attachments.html.markdown b/website/docs/d/ec2_transit_gateway_attachments.html.markdown new file mode 100644 index 000000000000..683efcb4056f --- /dev/null +++ b/website/docs/d/ec2_transit_gateway_attachments.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: "Transit Gateway" +layout: "aws" +page_title: "AWS: aws_ec2_transit_gateway_attachments" +description: |- + Get information on EC2 Transit Gateway Attachments +--- + +# Data Source: aws_ec2_transit_gateway_attachments + +Get information on EC2 Transit Gateway Attachments. + +## Example Usage + +### By Filter + +```hcl +data "aws_ec2_transit_gateway_attachments" "filtered" { + filter { + name = "state" + values = ["pendingAcceptance"] + } + + filter { + name = "resource-type" + values = ["vpc"] + } +} + +data "aws_ec2_transit_gateway_attachment" "unit" { + count = length(data.aws_ec2_transit_gateway_attachments.filtered.ids) + id = data.aws_ec2_transit_gateway_attachments.filtered.ids[count.index] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `filter` - (Optional) One or more configuration blocks containing name-values filters. Detailed below. + +### filter Argument Reference + +* `name` - (Required) Name of the filter check available value on [official documentation][1] +* `values` - (Required) List of one or more values for the filter. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `ids` A list of all attachments ids matching the filter. You can retrieve more information about the attachment using the [aws_ec2_transit_gateway_attachment][2] data source, searching by identifier. + +[1]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeTransitGatewayAttachments.html +[2]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway_attachment + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +- `read` - (Default `20m`) From 4a64cef5b635c371a8865d1d8b4a5da84a47c4c5 Mon Sep 17 00:00:00 2001 From: Lukas Hetzenecker Date: Fri, 24 Feb 2023 20:51:23 +0100 Subject: [PATCH 3/7] fix documentation --- ..._transit_gateway_attachments.html.markdown | 60 ------------------- ...2_transitgateway_attachments.html.markdown | 53 +++++++++++----- 2 files changed, 38 insertions(+), 75 deletions(-) delete mode 100644 website/docs/d/ec2_transit_gateway_attachments.html.markdown diff --git a/website/docs/d/ec2_transit_gateway_attachments.html.markdown b/website/docs/d/ec2_transit_gateway_attachments.html.markdown deleted file mode 100644 index 683efcb4056f..000000000000 --- a/website/docs/d/ec2_transit_gateway_attachments.html.markdown +++ /dev/null @@ -1,60 +0,0 @@ ---- -subcategory: "Transit Gateway" -layout: "aws" -page_title: "AWS: aws_ec2_transit_gateway_attachments" -description: |- - Get information on EC2 Transit Gateway Attachments ---- - -# Data Source: aws_ec2_transit_gateway_attachments - -Get information on EC2 Transit Gateway Attachments. - -## Example Usage - -### By Filter - -```hcl -data "aws_ec2_transit_gateway_attachments" "filtered" { - filter { - name = "state" - values = ["pendingAcceptance"] - } - - filter { - name = "resource-type" - values = ["vpc"] - } -} - -data "aws_ec2_transit_gateway_attachment" "unit" { - count = length(data.aws_ec2_transit_gateway_attachments.filtered.ids) - id = data.aws_ec2_transit_gateway_attachments.filtered.ids[count.index] -} -``` - -## Argument Reference - -The following arguments are supported: - -* `filter` - (Optional) One or more configuration blocks containing name-values filters. Detailed below. - -### filter Argument Reference - -* `name` - (Required) Name of the filter check available value on [official documentation][1] -* `values` - (Required) List of one or more values for the filter. - -## Attribute Reference - -In addition to all arguments above, the following attributes are exported: - -* `ids` A list of all attachments ids matching the filter. You can retrieve more information about the attachment using the [aws_ec2_transit_gateway_attachment][2] data source, searching by identifier. - -[1]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeTransitGatewayAttachments.html -[2]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway_attachment - -## Timeouts - -[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): - -- `read` - (Default `20m`) diff --git a/website/docs/d/ec2_transitgateway_attachments.html.markdown b/website/docs/d/ec2_transitgateway_attachments.html.markdown index 0eb84aa70c55..683efcb4056f 100644 --- a/website/docs/d/ec2_transitgateway_attachments.html.markdown +++ b/website/docs/d/ec2_transitgateway_attachments.html.markdown @@ -1,37 +1,60 @@ --- -subcategory: "EC2 (Elastic Compute Cloud)" +subcategory: "Transit Gateway" layout: "aws" -page_title: "AWS: aws_ec2_transitgateway_attachments" +page_title: "AWS: aws_ec2_transit_gateway_attachments" description: |- - Terraform data source for managing an AWS EC2 (Elastic Compute Cloud) Transitgateway Attachments. + Get information on EC2 Transit Gateway Attachments --- -# Data Source: aws_ec2_transitgateway_attachments +# Data Source: aws_ec2_transit_gateway_attachments -Terraform data source for managing an AWS EC2 (Elastic Compute Cloud) Transitgateway Attachments. +Get information on EC2 Transit Gateway Attachments. ## Example Usage -### Basic Usage +### By Filter -```terraform -data "aws_ec2_transitgateway_attachments" "example" { +```hcl +data "aws_ec2_transit_gateway_attachments" "filtered" { + filter { + name = "state" + values = ["pendingAcceptance"] + } + + filter { + name = "resource-type" + values = ["vpc"] + } +} + +data "aws_ec2_transit_gateway_attachment" "unit" { + count = length(data.aws_ec2_transit_gateway_attachments.filtered.ids) + id = data.aws_ec2_transit_gateway_attachments.filtered.ids[count.index] } ``` ## Argument Reference -The following arguments are required: +The following arguments are supported: -* `example_arg` - (Required) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `filter` - (Optional) One or more configuration blocks containing name-values filters. Detailed below. -The following arguments are optional: +### filter Argument Reference -* `optional_arg` - (Optional) Concise argument description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `name` - (Required) Name of the filter check available value on [official documentation][1] +* `values` - (Required) List of one or more values for the filter. -## Attributes Reference +## Attribute Reference In addition to all arguments above, the following attributes are exported: -* `arn` - ARN of the Transitgateway Attachments. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. -* `example_attribute` - Concise description. Do not begin the description with "An", "The", "Defines", "Indicates", or "Specifies," as these are verbose. In other words, "Indicates the amount of storage," can be rewritten as "Amount of storage," without losing any information. +* `ids` A list of all attachments ids matching the filter. You can retrieve more information about the attachment using the [aws_ec2_transit_gateway_attachment][2] data source, searching by identifier. + +[1]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeTransitGatewayAttachments.html +[2]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway_attachment + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +- `read` - (Default `20m`) From 505b1becc720c245a28569992bd26f32654894cd Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 24 Feb 2023 20:54:29 +0100 Subject: [PATCH 4/7] Create 29644.txt --- .changelog/29644.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/29644.txt diff --git a/.changelog/29644.txt b/.changelog/29644.txt new file mode 100644 index 000000000000..ff9fabe68f76 --- /dev/null +++ b/.changelog/29644.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_ec2_transit_gateway_attachments +``` From 9e851a14be42ec03368e53c5540bcd11a8b90444 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 24 Feb 2023 22:04:53 +0100 Subject: [PATCH 5/7] Rename ec2_transitgateway_attachments.html.markdown to ec2_transit_gateway_attachments.html.markdown --- ...tml.markdown => ec2_transit_gateway_attachments.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/docs/d/{ec2_transitgateway_attachments.html.markdown => ec2_transit_gateway_attachments.html.markdown} (100%) diff --git a/website/docs/d/ec2_transitgateway_attachments.html.markdown b/website/docs/d/ec2_transit_gateway_attachments.html.markdown similarity index 100% rename from website/docs/d/ec2_transitgateway_attachments.html.markdown rename to website/docs/d/ec2_transit_gateway_attachments.html.markdown From 29cc6e2ca509c250c1c41c66721d6900d392d104 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 31 Mar 2023 17:03:21 -0400 Subject: [PATCH 6/7] d/aws_ec2_transit_gateway_attachments: Alphabetize attributes. --- .../service/ec2/transitgateway_attachments_data_source.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/ec2/transitgateway_attachments_data_source.go b/internal/service/ec2/transitgateway_attachments_data_source.go index e4bfd3e3aa07..022faf332ba7 100644 --- a/internal/service/ec2/transitgateway_attachments_data_source.go +++ b/internal/service/ec2/transitgateway_attachments_data_source.go @@ -23,13 +23,13 @@ func DataSourceTransitGatewayAttachments() *schema.Resource { }, Schema: map[string]*schema.Schema{ + "filter": CustomFiltersSchema(), "ids": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "filter": CustomFiltersSchema(), - "tags": tftags.TagsSchemaComputed(), + "tags": tftags.TagsSchemaComputed(), }, } } From cd931514d8d86b1b7b40035a68f861a163f96384 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 31 Mar 2023 17:05:42 -0400 Subject: [PATCH 7/7] d/aws_ec2_transit_gateway_attachments: Tidy up acceptance tests. --- .../service/ec2/transitgateway_attachments_data_source_test.go | 2 +- internal/service/ec2/transitgateway_data_source_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/service/ec2/transitgateway_attachments_data_source_test.go b/internal/service/ec2/transitgateway_attachments_data_source_test.go index d710558759f2..e4498e18576f 100644 --- a/internal/service/ec2/transitgateway_attachments_data_source_test.go +++ b/internal/service/ec2/transitgateway_attachments_data_source_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" ) -func TestAccTransitGatewayAttachmentsDataSource_Filter(t *testing.T) { +func testAccTransitGatewayAttachmentsDataSource_Filter(t *testing.T) { ctx := acctest.Context(t) dataSourceName := "data.aws_ec2_transit_gateway_attachments.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/ec2/transitgateway_data_source_test.go b/internal/service/ec2/transitgateway_data_source_test.go index b3758dce663a..a81b868add15 100644 --- a/internal/service/ec2/transitgateway_data_source_test.go +++ b/internal/service/ec2/transitgateway_data_source_test.go @@ -18,6 +18,9 @@ func TestAccTransitGatewayDataSource_serial(t *testing.T) { "Filter": testAccTransitGatewayAttachmentDataSource_Filter, "ID": testAccTransitGatewayAttachmentDataSource_ID, }, + "Attachments": { + "Filter": testAccTransitGatewayAttachmentsDataSource_Filter, + }, "Connect": { "Filter": testAccTransitGatewayConnectDataSource_Filter, "ID": testAccTransitGatewayConnectDataSource_ID,