Skip to content

Commit

Permalink
data-source/aws_outposts_outpost: Add arn argument (#14967)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbarney authored Sep 2, 2020
1 parent 7d94886 commit 3680d46
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
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

0 comments on commit 3680d46

Please sign in to comment.