Skip to content

Commit

Permalink
Merge pull request #17585 from farhanangullia/f-ds_aws_outposts_outpo…
Browse files Browse the repository at this point in the history
…st(s)-owner_id

data_source/aws_outposts_outpost and aws_outposts_outposts: add argument for owner_id
ewbankkit authored May 17, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 9cd36e6 + cc62271 commit ea03cc6
Showing 6 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changelog/17585.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
data-source/aws_outposts_outpost: `owner_id` is now an optional argument
```

```release-note:enhancement
data-source/aws_outposts_outposts: Add `owner_id` argument
```
5 changes: 5 additions & 0 deletions aws/data_source_aws_outposts_outpost.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ func dataSourceAwsOutpostsOutpost() *schema.Resource {
},
"owner_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"site_id": {
@@ -82,6 +83,10 @@ func dataSourceAwsOutpostsOutpostRead(d *schema.ResourceData, meta interface{})
continue
}

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

results = append(results, outpost)
}

44 changes: 42 additions & 2 deletions aws/data_source_aws_outposts_outpost_test.go
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ func TestAccAWSOutpostsOutpostDataSource_Id(t *testing.T) {
{
Config: testAccAWSOutpostsOutpostDataSourceConfigId(),
Check: resource.ComposeTestCheckFunc(
testAccMatchResourceAttrRegionalARN(dataSourceName, "arn", "outposts", regexp.MustCompile(`outpost/op-.+$`)),
testAccCheckResourceAttrRegionalARNIgnoreRegionAndAccount(dataSourceName, "arn", "outposts", regexp.MustCompile(`outpost/op-.+$`).String()),
resource.TestMatchResourceAttr(dataSourceName, "availability_zone", regexp.MustCompile(`^.+$`)),
resource.TestMatchResourceAttr(dataSourceName, "availability_zone_id", regexp.MustCompile(`^.+$`)),
resource.TestCheckResourceAttrSet(dataSourceName, "description"),
resource.TestMatchResourceAttr(dataSourceName, "id", regexp.MustCompile(`^op-.+$`)),
resource.TestMatchResourceAttr(dataSourceName, "name", regexp.MustCompile(`^.+$`)),
testAccCheckResourceAttrAccountID(dataSourceName, "owner_id"),
testAccMatchResourceAttrAccountID(dataSourceName, "owner_id"),
),
},
},
@@ -85,6 +85,32 @@ func TestAccAWSOutpostsOutpostDataSource_Arn(t *testing.T) {
})
}

func TestAccAWSOutpostsOutpostDataSource_OwnerId(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) },
ErrorCheck: testAccErrorCheck(t, outposts.EndpointsID),
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccAWSOutpostsOutpostDataSourceConfigOwnerId(),
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" {}
@@ -122,3 +148,17 @@ data "aws_outposts_outpost" "test" {
}
`
}

func testAccAWSOutpostsOutpostDataSourceConfigOwnerId() string {
return `
data "aws_outposts_outposts" "test" {}
data "aws_outposts_outpost" "source" {
id = tolist(data.aws_outposts_outposts.test.ids)[0]
}
data "aws_outposts_outpost" "test" {
owner_id = data.aws_outposts_outpost.source.owner_id
}
`
}
9 changes: 9 additions & 0 deletions aws/data_source_aws_outposts_outposts.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,11 @@ func dataSourceAwsOutpostsOutposts() *schema.Resource {
Optional: true,
Computed: true,
},
"owner_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
@@ -71,6 +76,10 @@ func dataSourceAwsOutpostsOutpostsRead(d *schema.ResourceData, meta interface{})
continue
}

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

arns = append(arns, aws.StringValue(outpost.OutpostArn))
ids = append(ids, aws.StringValue(outpost.OutpostId))
}
2 changes: 1 addition & 1 deletion website/docs/d/outposts_outpost.html.markdown
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ The following arguments are supported:
* `id` - (Optional) Identifier of the Outpost.
* `name` - (Optional) Name of the Outpost.
* `arn` - (Optional) Amazon Resource Name (ARN).
* `owner_id` - (Optional) AWS Account identifier of the Outpost owner.

## Attribute Reference

@@ -33,5 +34,4 @@ In addition to all arguments above, the following attributes are exported:
* `availability_zone` - Availability Zone name.
* `availability_zone_id` - Availability Zone identifier.
* `description` - Description.
* `owner_id` - AWS Account identifier of the Outpost owner.
* `site_id` - Site identifier.
1 change: 1 addition & 0 deletions website/docs/d/outposts_outposts.html.markdown
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ The following arguments are supported:
* `availability_zone` - (Optional) Availability Zone name.
* `availability_zone_id` - (Optional) Availability Zone identifier.
* `site_id` - (Optional) Site identifier.
* `owner_id` - (Optional) AWS Account identifier of the Outpost owner.

## Attribute Reference

0 comments on commit ea03cc6

Please sign in to comment.