Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Outpost by Arn in datasource #14967

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions aws/data_source_aws_outposts_outpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ func dataSourceAwsOutpostsOutpost() *schema.Resource {

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateArn,
},
"availability_zone": {
Type: schema.TypeString,
Expand Down Expand Up @@ -76,6 +78,10 @@ func dataSourceAwsOutpostsOutpostRead(d *schema.ResourceData, meta interface{})
continue
}

if v, ok := d.GetOk("arn"); ok && v.(string) != aws.StringValue(outpost.OutpostArn) {
continue
}

results = append(results, outpost)
}

Expand Down
39 changes: 39 additions & 0 deletions aws/data_source_aws_outposts_outpost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ func TestAccAWSOutpostsOutpostDataSource_Name(t *testing.T) {
})
}

func TestAccAWSOutpostsOutpostDataSource_Arn(t *testing.T) {
sourceDataSourceName := "data.aws_outposts_outpost.source"
dataSourceName := "data.aws_outposts_outpost.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccAWSOutpostsOutpostDataSourceConfigArn(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", sourceDataSourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone", sourceDataSourceName, "availability_zone"),
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_id", sourceDataSourceName, "availability_zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", sourceDataSourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "id", sourceDataSourceName, "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", sourceDataSourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", sourceDataSourceName, "owner_id"),
),
},
},
})
}

func testAccAWSOutpostsOutpostDataSourceConfigId() string {
return `
data "aws_outposts_outposts" "test" {}
Expand All @@ -79,3 +104,17 @@ data "aws_outposts_outpost" "test" {
}
`
}

func testAccAWSOutpostsOutpostDataSourceConfigArn() string {
return `
data "aws_outposts_outposts" "test" {}

data "aws_outposts_outpost" "source" {
arn = tolist(data.aws_outposts_outposts.test.arns)[0]
}

data "aws_outposts_outpost" "test" {
arn = data.aws_outposts_outpost.source.arn
}
`
}
2 changes: 1 addition & 1 deletion website/docs/d/outposts_outpost.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ The following arguments are supported:

* `id` - (Optional) Identifier of the Outpost.
* `name` - (Optional) Name of the Outpost.
* `arn` - (Optional) Amazon Resource Name (ARN).

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name (ARN).
* `availability_zone` - Availability Zone name.
* `availability_zone_id` - Availability Zone identifier.
* `description` - Description.
Expand Down