Skip to content

Commit 81df0d7

Browse files
committed
image partial availability
1 parent 2f12757 commit 81df0d7

File tree

6 files changed

+122
-3
lines changed

6 files changed

+122
-3
lines changed

ibm/service/vpc/data_source_ibm_is_image.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,25 @@ func DataSourceIBMISImage() *schema.Resource {
317317
Set: flex.ResourceIBMVPCHash,
318318
Description: "List of access tags",
319319
},
320+
"zones": &schema.Schema{
321+
Type: schema.TypeList,
322+
Computed: true,
323+
Description: "The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region.If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.",
324+
Elem: &schema.Resource{
325+
Schema: map[string]*schema.Schema{
326+
"href": &schema.Schema{
327+
Type: schema.TypeString,
328+
Computed: true,
329+
Description: "The URL for this zone.",
330+
},
331+
"name": &schema.Schema{
332+
Type: schema.TypeString,
333+
Computed: true,
334+
Description: "The globally unique name for this zone.",
335+
},
336+
},
337+
},
338+
},
320339
},
321340
}
322341
}
@@ -618,6 +637,17 @@ func imageGetById(context context.Context, d *schema.ResourceData, meta interfac
618637
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting allowed_use: %s", err), "(Data) ibm_is_image", "read")
619638
log.Println(tfErr.GetDiag())
620639
}
640+
zones := []map[string]interface{}{}
641+
for _, zonesItem := range image.Zones {
642+
zonesItemMap, err := DataSourceIBMIsImageZoneReferenceToMap(&zonesItem) // #nosec G601
643+
if err != nil {
644+
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_image", "read", "zones-to-map").GetDiag()
645+
}
646+
zones = append(zones, zonesItemMap)
647+
}
648+
if err = d.Set("zones", zones); err != nil {
649+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting zones: %s", err), "(Data) ibm_is_image", "read", "set-zones").GetDiag()
650+
}
621651
return nil
622652
}
623653

@@ -751,3 +781,9 @@ func DataSourceIBMIsImageAllowedUseToMap(model *vpcv1.ImageAllowedUse) (map[stri
751781
}
752782
return modelMap, nil
753783
}
784+
func DataSourceIBMIsImageZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) {
785+
modelMap := make(map[string]interface{})
786+
modelMap["href"] = *model.Href
787+
modelMap["name"] = *model.Name
788+
return modelMap, nil
789+
}

ibm/service/vpc/data_source_ibm_is_images.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,25 @@ func DataSourceIBMISImages() *schema.Resource {
340340
Set: flex.ResourceIBMVPCHash,
341341
Description: "List of access tags",
342342
},
343+
"zones": &schema.Schema{
344+
Type: schema.TypeList,
345+
Computed: true,
346+
Description: "The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region.If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.",
347+
Elem: &schema.Resource{
348+
Schema: map[string]*schema.Schema{
349+
"href": &schema.Schema{
350+
Type: schema.TypeString,
351+
Computed: true,
352+
Description: "The URL for this zone.",
353+
},
354+
"name": &schema.Schema{
355+
Type: schema.TypeString,
356+
Computed: true,
357+
Description: "The globally unique name for this zone.",
358+
},
359+
},
360+
},
361+
},
343362
},
344363
},
345364
},
@@ -561,6 +580,17 @@ func imageList(context context.Context, d *schema.ResourceData, meta interface{}
561580
"Error on get of resource image (%s) access tags: %s", d.Id(), err)
562581
}
563582
l[isImageAccessTags] = accesstags
583+
584+
zones := []map[string]interface{}{}
585+
for _, zonesItem := range image.Zones {
586+
zonesItemMap, _ := DataSourceIBMIsImagesZoneReferenceToMap(&zonesItem) // #nosec G601
587+
if err != nil {
588+
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_is_image", "read")
589+
log.Println(tfErr.GetDiag())
590+
}
591+
zones = append(zones, zonesItemMap)
592+
}
593+
l["zones"] = zones
564594
imagesInfo = append(imagesInfo, l)
565595
}
566596
d.SetId(dataSourceIBMISImagesID(d))
@@ -574,3 +604,9 @@ func imageList(context context.Context, d *schema.ResourceData, meta interface{}
574604
func dataSourceIBMISImagesID(d *schema.ResourceData) string {
575605
return time.Now().UTC().String()
576606
}
607+
func DataSourceIBMIsImagesZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) {
608+
modelMap := make(map[string]interface{})
609+
modelMap["href"] = *model.Href
610+
modelMap["name"] = *model.Name
611+
return modelMap, nil
612+
}

