-
Notifications
You must be signed in to change notification settings - Fork 9k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Data Sources: aws_outposts_site(s) #13825
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/outposts" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceAwsOutpostsSite() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsOutpostsSiteRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsOutpostsSiteRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).outpostsconn | ||
|
||
input := &outposts.ListSitesInput{} | ||
|
||
var results []*outposts.Site | ||
|
||
err := conn.ListSitesPages(input, func(page *outposts.ListSitesOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, site := range page.Sites { | ||
if site == nil { | ||
continue | ||
} | ||
|
||
if v, ok := d.GetOk("id"); ok && v.(string) != aws.StringValue(site.SiteId) { | ||
continue | ||
} | ||
|
||
if v, ok := d.GetOk("name"); ok && v.(string) != aws.StringValue(site.Name) { | ||
continue | ||
} | ||
|
||
results = append(results, site) | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing Outposts Sites: %w", err) | ||
} | ||
|
||
if len(results) == 0 { | ||
return fmt.Errorf("no Outposts Site found matching criteria; try different search") | ||
} | ||
|
||
if len(results) > 1 { | ||
return fmt.Errorf("multiple Outposts Sites found matching criteria; try different search") | ||
} | ||
|
||
site := results[0] | ||
|
||
d.SetId(aws.StringValue(site.SiteId)) | ||
d.Set("account_id", site.AccountId) | ||
d.Set("description", site.Description) | ||
d.Set("name", site.Name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccAWSOutpostsSiteDataSource_Id(t *testing.T) { | ||
dataSourceName := "data.aws_outposts_site.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsSites(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSOutpostsSiteDataSourceConfigId(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckResourceAttrAccountID(dataSourceName, "account_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "description"), | ||
resource.TestMatchResourceAttr(dataSourceName, "id", regexp.MustCompile(`^os-.+$`)), | ||
resource.TestMatchResourceAttr(dataSourceName, "name", regexp.MustCompile(`^.+$`)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSOutpostsSiteDataSource_Name(t *testing.T) { | ||
sourceDataSourceName := "data.aws_outposts_site.source" | ||
dataSourceName := "data.aws_outposts_site.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsSites(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSOutpostsSiteDataSourceConfigName(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "account_id", sourceDataSourceName, "account_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "description", sourceDataSourceName, "description"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "id", sourceDataSourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", sourceDataSourceName, "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAWSOutpostsSiteDataSourceConfigId() string { | ||
return fmt.Sprintf(` | ||
data "aws_outposts_sites" "test" {} | ||
|
||
data "aws_outposts_site" "test" { | ||
id = tolist(data.aws_outposts_sites.test.ids)[0] | ||
} | ||
`) | ||
} | ||
|
||
func testAccAWSOutpostsSiteDataSourceConfigName() string { | ||
return fmt.Sprintf(` | ||
data "aws_outposts_sites" "test" {} | ||
|
||
data "aws_outposts_site" "source" { | ||
id = tolist(data.aws_outposts_sites.test.ids)[0] | ||
} | ||
|
||
data "aws_outposts_site" "test" { | ||
name = data.aws_outposts_site.source.name | ||
} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/outposts" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceAwsOutpostsSites() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsOutpostsSitesRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"ids": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsOutpostsSitesRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).outpostsconn | ||
|
||
input := &outposts.ListSitesInput{} | ||
|
||
var ids []string | ||
|
||
err := conn.ListSitesPages(input, func(page *outposts.ListSitesOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, site := range page.Sites { | ||
if site == nil { | ||
continue | ||
} | ||
|
||
ids = append(ids, aws.StringValue(site.SiteId)) | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing Outposts Sites: %w", err) | ||
} | ||
|
||
if err := d.Set("ids", ids); err != nil { | ||
return fmt.Errorf("error setting ids: %w", err) | ||
} | ||
|
||
d.SetId(resource.UniqueId()) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/outposts" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
func TestAccAWSOutpostsSitesDataSource_basic(t *testing.T) { | ||
dataSourceName := "data.aws_outposts_sites.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsSites(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSOutpostsSitesDataSourceConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckOutpostsSitesAttributes(dataSourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckOutpostsSitesAttributes(dataSourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[dataSourceName] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", dataSourceName) | ||
} | ||
|
||
if v := rs.Primary.Attributes["ids.#"]; v == "0" { | ||
return fmt.Errorf("expected at least one ids result, got none") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccPreCheckAWSOutpostsSites(t *testing.T) { | ||
conn := testAccProvider.Meta().(*AWSClient).outpostsconn | ||
|
||
input := &outposts.ListSitesInput{} | ||
|
||
output, err := conn.ListSites(input) | ||
|
||
if testAccPreCheckSkipError(err) { | ||
t.Skipf("skipping acceptance testing: %s", err) | ||
} | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected PreCheck error: %s", err) | ||
} | ||
|
||
// Ensure there is at least one Site | ||
if output == nil || len(output.Sites) == 0 { | ||
t.Skip("skipping since no Sites Outpost found") | ||
} | ||
} | ||
|
||
func testAccAWSOutpostsSitesDataSourceConfig() string { | ||
return fmt.Sprintf(` | ||
data "aws_outposts_sites" "test" {} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
subcategory: "Outposts" | ||
layout: "aws" | ||
page_title: "AWS: aws_outposts_site" | ||
description: |- | ||
Provides details about an Outposts Site | ||
--- | ||
|
||
# Data Source: aws_outposts_site | ||
|
||
Provides details about an Outposts Site. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_outposts_site" "example" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `id` - (Optional) Identifier of the Site. | ||
* `name` - (Optional) Name of the Site. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `account_id` - AWS Account identifier. | ||
* `description` - Description. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
subcategory: "Outposts" | ||
layout: "aws" | ||
page_title: "AWS: aws_outposts_sites" | ||
description: |- | ||
Provides details about multiple Outposts Sites. | ||
--- | ||
|
||
# Data Source: aws_outposts_sites | ||
|
||
Provides details about multiple Outposts Sites. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_outposts_sites" "all" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
There are no arguments available for this data source. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no "arguments above" :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmmmm copypasta 馃崫 will update! |
||
|
||
* `ids` - Set of Outposts Site identifiers. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should one of these be required, using
AtLeastOneOf
orExactlyOneOf
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, we should likely encourage good implementations for folks even with just one site to start. 馃憤