From 236c2772ffd92ea90e29c13a68aa547670a7a321 Mon Sep 17 00:00:00 2001 From: Andrew Holford Date: Tue, 9 Jul 2024 15:12:52 +0100 Subject: [PATCH] add code to nutanix_image data_resource and resource to accommodate version attribute --- nutanix/data_source_nutanix_image.go | 10 ++++++++++ nutanix/resource_nutanix_image.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/nutanix/data_source_nutanix_image.go b/nutanix/data_source_nutanix_image.go index bfa6bbec5..3584bb51b 100644 --- a/nutanix/data_source_nutanix_image.go +++ b/nutanix/data_source_nutanix_image.go @@ -244,6 +244,16 @@ func dataSourceNutanixImageRead(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(err) } + version := make(map[string]string) + if resp.Status.Resources.Version != nil { + version["product_name"] = utils.StringValue(resp.Status.Resources.Version.ProductName) + version["product_version"] = utils.StringValue(resp.Status.Resources.Version.ProductVersion) + } + + if err := d.Set("version", version); err != nil { + return diag.FromErr(err) + } + d.SetId(utils.StringValue(resp.Metadata.UUID)) return nil diff --git a/nutanix/resource_nutanix_image.go b/nutanix/resource_nutanix_image.go index 4e1e11c5e..afe338827 100644 --- a/nutanix/resource_nutanix_image.go +++ b/nutanix/resource_nutanix_image.go @@ -545,6 +545,8 @@ func resourceNutanixImageDelete(ctx context.Context, d *schema.ResourceData, met func getImageResource(d *schema.ResourceData, image *v3.ImageResources) error { cs, csok := d.GetOk("checksum") checks := &v3.Checksum{} + vr, vrok := d.GetOk("version") + versionResource := &v3.ImageVersionResources{} su, suok := d.GetOk("source_uri") sp, spok := d.GetOk("source_path") var furi string @@ -590,6 +592,26 @@ func getImageResource(d *schema.ResourceData, image *v3.ImageResources) error { image.Checksum = checks } + if vrok { + version := vr.(map[string]interface{}) + pn, pnok := version["product_name"] + pv, pvok := version["product_version"] + + if pnok { + if pn.(string) == "" { + return fmt.Errorf("'product_name' is not given") + } + versionResource.ProductName = utils.StringPtr(pn.(string)) + } + if pvok { + if pv.(string) == "" { + return fmt.Errorf("'product_version' is not given") + } + versionResource.ProductVersion = utils.StringPtr(pv.(string)) + } + image.Version = versionResource + } + // List of clusters where image is requested to be placed at time of creation if refs, refsok := d.GetOk("cluster_references"); refsok && len(refs.([]interface{})) > 0 { image.InitialPlacementRefList = validateArrayRefValues(refs, "cluster")