ibm/service/vpc/resource_ibm_is_image.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,25 @@ func ResourceIBMISImage() *schema.Resource {
291291
},
292292
},
293293
},
294+
"zones": &schema.Schema{
295+
Type: schema.TypeList,
296+
Computed: true,
297+
Description: "The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region.If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.",
298+
Elem: &schema.Resource{
299+
Schema: map[string]*schema.Schema{
300+
"href": &schema.Schema{
301+
Type: schema.TypeString,
302+
Computed: true,
303+
Description: "The URL for this zone.",
304+
},
305+
"name": &schema.Schema{
306+
Type: schema.TypeString,
307+
Computed: true,
308+
Description: "The globally unique name for this zone.",
309+
},
310+
},
311+
},
312+
},
294313
},
295314
}
296315
}
@@ -999,6 +1018,18 @@ func imgGet(context context.Context, d *schema.ResourceData, meta interface{}, i
9991018
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_image", "read", "set-resource_group").GetDiag()
10001019
}
10011020
}
1021+
zones := []map[string]interface{}{}
1022+
for _, zonesItem := range image.Zones {
1023+
zonesItemMap, err := ResourceIBMIsImageZoneReferenceToMap(&zonesItem) // #nosec G601
1024+
if err != nil {
1025+
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_image", "read", "zones-to-map").GetDiag()
1026+
}
1027+
zones = append(zones, zonesItemMap)
1028+
}
1029+
if err = d.Set("zones", zones); err != nil {
1030+
err = fmt.Errorf("Error setting zones: %s", err)
1031+
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_image", "read", "set-zones").GetDiag()
1032+
}
10021033
return nil
10031034
}
10041035

@@ -1135,3 +1166,9 @@ func ResourceIBMIsImageImageAllowUseToMap(model *vpcv1.ImageAllowedUse) (map[str
11351166
}
11361167
return modelMap, nil
11371168
}
1169+
func ResourceIBMIsImageZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) {
1170+
modelMap := make(map[string]interface{})
1171+
modelMap["href"] = *model.Href
1172+
modelMap["name"] = *model.Name
1173+
return modelMap, nil
1174+
}

website/docs/d/is_image.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ In addition to all argument reference list, you can access the following attribu
136136
**&#x2022;** `cloud_init`: user_data will be interpreted according to the cloud-init standard.</br>
137137
**&#x2022;** `esxi_kickstart`: user_data will be interpreted as a VMware ESXi installation script.</br>
138138
**&#x2022;** `ipxe`: user_data will be interpreted as a single URL to an iPXE script or as the text of an iPXE script.</br>
139+
- `zones` - (List) The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region.If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.
140+
Nested schema for **zones**:
141+
- `href` - (String) The URL for this zone.
142+
- `name` - (String) The globally unique name for this zone.
143+

website/docs/d/is_images.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ data "ibm_is_image" "example" {
3737
}
3838
```
3939

40-
```
4140
## Argument reference
4241

4342
Review the argument references that you can specify for your data source.
@@ -138,6 +137,9 @@ You can access the following attribute references after your data source is crea
138137
- `id` – (Computed, String) The unique identifier for this account.
139138
- `resource_type` – (Computed, String) The resource type.
140139

141-
140+
- `zones` - (List) The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region. If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.
141+
Nested schema for **zones**:
142+
- `href` - (String) The URL for this zone.
143+
- `name` - (String) The globally unique name for this zone.
142144

143145

website/docs/r/is_image.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ In addition to all argument reference list, you can access the following attribu
203203
**&#x2022;** `ipxe`: user_data will be interpreted as a single URL to an iPXE script or as the text of an iPXE script.</br>
204204

205205
- `visibility` - (String) The access scope of an image such as `private` or `public`.
206-
206+
- `zones` - (List) The zones in which this image is available for use.If the image has a status of `available` or `deprecated`, this will include all zones in the region.If the image has a status of `partially_available`, this will include one or more zones in the region. If the image has a status of `failed`, `obsolete`, `pending`, or `unusable`, this will be empty.
207+
Nested schema for **zones**:
208+
- `href` - (String) The URL for this zone.
209+
- `name` - (String) The globally unique name for this zone.
207210

208211
## Import
209212
The `ibm_is_image` resource can be imported by using image ID.

0 commit comments

Comments
 (0)