Skip to content

Commit a311a62

Browse files
committed
feat(legacy-vendor-images):added support for vpc-services
1 parent c9676d6 commit a311a62

10 files changed

+227
-11
lines changed

ibm/service/vpc/data_source_ibm_is_image.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,37 @@ func DataSourceIBMISImage() *schema.Resource {
197197
Computed: true,
198198
Description: "The type of encryption used on the image",
199199
},
200+
"remote": {
201+
Type: schema.TypeList,
202+
Optional: true,
203+
Computed: true,
204+
Description: "If present, this property indicates that the resource associated with this reference is remote and therefore may not be directly retrievable.",
205+
Elem: &schema.Resource{
206+
Schema: map[string]*schema.Schema{
207+
"account": {
208+
Type: schema.TypeList,
209+
Optional: true,
210+
Computed: true,
211+
Description: "If present, this property indicates that the referenced resource is remote to this account, and identifies the owning account.",
212+
Elem: &schema.Resource{
213+
Schema: map[string]*schema.Schema{
214+
"id": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
Computed: true,
218+
Description: "The unique identifier for this resource group.",
219+
},
220+
"resource_type": {
221+
Type: schema.TypeString,
222+
Computed: true,
223+
Description: "The resource type.",
224+
},
225+
},
226+
},
227+
},
228+
},
229+
},
230+
},
200231
"source_volume": {
201232
Type: schema.TypeString,
202233
Computed: true,
@@ -366,6 +397,18 @@ func imageGetByName(context context.Context, d *schema.ResourceData, meta interf
366397
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_group: %s", err), "(Data) ibm_is_image", "read", "set-resource_group").GetDiag()
367398
}
368399
}
400+
if image.Remote != nil {
401+
imageRemoteList := []map[string]interface{}{}
402+
imageRemoteMap, err := dataSourceImageRemote(image)
403+
if err != nil {
404+
return err
405+
}
406+
imageRemoteList = append(imageRemoteList, imageRemoteMap)
407+
if err = d.Set(isImageRemote, imageRemoteList); err != nil {
408+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting remote: %s", err), "(Data) ibm_is_image", "read", "set-remote").GetDiag()
409+
}
410+
}
411+
369412
if err = d.Set("os", image.OperatingSystem.Name); err != nil {
370413
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting os: %s", err), "(Data) ibm_is_image", "read", "set-os").GetDiag()
371414
}
@@ -443,6 +486,17 @@ func imageGetById(context context.Context, d *schema.ResourceData, meta interfac
443486
if *image.Status == "deprecated" {
444487
fmt.Printf("[WARN] Given image %s is deprecated and soon will be obsolete.", name)
445488
}
489+
490+
if image.Remote != nil {
491+
imageRemoteList := []map[string]interface{}{}
492+
imageRemoteMap, err := dataSourceImageRemote(*image)
493+
if err != nil {
494+
return err
495+
}
496+
imageRemoteList = append(imageRemoteList, imageRemoteMap)
497+
d.Set(isImageRemote, imageRemoteList)
498+
}
499+
446500
if len(image.StatusReasons) > 0 {
447501
if err = d.Set("status_reasons", dataSourceIBMIsImageFlattenStatusReasons(image.StatusReasons)); err != nil {
448502
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status_reasons: %s", err), "(Data) ibm_is_image", "read", "set-status_reasons").GetDiag()
@@ -571,6 +625,27 @@ func dataSourceImageCollectionCatalogOfferingToMap(imageCatalogOfferingItem vpcv
571625
return imageCatalogOfferingMap
572626
}
573627

628+
func dataSourceImageRemote(imageRemote vpcv1.Image) (map[string]interface{}, error) {
629+
if imageRemote.Remote == nil || imageRemote.Remote.Account == nil {
630+
return nil, nil
631+
}
632+
633+
accountMap := map[string]interface{}{}
634+
635+
if imageRemote.Remote.Account.ID != nil {
636+
accountMap["id"] = *imageRemote.Remote.Account.ID
637+
}
638+
if imageRemote.Remote.Account.ResourceType != nil {
639+
accountMap["resource_type"] = *imageRemote.Remote.Account.ResourceType
640+
}
641+
642+
remoteMap := map[string]interface{}{
643+
"account": []interface{}{accountMap},
644+
}
645+
646+
return remoteMap, nil
647+
}
648+
574649
func dataSourceIBMIsImageFlattenStatusReasons(result []vpcv1.ImageStatusReason) (statusReasons []map[string]interface{}) {
575650
for _, statusReasonsItem := range result {
576651
statusReasons = append(statusReasons, dataSourceIBMIsImageStatusReasonToMap(&statusReasonsItem))

ibm/service/vpc/data_source_ibm_is_image_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ func TestAccIBMISImageDataSource_With_VisibiltyPrivate(t *testing.T) {
174174
})
175175
}
176176

177+
func TestAccIBMISImageDataSourceRemoteAccountId(t *testing.T) {
178+
resName := "data.ibm_is_image.test1"
179+
180+
resource.Test(t, resource.TestCase{
181+
PreCheck: func() { acc.TestAccPreCheck(t) },
182+
Providers: acc.TestAccProviders,
183+
Steps: []resource.TestStep{
184+
{
185+
Config: testAccCheckIBMISCatalogImageDataSourceRemoteAccountId(),
186+
Check: resource.ComposeTestCheckFunc(
187+
resource.TestCheckResourceAttrSet(resName, "remote"),
188+
),
189+
},
190+
},
191+
})
192+
}
193+
177194
func testAccCheckIBMISImageDataSourceConfig(imageName string) string {
178195
return fmt.Sprintf(`
179196
resource "ibm_is_image" "isExampleImage" {
@@ -248,3 +265,10 @@ func testAccCheckIBMISImageDataSourceWithVisibilityPrivate(imageName, visibility
248265
visibility = "%s"
249266
}`, acc.Image_cos_url, imageName, acc.Image_operating_system, visibility)
250267
}
268+
269+
func testAccCheckIBMISCatalogImageDataSourceRemoteAccountId() string {
270+
return fmt.Sprintf(`
271+
data "ibm_is_images" "test1" {
272+
catalog_managed = true
273+
}`)
274+
}

ibm/service/vpc/data_source_ibm_is_images.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
isImages = "images"
2121
isImagesResourceGroupID = "resource_group"
2222
isImageCatalogManaged = "catalog_managed"
23+
isImageRemoteAccountId = "remote_account_id"
2324
)
2425

2526
func DataSourceIBMISImages() *schema.Resource {
@@ -54,6 +55,11 @@ func DataSourceIBMISImages() *schema.Resource {
5455
Optional: true,
5556
Description: "Whether the image is publicly visible or private to the account",
5657
},
58+
isImageRemoteAccountId: {
59+
Type: schema.TypeString,
60+
Optional: true,
61+
Description: "Filters the collection to images with a remote.account.id property matching the specified account identifier.",
62+
},
5763
isImageUserDataFormat: {
5864
Type: schema.TypeSet,
5965
Elem: &schema.Schema{Type: schema.TypeString},
@@ -180,6 +186,34 @@ func DataSourceIBMISImages() *schema.Resource {
180186
Computed: true,
181187
Description: "The operating system architecture",
182188
},
189+
"remote": {
190+
Type: schema.TypeList,
191+
Computed: true,
192+
Description: "If present, this property indicates that the resource associated with this reference is remote and therefore may not be directly retrievable.",
193+
Elem: &schema.Resource{
194+
Schema: map[string]*schema.Schema{
195+
"account": {
196+
Type: schema.TypeList,
197+
Computed: true,
198+
Description: "If present, this property indicates that the referenced resource is remote to this account, and identifies the owning account.",
199+
Elem: &schema.Resource{
200+
Schema: map[string]*schema.Schema{
201+
"id": {
202+
Type: schema.TypeString,
203+
Computed: true,
204+
Description: "The unique identifier for this resource group.",
205+
},
206+
"resource_type": {
207+
Type: schema.TypeString,
208+
Computed: true,
209+
Description: "The resource type.",
210+
},
211+
},
212+
},
213+
},
214+
},
215+
},
216+
},
183217
"resource_group": {
184218
Type: schema.TypeList,
185219
Computed: true,
@@ -338,6 +372,10 @@ func imageList(context context.Context, d *schema.ResourceData, meta interface{}
338372
visibility = v.(string)
339373
}
340374

375+
var remoteAccountId string
376+
if v, ok := d.GetOk(isImageRemoteAccountId); ok {
377+
remoteAccountId = v.(string)
378+
}
341379
var status string
342380
if v, ok := d.GetOk(isImageStatus); ok {
343381
status = v.(string)
@@ -354,6 +392,19 @@ func imageList(context context.Context, d *schema.ResourceData, meta interface{}
354392
if imageName != "" {
355393
listImagesOptions.SetName(imageName)
356394
}
395+
396+
if remoteAccountId != "" {
397+
if remoteAccountId == "user" {
398+
remoteAccountId = "null"
399+
listImagesOptions.SetRemoteAccountID(remoteAccountId)
400+
} else if remoteAccountId == "provider" {
401+
remoteAccountId = "not:null"
402+
listImagesOptions.SetRemoteAccountID(remoteAccountId)
403+
} else {
404+
listImagesOptions.SetRemoteAccountID(remoteAccountId)
405+
}
406+
}
407+
357408
if visibility != "" {
358409
listImagesOptions.SetVisibility(visibility)
359410
}
@@ -454,6 +505,17 @@ func imageList(context context.Context, d *schema.ResourceData, meta interface{}
454505
catalogOfferingList = append(catalogOfferingList, catalogOfferingMap)
455506
l[isImageCatalogOffering] = catalogOfferingList
456507
}
508+
509+
if image.Remote != nil {
510+
imageRemoteMap, err := dataSourceImageRemote(image)
511+
if err != nil {
512+
return err
513+
}
514+
if len(imageRemoteMap) > 0 {
515+
l["remote"] = []interface{}{imageRemoteMap}
516+
}
517+
}
518+
457519
accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *image.CRN, "", isImageAccessTagType)
458520
if err != nil {
459521
log.Printf(

ibm/service/vpc/data_source_ibm_is_images_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ func TestAccIBMISImageDataSource_With_FilterVisibilty(t *testing.T) {
9696
})
9797
}
9898

99+
func TestAccIBMISImageDataSource_With_FilterRemoteAccountId(t *testing.T) {
100+
resName := "data.ibm_is_images.test1"
101+
resource.Test(t, resource.TestCase{
102+
PreCheck: func() { acc.TestAccPreCheck(t) },
103+
Providers: acc.TestAccProviders,
104+
Steps: []resource.TestStep{
105+
{
106+
Config: testAccCheckIBMISImagesDataSourceWithRemoteAccountId("user"),
107+
Check: resource.ComposeTestCheckFunc(
108+
resource.TestCheckResourceAttrSet(resName, "remote"),
109+
),
110+
},
111+
},
112+
})
113+
}
114+
99115
func TestAccIBMISImageDataSource_With_FilterStatus(t *testing.T) {
100116
resName := "data.ibm_is_images.test1"
101117
resource.Test(t, resource.TestCase{
@@ -149,3 +165,11 @@ func testAccCheckIBMISImagesDataSourceWithStatusPublic(status string) string {
149165
}
150166
`, status)
151167
}
168+
169+
func testAccCheckIBMISImagesDataSourceWithRemoteAccountId(remoteAccountId string) string {
170+
return fmt.Sprintf(`
171+
data "ibm_is_images" "test1" {
172+
remote_account_id = "%s"
173+
}
174+
`, remoteAccountId)
175+
}

ibm/service/vpc/data_source_ibm_is_instance_profile.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ func instanceProfileGet(context context.Context, d *schema.ResourceData, meta in
980980

981981
// Manufacturer details added.
982982
if profile.VcpuManufacturer != nil {
983-
err = d.Set(isInstanceVCPUManufacturer, dataSourceInstanceProfileFlattenVcpuManufacture(*profile.VcpuManufacturer))
983+
err = d.Set(isInstanceVCPUManufacturer, dataSourceInstanceProfileFlattenVcpuManufacture(*&profile.VcpuManufacturer))
984984
if err != nil {
985985
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting vcpu_manufacturer: %s", err), "(Data) ibm_is_instance_profile", "read", "set-vcpu_manufacturer").GetDiag()
986986
}
@@ -1290,22 +1290,22 @@ func dataSourceInstanceProfileVcpuArchitectureToMap(vcpuArchitectureItem vpcv1.I
12901290
}
12911291

12921292
/* Changes for the AMD Support VCPU Manufacturer */
1293-
func dataSourceInstanceProfileFlattenVcpuManufacture(result vpcv1.InstanceProfileVcpuManufacturer) (fl []map[string]interface{}) {
1293+
func dataSourceInstanceProfileFlattenVcpuManufacture(result vpcv1.InstanceProfileVcpuManufacturerIntf) (fl []map[string]interface{}) {
12941294
fl = []map[string]interface{}{}
12951295
finalMap := dataSourceInstanceProfileVcpuManufacturerToMap(result)
12961296
fl = append(fl, finalMap)
12971297

12981298
return fl
12991299
}
13001300

1301-
func dataSourceInstanceProfileVcpuManufacturerToMap(vcpuManufacutererItem vpcv1.InstanceProfileVcpuManufacturer) (vcpuManufacturerMap map[string]interface{}) {
1301+
func dataSourceInstanceProfileVcpuManufacturerToMap(vcpuManufacutererItem vpcv1.InstanceProfileVcpuManufacturerIntf) (vcpuManufacturerMap map[string]interface{}) {
13021302
vcpuManufacturerMap = map[string]interface{}{}
13031303

1304-
if vcpuManufacutererItem.Type != nil {
1305-
vcpuManufacturerMap["type"] = vcpuManufacutererItem.Type
1306-
}
1307-
if vcpuManufacutererItem.Value != nil {
1308-
vcpuManufacturerMap["value"] = vcpuManufacutererItem.Value
1304+
if vcpuManufacutererItem != nil {
1305+
if vcpuManufacturer, ok := vcpuManufacutererItem.(*vpcv1.InstanceProfileVcpuManufacturer); ok {
1306+
vcpuManufacturerMap["type"] = vcpuManufacturer.Type
1307+
vcpuManufacturerMap["value"] = vcpuManufacturer.Value
1308+
}
13091309
}
13101310

13111311
return vcpuManufacturerMap

ibm/service/vpc/data_source_ibm_is_instance_profiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ func instanceProfilesList(context context.Context, d *schema.ResourceData, meta
952952
// reduce the line of code here. - sumit's suggestions
953953
if profile.VcpuManufacturer != nil {
954954
vcpuManufacturerList := []map[string]interface{}{}
955-
vcpuManufacturerMap := dataSourceInstanceProfileVcpuManufacturerToMap(*profile.VcpuManufacturer)
955+
vcpuManufacturerMap := dataSourceInstanceProfileVcpuManufacturerToMap(profile.VcpuManufacturer)
956956
vcpuManufacturerList = append(vcpuManufacturerList, vcpuManufacturerMap)
957957
l["vcpu_manufacturer"] = vcpuManufacturerList
958958
}

ibm/service/vpc/data_source_ibm_is_vpn_gateway_connection_local_cidrs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func dataSourceIBMIsVPNGatewayConnectionLocalCidrsRead(context context.Context,
5252
return tfErr.GetDiag()
5353
}
5454

55-
listVPNGatewayConnectionsLocalCidrsOptions := &vpcv1.ListVPNGatewayConnectionsLocalCIDRsOptions{}
55+
listVPNGatewayConnectionsLocalCidrsOptions := &vpcv1.ListVPNGatewayConnectionsPeerCIDRsOptions{}
5656

5757
listVPNGatewayConnectionsLocalCidrsOptions.SetVPNGatewayID(d.Get("vpn_gateway").(string))
5858
listVPNGatewayConnectionsLocalCidrsOptions.SetID(d.Get("vpn_gateway_connection").(string))

ibm/service/vpc/resource_ibm_is_image.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const (
5151
isImageDeprecate = "deprecate"
5252
isImageObsolete = "obsolete"
5353
isImageUserDataFormat = "user_data_format"
54+
55+
isImageRemote = "remote"
5456
)
5557

5658
func ResourceIBMISImage() *schema.Resource {

website/docs/d/is_image.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Review the argument references that you can specify for your data source.
4747

4848
- `visibility` - (Optional, String) The visibility of the image. Accepted values are `public` or `private`.
4949

50+
5051
## Attribute reference
5152
In addition to all argument reference list, you can access the following attribute references after your data source is created.
5253

@@ -103,6 +104,15 @@ In addition to all argument reference list, you can access the following attribu
103104

104105
- `source_volume` - The source volume id of the image.
105106
- `user_data_format` - (String) The user data format for this image.
107+
- `remote` - (Optional, List) If present, this property indicates that the resource associated with this reference is remote and therefore may not be directly retrievable.
108+
109+
**Nested schema for `remote`:**
110+
- `account` - (Optional, List) Indicates that the referenced resource is remote to this account, and identifies the owning account.
111+
112+
**Nested schema for `account`:**
113+
- `id` – (Computed, String) The unique identifier for this account.
114+
- `resource_type` – (Computed, String) The resource type.
115+
106116

107117
~> **Note:** </br> Supported values are : </br>
108118
**&#x2022;** `cloud_init`: user_data will be interpreted according to the cloud-init standard.</br>

0 commit comments

Comments
 (0)