From 791be86985525bf23e38e4660a60ec69f6b3ecfa Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Mon, 9 Jan 2023 16:57:24 +0800 Subject: [PATCH] data source `azurerm_shared_image` - support `purchase_plan` (#19873) --- .../compute/shared_image_data_source.go | 54 +++++++++++++++++++ .../compute/shared_image_data_source_test.go | 3 ++ website/docs/d/shared_image.html.markdown | 12 +++++ 3 files changed, 69 insertions(+) diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 3af3b4ba7da9..671cadc81422 100644 --- a/internal/services/compute/shared_image_data_source.go +++ b/internal/services/compute/shared_image_data_source.go @@ -97,6 +97,27 @@ func dataSourceSharedImage() *pluginsdk.Resource { Computed: true, }, + "purchase_plan": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "publisher": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "product": { + Type: pluginsdk.TypeString, + Computed: true, + }, + }, + }, + }, + "release_note_uri": { Type: pluginsdk.TypeString, Computed: true, @@ -145,6 +166,10 @@ func dataSourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) erro if err := d.Set("identifier", flattenGalleryImageDataSourceIdentifier(props.Identifier)); err != nil { return fmt.Errorf("setting `identifier`: %+v", err) } + + if err := d.Set("purchase_plan", flattenGalleryImageDataSourcePurchasePlan(props.PurchasePlan)); err != nil { + return fmt.Errorf("setting `purchase_plan`: %+v", err) + } } return tags.FlattenAndSet(d, resp.Tags) @@ -171,3 +196,32 @@ func flattenGalleryImageDataSourceIdentifier(input *compute.GalleryImageIdentifi return []interface{}{result} } + +func flattenGalleryImageDataSourcePurchasePlan(input *compute.ImagePurchasePlan) []interface{} { + if input == nil { + return []interface{}{} + } + + name := "" + if input.Name != nil { + name = *input.Name + } + + publisher := "" + if input.Publisher != nil { + publisher = *input.Publisher + } + + product := "" + if input.Product != nil { + product = *input.Product + } + + return []interface{}{ + map[string]interface{}{ + "name": name, + "publisher": publisher, + "product": product, + }, + } +} diff --git a/internal/services/compute/shared_image_data_source_test.go b/internal/services/compute/shared_image_data_source_test.go index f02ba76e8460..8254a7a50c3f 100644 --- a/internal/services/compute/shared_image_data_source_test.go +++ b/internal/services/compute/shared_image_data_source_test.go @@ -46,6 +46,9 @@ func TestAccDataSourceAzureRMSharedImage_complete(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("tags.%").HasValue("0"), check.That(data.ResourceName).Key("hyper_v_generation").HasValue("V1"), + check.That(data.ResourceName).Key("purchase_plan.0.name").HasValue("AccTestPlan"), + check.That(data.ResourceName).Key("purchase_plan.0.publisher").HasValue("AccTestPlanPublisher"), + check.That(data.ResourceName).Key("purchase_plan.0.product").HasValue("AccTestPlanProduct"), ), }, }) diff --git a/website/docs/d/shared_image.html.markdown b/website/docs/d/shared_image.html.markdown index 6b5006d6964f..45278b151b80 100644 --- a/website/docs/d/shared_image.html.markdown +++ b/website/docs/d/shared_image.html.markdown @@ -53,6 +53,8 @@ The following attributes are exported: * `privacy_statement_uri` - The URI containing the Privacy Statement for this Shared Image. +* `purchase_plan` - (Optional) A `purchase_plan` block as defined below. + * `release_note_uri` - The URI containing the Release Notes for this Shared Image. * `tags` - A mapping of tags assigned to the Shared Image. @@ -67,6 +69,16 @@ A `identifier` block exports the following: * `sku` - The Name of the SKU for this Gallery Image. +--- + +A `purchase_plan` block exports the following: + +* `name` - (Required) The Purchase Plan Name for this Shared Image. + +* `publisher` - (Optional) The Purchase Plan Publisher for this Gallery Image. + +* `product` - (Optional) The Purchase Plan Product for this Gallery Image. + ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: