Skip to content

Commit

Permalink
data source azurerm_shared_image - support purchase_plan (#19873)
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o authored Jan 9, 2023
1 parent 7f8cd8e commit 791be86
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/services/compute/shared_image_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
}
3 changes: 3 additions & 0 deletions internal/services/compute/shared_image_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
})
Expand Down
12 changes: 12 additions & 0 deletions website/docs/d/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit 791be86

Please sign in to comment.