Skip to content

Commit 6d57acd

Browse files
committed
Resolving merge conflict in change log by incorporating both changes
1 parent 43088ef commit 6d57acd

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Added
44
- Support for importing Buckets and Pre-authenticated requests in Object Storage
55
- Support glob inclusion and exclusion patterns for object names allowed in Object Storage Lifecycle
6+
- Support for sorting for resources returned in `oci_core_images` data source
67

78
### Fixed
89
- Import functionality for Objects in Object Storage

examples/compute/image/datasources.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@ data "oci_core_images" "TFSupportedShapeImages" {
2828

2929
# Uncomment below to filter images that are a specific OS version
3030
#operating_system_version = "7.5"
31+
32+
# Uncomment below to sort images by creation time
33+
#sort_by = "TIMECREATED"
34+
# Default sort order for TIMECREATED is descending (DESC)
35+
#sort_order = "ASC"
36+
37+
# Uncomment below to sort images by display name, display name sort order is case-sensitive
38+
#sort_by = "DISPLAYNAME"
39+
# Default sort order for DISPLAYNAME is ascending (ASC)
40+
#sort_order = "DESC"
3141
}

oci/core_image_scenario_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func (s *ResourceCoreImageTestSuite) TestAccResourceCoreImage_objectStorageImage
9999
name = "launch_options.is_pv_encryption_in_transit_enabled"
100100
values = ["true"]
101101
}
102+
103+
sort_by = "TIMECREATED"
104+
sort_order = "DESC"
102105
}`, s.OperatingSystem),
103106
Check: resource.ComposeAggregateTestCheckFunc(
104107
resource.TestCheckResourceAttr("data.oci_core_images.t", "images.0.create_image_allowed", "true"),

oci/core_images_data_source.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/hashicorp/terraform/helper/schema"
10+
"github.com/hashicorp/terraform/helper/validation"
1011
oci_core "github.com/oracle/oci-go-sdk/core"
1112
)
1213

@@ -54,6 +55,22 @@ func CoreImagesDataSource() *schema.Resource {
5455
Optional: true,
5556
Deprecated: FieldDeprecated("page"),
5657
},
58+
"sort_by": {
59+
Type: schema.TypeString,
60+
Optional: true,
61+
ValidateFunc: validation.StringInSlice([]string{
62+
string(oci_core.ListImagesSortByTimecreated),
63+
string(oci_core.ListImagesSortByDisplayname),
64+
}, false),
65+
},
66+
"sort_order": {
67+
Type: schema.TypeString,
68+
Optional: true,
69+
ValidateFunc: validation.StringInSlice([]string{
70+
string(oci_core.ListImagesSortOrderAsc),
71+
string(oci_core.ListImagesSortOrderDesc),
72+
}, false),
73+
},
5774
},
5875
}
5976
}
@@ -118,6 +135,14 @@ func (s *CoreImagesDataSourceCrud) Get() error {
118135
request.Page = &tmp
119136
}
120137

138+
if sortBy, ok := s.D.GetOkExists("sort_by"); ok {
139+
request.SortBy = oci_core.ListImagesSortByEnum(sortBy.(string))
140+
}
141+
142+
if sortOrder, ok := s.D.GetOkExists("sort_order"); ok {
143+
request.SortOrder = oci_core.ListImagesSortOrderEnum(sortOrder.(string))
144+
}
145+
121146
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "core")
122147

123148
response, err := s.Client.ListImages(context.Background(), request)

oci/filters_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,37 @@ func TestApplyFilters_multiProperty(t *testing.T) {
642642
}
643643
}
644644

645+
// Test to validate that the Apply filters do not impact the original item order
646+
func TestApplyFilters_ElementOrder(t *testing.T) {
647+
items := []map[string]interface{}{
648+
{"letter": "a"},
649+
{"letter": "b"},
650+
{"letter": "c"},
651+
{"letter": "d"},
652+
}
653+
654+
testSchema := map[string]*schema.Schema{
655+
"letter": {
656+
Type: schema.TypeString,
657+
},
658+
}
659+
660+
filters := &schema.Set{F: func(interface{}) int { return 1 }}
661+
filters.Add(map[string]interface{}{
662+
"name": "letter",
663+
"values": []interface{}{"a", "d"},
664+
})
665+
666+
res := ApplyFilters(filters, items, testSchema)
667+
if len(res) != 2 {
668+
t.Errorf("Expected 2 result, got %d", len(res))
669+
}
670+
if res[0]["letter"] != "a" || res[1]["letter"] != "d" {
671+
t.Errorf("Expected sort order not retained, got %s %s", res[0]["letter"], res[1]["letter"])
672+
}
673+
674+
}
675+
645676
func TestGetValue_EmptyMap(t *testing.T) {
646677
item := map[string]interface{}{}
647678

website/docs/d/core_images.html.markdown

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Lists the available images in the specified compartment, including both
1313
[Oracle-provided images](https://docs.cloud.oracle.com/iaas/Content/Compute/References/images.htm) and
1414
[custom images](https://docs.cloud.oracle.com/iaas/Content/Compute/Tasks/managingcustomimages.htm) that have
1515
been created. The list of images returned is ordered to first show all
16-
Oracle-provided images, then all custom images.
16+
Oracle-provided images, then all custom images. Read more on [List Images](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/Image/ListImages)
1717

1818
The order of images returned may change when new images are released.
1919

@@ -31,8 +31,11 @@ data "oci_core_images" "test_images" {
3131
operating_system_version = "${var.image_operating_system_version}"
3232
shape = "${var.image_shape}"
3333
state = "${var.image_state}"
34+
sort_by = "${var.image_sort_by}"
35+
sort_order = "${var.image_sort_order}"
3436
}
3537
```
38+
For more detailed implementation refer the [image example](https://github.com/oracle/terraform-provider-oci/tree/master/examples/compute/image)
3639

3740
## Argument Reference
3841

@@ -44,7 +47,8 @@ The following arguments are supported:
4447
* `operating_system_version` - (Optional) The image's operating system version. Example: `7.2`
4548
* `shape` - (Optional) Shape name.
4649
* `state` - (Optional) A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
47-
50+
* `sort_by` - (Optional) Sort the resources returned, by creation time or display name. Example `TIMECREATED` or `DISPLAYNAME`.
51+
* `sort_order` - (Optional) The sort order to use, either ascending (`ASC`) or descending (`DESC`).
4852

4953
## Attributes Reference
5054

0 commit comments

Comments
 (0)