-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #19503 from hashicorp/f-servicecat-ds-product
ds/servicecatalog_product: New data source
- Loading branch information
Showing
5 changed files
with
270 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-notes:new-data-source | ||
aws_servicecatalog_product | ||
``` |
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,122 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"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" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog/waiter" | ||
) | ||
|
||
func dataSourceAwsServiceCatalogProduct() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsServiceCatalogProductRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"accept_language": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "en", | ||
ValidateFunc: validation.StringInSlice(tfservicecatalog.AcceptLanguage_Values(), false), | ||
}, | ||
"created_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"distributor": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"has_default_path": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"support_description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"support_email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"support_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tagsSchemaComputed(), | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsServiceCatalogProductRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).scconn | ||
|
||
output, err := waiter.ProductReady(conn, d.Get("accept_language").(string), d.Get("id").(string)) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error describing Service Catalog Product: %w", err) | ||
} | ||
|
||
if output == nil || output.ProductViewDetail == nil || output.ProductViewDetail.ProductViewSummary == nil { | ||
return fmt.Errorf("error getting Service Catalog Product: empty response") | ||
} | ||
|
||
pvs := output.ProductViewDetail.ProductViewSummary | ||
|
||
d.Set("arn", output.ProductViewDetail.ProductARN) | ||
if output.ProductViewDetail.CreatedTime != nil { | ||
d.Set("created_time", output.ProductViewDetail.CreatedTime.Format(time.RFC3339)) | ||
} | ||
d.Set("description", pvs.ShortDescription) | ||
d.Set("distributor", pvs.Distributor) | ||
d.Set("has_default_path", pvs.HasDefaultPath) | ||
d.Set("name", pvs.Name) | ||
d.Set("owner", pvs.Owner) | ||
d.Set("status", output.ProductViewDetail.Status) | ||
d.Set("support_description", pvs.SupportDescription) | ||
d.Set("support_email", pvs.SupportEmail) | ||
d.Set("support_url", pvs.SupportUrl) | ||
d.Set("type", pvs.Type) | ||
|
||
d.SetId(aws.StringValue(pvs.ProductId)) | ||
|
||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
if err := d.Set("tags", keyvaluetags.ServicecatalogKeyValueTags(output.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,93 @@ | ||
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 TestAccAWSServiceCatalogProductDataSource_basic(t *testing.T) { | ||
resourceName := "aws_servicecatalog_product.test" | ||
dataSourceName := "data.aws_servicecatalog_product.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, servicecatalog.EndpointsID), | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAwsServiceCatalogProductDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSServiceCatalogProductDataSourceConfig_basic(rName, "beskrivning", "supportbeskrivning"), | ||
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, "distributor", dataSourceName, "distributor"), | ||
resource.TestCheckResourceAttrPair(resourceName, "has_default_path", dataSourceName, "has_default_path"), | ||
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "owner", dataSourceName, "owner"), | ||
resource.TestCheckResourceAttrPair(resourceName, "status", dataSourceName, "status"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_description", dataSourceName, "support_description"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_email", dataSourceName, "support_email"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_url", dataSourceName, "support_url"), | ||
resource.TestCheckResourceAttrPair(resourceName, "type", dataSourceName, "type"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.Name", dataSourceName, "tags.Name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSServiceCatalogProductDataSource_physicalID(t *testing.T) { | ||
resourceName := "aws_servicecatalog_product.test" | ||
dataSourceName := "data.aws_servicecatalog_product.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, servicecatalog.EndpointsID), | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAwsServiceCatalogProductDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSServiceCatalogProductDataSourceConfig_physicalID(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, "distributor", dataSourceName, "distributor"), | ||
resource.TestCheckResourceAttrPair(resourceName, "has_default_path", dataSourceName, "has_default_path"), | ||
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "owner", dataSourceName, "owner"), | ||
resource.TestCheckResourceAttrPair(resourceName, "status", dataSourceName, "status"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_description", dataSourceName, "support_description"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_email", dataSourceName, "support_email"), | ||
resource.TestCheckResourceAttrPair(resourceName, "support_url", dataSourceName, "support_url"), | ||
resource.TestCheckResourceAttrPair(resourceName, "type", dataSourceName, "type"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tags.Name", dataSourceName, "tags.Name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAWSServiceCatalogProductDataSourceConfig_basic(rName, description, supportDescription string) string { | ||
return composeConfig(testAccAWSServiceCatalogProductConfig_basic(rName, description, supportDescription), ` | ||
data "aws_servicecatalog_product" "test" { | ||
id = aws_servicecatalog_product.test.id | ||
} | ||
`) | ||
} | ||
|
||
func testAccAWSServiceCatalogProductDataSourceConfig_physicalID(rName string) string { | ||
return composeConfig(testAccAWSServiceCatalogProductConfig_physicalID(rName), ` | ||
data "aws_servicecatalog_product" "test" { | ||
id = aws_servicecatalog_product.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,51 @@ | ||
--- | ||
subcategory: "Service Catalog" | ||
layout: "aws" | ||
page_title: "AWS: aws_servicecatalog_product" | ||
description: |- | ||
Provides information on a Service Catalog Product | ||
--- | ||
|
||
# Data source: aws_servicecatalog_product | ||
|
||
Provides information on a Service Catalog Product. | ||
|
||
-> **Tip:** A "provisioning artifact" is also referred to as a "version." A "distributor" is also referred to as a "vendor." | ||
|
||
## Example Usage | ||
|
||
### Basic Usage | ||
|
||
```terraform | ||
data "aws_servicecatalog_product" "example" { | ||
id = "prod-dnigbtea24ste" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are required: | ||
|
||
* `id` - (Required) Product ID. | ||
|
||
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` - ARN of the product. | ||
* `created_time` - Time when the product was created. | ||
* `description` - Description of the product. | ||
* `distributor` - Distributor (i.e., vendor) of the product. | ||
* `has_default_path` - Whether the product has a default path. | ||
* `name` - Name of the product. | ||
* `owner` - Owner of the product. | ||
* `status` - Status of the product. | ||
* `support_description` - Support information about the product. | ||
* `support_email` - Contact email for product support. | ||
* `support_url` - Contact URL for product support. | ||
* `tags` - Tags to apply to the product. | ||
* `type` - Type of product. |