Skip to content

Commit 090f889

Browse files
committed
Instances: Add missing state field to datasource
This was omitted from the schema; even though it was plumbed through to the SDK. Also add a test to cover this field. This fixes github issue #478
1 parent 3b3aae2 commit 090f889

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

provider/core_instances_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func InstancesDataSource() *schema.Resource {
3939
Optional: true,
4040
Deprecated: crud.FieldDeprecated("page"),
4141
},
42+
"state": {
43+
Type: schema.TypeString,
44+
Optional: true,
45+
},
4246
"instances": {
4347
Type: schema.TypeList,
4448
Computed: true,

provider/core_instances_data_source_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,41 @@ func (s *DatasourceCoreInstanceTestSuite) TestAccDatasourceCoreInstance_basic()
114114
resource.TestCheckResourceAttr(s.ResourceName, "instances.0.hostname_label", ""),
115115
),
116116
},
117+
// Check that the optional "state" field can be queried on
118+
{
119+
Config: s.Config + s.TokenFn(`
120+
data "oci_core_instances" "t" {
121+
compartment_id = "${var.compartment_id}"
122+
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
123+
display_name = "{{.token}}"
124+
state = "{{.lifecycleState1}}"
125+
filter {
126+
name = "id"
127+
values = ["${oci_core_instance.t.id}"]
128+
}
129+
}
130+
131+
data "oci_core_instances" "t2" {
132+
compartment_id = "${var.compartment_id}"
133+
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
134+
display_name = "{{.token}}"
135+
state = "{{.lifecycleState2}}"
136+
filter {
137+
name = "id"
138+
values = ["${oci_core_instance.t.id}"]
139+
}
140+
}`,
141+
map[string]string{
142+
"lifecycleState1": string(core.InstanceLifecycleStateRunning),
143+
"lifecycleState2": string(core.InstanceLifecycleStateTerminated),
144+
},
145+
),
146+
Check: resource.ComposeTestCheckFunc(
147+
resource.TestCheckResourceAttr(s.ResourceName, "instances.#", "1"),
148+
resource.TestCheckResourceAttr(s.ResourceName, "instances.0.state", string(core.InstanceLifecycleStateRunning)),
149+
resource.TestCheckResourceAttr("data.oci_core_instances.t2", "instances.#", "0"),
150+
),
151+
},
117152
},
118153
},
119154
)

0 commit comments

Comments
 (0)