-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19500 from hashicorp/f-servicecat-ds-portfolio
ds/servicecatalog_portfolio: New data source
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
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,3 @@ | ||
```release-note:new-data-source | ||
aws_servicecatalog_portfolio | ||
``` |
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,98 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/servicecatalog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
tfservicecatalog "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog" | ||
) | ||
|
||
func dataSourceAwsServiceCatalogPortfolio() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsServiceCatalogPortfolioRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"accept_language": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "en", | ||
ValidateFunc: validation.StringInSlice(tfservicecatalog.AcceptLanguage_Values(), false), | ||
}, | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"provider_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tagsSchemaComputed(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsServiceCatalogPortfolioRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).scconn | ||
|
||
input := &servicecatalog.DescribePortfolioInput{ | ||
Id: aws.String(d.Get("id").(string)), | ||
} | ||
|
||
if v, ok := d.GetOk("accept_language"); ok { | ||
input.AcceptLanguage = aws.String(v.(string)) | ||
} | ||
|
||
output, err := conn.DescribePortfolio(input) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Service Catalog Portfolio (%s): %w", d.Get("id").(string), err) | ||
} | ||
|
||
if output == nil || output.PortfolioDetail == nil { | ||
return fmt.Errorf("error getting Service Catalog Portfolio (%s): empty response", d.Get("id").(string)) | ||
} | ||
|
||
detail := output.PortfolioDetail | ||
|
||
d.SetId(aws.StringValue(detail.Id)) | ||
|
||
if err := d.Set("created_time", aws.TimeValue(detail.CreatedTime).Format(time.RFC3339)); err != nil { | ||
log.Printf("[DEBUG] Error setting created_time: %s", err) | ||
} | ||
|
||
d.Set("arn", detail.ARN) | ||
d.Set("description", detail.Description) | ||
d.Set("name", detail.DisplayName) | ||
d.Set("provider_name", detail.ProviderName) | ||
|
||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
tags := keyvaluetags.ServicecatalogKeyValueTags(output.Tags) | ||
|
||
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %w", err) | ||
} | ||
|
||
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,44 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/servicecatalog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAWSServiceCatalogPortfolioDataSource_basic(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
dataSourceName := "data.aws_servicecatalog_portfolio.test" | ||
resourceName := "aws_servicecatalog_portfolio.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, servicecatalog.EndpointsID), | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckServiceCatlaogPortfolioDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAwsServiceCatalogPortfolioDataSourceConfigBasic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(resourceName, "created_time", dataSourceName, "created_time"), | ||
resource.TestCheckResourceAttrPair(resourceName, "description", dataSourceName, "description"), | ||
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "provider_name", dataSourceName, "provider_name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.Chicane", dataSourceName, "tags.Chicane"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsServiceCatalogPortfolioDataSourceConfigBasic(rName string) string { | ||
return composeConfig(testAccCheckAwsServiceCatalogPortfolioResourceConfigTags1(rName, "Chicane", "Nick"), ` | ||
data "aws_servicecatalog_portfolio" "test" { | ||
id = aws_servicecatalog_portfolio.test.id | ||
} | ||
`) | ||
} |
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,40 @@ | ||
--- | ||
subcategory: "Service Catalog" | ||
layout: "aws" | ||
page_title: "AWS: aws_servicecatalog_portfolio" | ||
description: |- | ||
Provides information for a Service Catalog Portfolio. | ||
--- | ||
|
||
# Data Source: aws_servicecatalog_portfolio | ||
|
||
Provides information for a Service Catalog Portfolio. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_servicecatalog_portfolio" "portfolio" { | ||
id = "port-07052002" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are required: | ||
|
||
* `id` - (Required) Portfolio identifier. | ||
|
||
The following arguments are optional: | ||
|
||
* `accept_language` - (Optional) Language code. Valid values: `en` (English), `jp` (Japanese), `zh` (Chinese). Default value is `en`. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `arn` - Portfolio ARN. | ||
* `created_time` - Time the portfolio was created. | ||
* `description` - Description of the portfolio | ||
* `name` - Portfolio name. | ||
* `provider_name` - Name of the person or organization who owns the portfolio. | ||
* `tags` - Tags applied to the portfolio. |