Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ds/servicecatalog_product: New data source #19503

Merged
merged 5 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-notes:new-data-source
aws_servicecatalog_product
```
122 changes: 122 additions & 0 deletions aws/data_source_aws_servicecatalog_product.go
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
}
93 changes: 93 additions & 0 deletions aws/data_source_aws_servicecatalog_product_test.go
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
}
`)
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func Provider() *schema.Provider {
"aws_secretsmanager_secret_version": dataSourceAwsSecretsManagerSecretVersion(),
"aws_servicecatalog_constraint": dataSourceAwsServiceCatalogConstraint(),
"aws_servicecatalog_portfolio": dataSourceAwsServiceCatalogPortfolio(),
"aws_servicecatalog_product": dataSourceAwsServiceCatalogProduct(),
"aws_servicequotas_service": dataSourceAwsServiceQuotasService(),
"aws_servicequotas_service_quota": dataSourceAwsServiceQuotasServiceQuota(),
"aws_service_discovery_dns_namespace": dataSourceServiceDiscoveryDnsNamespace(),
Expand Down
51 changes: 51 additions & 0 deletions website/docs/d/servicecatalog_product.html.markdown
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.