Skip to content

Commit 8df9a8b

Browse files
committed
feat(Legacy_Vendor_Images):UI-42316:Terraform Development for Legacy Vendor Images
1 parent 7cbf81f commit 8df9a8b

File tree

7 files changed

+3967
-1513
lines changed

7 files changed

+3967
-1513
lines changed

common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go

Lines changed: 3771 additions & 1513 deletions
Large diffs are not rendered by default.

ibm/service/vpc/data_source_ibm_is_image.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ func DataSourceIBMISImage() *schema.Resource {
194194
Computed: true,
195195
Description: "The type of encryption used on the image",
196196
},
197+
"remote": {
198+
Type: schema.TypeList,
199+
Optional: true,
200+
Computed: true,
201+
Description: "If present, this property indicates that the resource associated with this reference is remote and therefore may not be directly retrievable.",
202+
Elem: &schema.Resource{
203+
Schema: map[string]*schema.Schema{
204+
"account": {
205+
Type: schema.TypeList,
206+
Optional: true,
207+
Computed: true,
208+
Description: "If present, this property indicates that the referenced resource is remote to this account, and identifies the owning account.",
209+
Elem: &schema.Resource{
210+
Schema: map[string]*schema.Schema{
211+
"id": {
212+
Type: schema.TypeString,
213+
Optional: true,
214+
Computed: true,
215+
Description: "The unique identifier for this resource group.",
216+
},
217+
"resource_type": {
218+
Type: schema.TypeString,
219+
Computed: true,
220+
Description: "The resource type.",
221+
},
222+
},
223+
},
224+
},
225+
},
226+
},
227+
},
197228
"source_volume": {
198229
Type: schema.TypeString,
199230
Computed: true,
@@ -341,6 +372,17 @@ func imageGetByName(d *schema.ResourceData, meta interface{}, name, visibility s
341372
resourceGroupList = append(resourceGroupList, resourceGroupMap)
342373
d.Set("resource_group", resourceGroupList)
343374
}
375+
376+
if image.Remote != nil {
377+
imageRemoteList := []map[string]interface{}{}
378+
imageRemoteMap, err := dataSourceImageRemote(image)
379+
if err != nil {
380+
return err
381+
}
382+
imageRemoteList = append(imageRemoteList, imageRemoteMap)
383+
d.Set(isImageRemote, imageRemoteList)
384+
}
385+
344386
d.Set("os", *image.OperatingSystem.Name)
345387
d.Set("architecture", *image.OperatingSystem.Architecture)
346388
d.Set("crn", *image.CRN)
@@ -394,6 +436,18 @@ func imageGetById(d *schema.ResourceData, meta interface{}, identifier string) e
394436
if *image.Status == "deprecated" {
395437
fmt.Printf("[WARN] Given image %s is deprecated and soon will be obsolete.", name)
396438
}
439+
440+
if image.Remote != nil {
441+
imageRemoteMap, err := dataSourceImageRemote(*image)
442+
if err != nil {
443+
return err
444+
}
445+
if len(imageRemoteMap) > 0 {
446+
imageRemoteList := []map[string]interface{}{imageRemoteMap}
447+
d.Set(isImageRemote, imageRemoteList)
448+
}
449+
}
450+
397451
if len(image.StatusReasons) > 0 {
398452
d.Set("status_reasons", dataSourceIBMIsImageFlattenStatusReasons(image.StatusReasons))
399453
}
@@ -495,6 +549,27 @@ func dataSourceImageCollectionCatalogOfferingToMap(imageCatalogOfferingItem vpcv
495549
return imageCatalogOfferingMap
496550
}
497551

552+
func dataSourceImageRemote(imageRemote vpcv1.Image) (map[string]interface{}, error) {
553+
result := map[string]interface{}{}
554+
555+
if imageRemote.Remote != nil && imageRemote.Remote.Account != nil {
556+
accountMap := map[string]interface{}{}
557+
558+
if imageRemote.Remote.Account.ID != nil {
559+
accountMap["id"] = *imageRemote.Remote.Account.ID
560+
}
561+
if imageRemote.Remote.Account.ResourceType != nil {
562+
accountMap["resource_type"] = *imageRemote.Remote.Account.ResourceType
563+
}
564+
565+
result["remote"] = map[string]interface{}{
566+
"account": accountMap,
567+
}
568+
}
569+
570+
return result, nil
571+
}
572+
498573
func dataSourceIBMIsImageFlattenStatusReasons(result []vpcv1.ImageStatusReason) (statusReasons []map[string]interface{}) {
499574
for _, statusReasonsItem := range result {
500575
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func DataSourceIBMISImages() *schema.Resource {
5252
Optional: true,
5353
Description: "Whether the image is publicly visible or private to the account",
5454
},
55+
isImageRemoteAccountId: {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
},
5559
isImageUserDataFormat: {
5660
Type: schema.TypeSet,
5761
Elem: &schema.Schema{Type: schema.TypeString},
@@ -178,6 +182,34 @@ func DataSourceIBMISImages() *schema.Resource {
178182
Computed: true,
179183
Description: "The operating system architecture",
180184
},
185+
"remote": {
186+
Type: schema.TypeList,
187+
Computed: true,
188+
Description: "If present, this property indicates that the resource associated with this reference is remote and therefore may not be directly retrievable.",
189+
Elem: &schema.Resource{
190+
Schema: map[string]*schema.Schema{
191+
"account": {
192+
Type: schema.TypeList,
193+
Computed: true,
194+
Description: "If present, this property indicates that the referenced resource is remote to this account, and identifies the owning account.",
195+
Elem: &schema.Resource{
196+
Schema: map[string]*schema.Schema{
197+
"id": {
198+
Type: schema.TypeString,
199+
Computed: true,
200+
Description: "The unique identifier for this resource group.",
201+
},
202+
"resource_type": {
203+
Type: schema.TypeString,
204+
Computed: true,
205+
Description: "The resource type.",
206+
},
207+
},
208+
},
209+
},
210+
},
211+
},
212+
},
181213
"resource_group": {
182214
Type: schema.TypeList,
183215
Computed: true,
@@ -334,6 +366,11 @@ func imageList(d *schema.ResourceData, meta interface{}) error {
334366
visibility = v.(string)
335367
}
336368

369+
var remoteAccountId string
370+
if v, ok := d.GetOk(isImageRemoteAccountId); ok {
371+
remoteAccountId = v.(string)
372+
}
373+
337374
var status string
338375
if v, ok := d.GetOk(isImageStatus); ok {
339376
status = v.(string)
@@ -350,6 +387,15 @@ func imageList(d *schema.ResourceData, meta interface{}) error {
350387
if imageName != "" {
351388
listImagesOptions.SetName(imageName)
352389
}
390+
391+
if remoteAccountId != "" {
392+
if remoteAccountId == "null" || remoteAccountId == "not:null" {
393+
listImagesOptions.SetRemoteAccountID(remoteAccountId)
394+
} else {
395+
listImagesOptions.SetRemoteAccountID(remoteAccountId)
396+
}
397+
}
398+
353399
if visibility != "" {
354400
listImagesOptions.SetVisibility(visibility)
355401
}
@@ -448,6 +494,18 @@ func imageList(d *schema.ResourceData, meta interface{}) error {
448494
catalogOfferingList = append(catalogOfferingList, catalogOfferingMap)
449495
l[isImageCatalogOffering] = catalogOfferingList
450496
}
497+
498+
if image.Remote != nil {
499+
imageRemoteMap, err := dataSourceImageRemote(image)
500+
if err != nil {
501+
return err
502+
}
503+
if len(imageRemoteMap) > 0 {
504+
imageRemoteList := []map[string]interface{}{imageRemoteMap}
505+
l["remote"] = imageRemoteList
506+
}
507+
}
508+
451509
accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *image.CRN, "", isImageAccessTagType)
452510
if err != nil {
453511
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/resource_ibm_is_image.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
isImageFile = "file"
3030
isImageVolume = "source_volume"
3131
isImageMinimumProvisionedSize = "size"
32+
isImageRemoteAccountId = "remote_account_id"
3233

3334
isImageResourceGroup = "resource_group"
3435
isImageEncryptedDataKey = "encrypted_data_key"
@@ -49,6 +50,8 @@ const (
4950
isImageDeprecate = "deprecate"
5051
isImageObsolete = "obsolete"
5152
isImageUserDataFormat = "user_data_format"
53+
54+
isImageRemote = "remote"
5255
)
5356

5457
func ResourceIBMISImage() *schema.Resource {

website/docs/d/is_image.html.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ data "ibm_is_image" "example" {
3434
}
3535
```
3636

37+
```terraform
38+
data "ibm_is_image" "example" {
39+
remote{
40+
account{
41+
id = "addgdfdfd"
42+
}
43+
}
44+
}
45+
```
46+
3747
## Argument reference
3848
Review the argument references that you can specify for your data source.
3949

@@ -47,6 +57,8 @@ Review the argument references that you can specify for your data source.
4757

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

60+
- `remote-account-id` - (Optional, String) Accepted values are `provider` or `user` or valid account_id.
61+
5062
## Attribute reference
5163
In addition to all argument reference list, you can access the following attribute references after your data source is created.
5264

0 commit comments

Comments
 (0)