From fb03e541e7df5d97a5c08397951f79788158bd63 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 24 May 2021 14:15:36 -0400 Subject: [PATCH 1/5] provider: Add new data source --- aws/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/provider.go b/aws/provider.go index d0d6e9b9846..f8022ea50ae 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -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(), From 66e3e209710bf19e3d2e73750ef8a5badee7ebc2 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 24 May 2021 14:16:04 -0400 Subject: [PATCH 2/5] ds/servicecat_product: New data source --- aws/data_source_aws_servicecatalog_product.go | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 aws/data_source_aws_servicecatalog_product.go diff --git a/aws/data_source_aws_servicecatalog_product.go b/aws/data_source_aws_servicecatalog_product.go new file mode 100644 index 00000000000..f54a52a6084 --- /dev/null +++ b/aws/data_source_aws_servicecatalog_product.go @@ -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 +} From 19cfe9c11294f11fa46f241f5adef282428e6bd3 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 24 May 2021 14:16:33 -0400 Subject: [PATCH 3/5] tests/ds/servicecat_product: New data source --- ..._source_aws_servicecatalog_product_test.go | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 aws/data_source_aws_servicecatalog_product_test.go diff --git a/aws/data_source_aws_servicecatalog_product_test.go b/aws/data_source_aws_servicecatalog_product_test.go new file mode 100644 index 00000000000..0d83b480da3 --- /dev/null +++ b/aws/data_source_aws_servicecatalog_product_test.go @@ -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 +} +`) +} From c43f688b98a7070fdb38d02a64fa46198cc0cc91 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 24 May 2021 14:16:45 -0400 Subject: [PATCH 4/5] docs/ds/servicecat_product: New data source --- .../d/servicecatalog_product.html.markdown | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 website/docs/d/servicecatalog_product.html.markdown diff --git a/website/docs/d/servicecatalog_product.html.markdown b/website/docs/d/servicecatalog_product.html.markdown new file mode 100644 index 00000000000..dfde282c810 --- /dev/null +++ b/website/docs/d/servicecatalog_product.html.markdown @@ -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. From da7b4afd07465449aa12a23e640bc2d33448f6cf Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 24 May 2021 14:18:07 -0400 Subject: [PATCH 5/5] ds/servicecat_product: Add changelog --- .changelog/19503.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19503.txt diff --git a/.changelog/19503.txt b/.changelog/19503.txt new file mode 100644 index 00000000000..88b7b14cb40 --- /dev/null +++ b/.changelog/19503.txt @@ -0,0 +1,3 @@ +```release-notes:new-data-source + aws_servicecatalog_product + ``` \ No newline at end of file