Skip to content

Commit 35eed83

Browse files
committed
fix for instance force new bug with kmsKeyId and fixing the image test
1 parent be59f79 commit 35eed83

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

oci/core_image_test.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,23 @@ var (
1818
generateResourceFromRepresentationMap("oci_core_image", "test_image", Required, Create, imageRepresentation)
1919

2020
imageDataSourceRepresentation = map[string]interface{}{
21-
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
22-
"display_name": Representation{repType: Optional, create: `MyCustomImage`, update: `displayName2`},
23-
"operating_system": Representation{repType: Optional, create: `operatingSystem`},
24-
"operating_system_version": Representation{repType: Optional, create: `operatingSystemVersion`},
25-
"shape": Representation{repType: Optional, create: `shape`},
26-
"state": Representation{repType: Optional, create: `AVAILABLE`},
27-
"filter": RepresentationGroup{Required, imageDataSourceFilterRepresentation}}
21+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
22+
"display_name": Representation{repType: Optional, create: `MyCustomImage`, update: `displayName2`},
23+
"state": Representation{repType: Optional, create: `AVAILABLE`},
24+
"filter": RepresentationGroup{Required, imageDataSourceFilterRepresentation}}
2825
imageDataSourceFilterRepresentation = map[string]interface{}{
2926
"name": Representation{repType: Required, create: `id`},
3027
"values": Representation{repType: Required, create: []string{`${oci_core_image.test_image.id}`}},
3128
}
3229

3330
imageRepresentation = map[string]interface{}{
34-
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
35-
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
36-
"display_name": Representation{repType: Optional, create: `MyCustomImage`, update: `displayName2`},
37-
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
38-
"image_source_details": RepresentationGroup{Optional, imageImageSourceDetailsRepresentation},
39-
"instance_id": Representation{repType: Required, create: `${oci_core_instance.test_instance.id}`},
40-
"launch_mode": Representation{repType: Optional, create: `NATIVE`},
41-
"timeouts": RepresentationGroup{Required, timeoutsRepresentation},
42-
}
43-
imageImageSourceDetailsRepresentation = map[string]interface{}{
44-
"source_type": Representation{repType: Required, create: `objectStorageTuple`},
45-
"bucket_name": Representation{repType: Optional, create: `MyBucket`},
46-
"namespace_name": Representation{repType: Optional, create: `MyNamespace`},
47-
"object_name": Representation{repType: Optional, create: `image-to-import.qcow2`},
48-
"source_image_type": Representation{repType: Optional, create: `QCOW2`},
49-
"source_uri": Representation{repType: Optional, create: `https://objectstorage.us-phoenix-1.oraclecloud.com/n/MyNamespace/b/MyBucket/o/image-to-import.qcow2`},
31+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
32+
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
33+
"display_name": Representation{repType: Optional, create: `MyCustomImage`, update: `displayName2`},
34+
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
35+
"instance_id": Representation{repType: Required, create: `${oci_core_instance.test_instance.id}`},
36+
"launch_mode": Representation{repType: Optional, create: `NATIVE`},
37+
"timeouts": RepresentationGroup{Required, timeoutsRepresentation},
5038
}
5139

5240
timeoutsRepresentation = map[string]interface{}{
@@ -57,7 +45,6 @@ var (
5745
)
5846

5947
func TestCoreImageResource_basic(t *testing.T) {
60-
t.Skip("Long running test")
6148
provider := testAccProvider
6249
config := testProviderConfig()
6350

@@ -106,9 +93,7 @@ func TestCoreImageResource_basic(t *testing.T) {
10693
resource.TestCheckResourceAttr(resourceName, "display_name", "MyCustomImage"),
10794
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
10895
resource.TestCheckResourceAttrSet(resourceName, "id"),
109-
resource.TestCheckResourceAttr(resourceName, "image_source_details.#", "1"),
110-
resource.TestCheckResourceAttr(resourceName, "image_source_details.0.source_image_type", "QCOW2"),
111-
resource.TestCheckResourceAttr(resourceName, "image_source_details.0.source_type", "objectStorageTuple"),
96+
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
11297
resource.TestCheckResourceAttr(resourceName, "launch_mode", "NATIVE"),
11398
resource.TestCheckResourceAttrSet(resourceName, "operating_system"),
11499
resource.TestCheckResourceAttrSet(resourceName, "operating_system_version"),
@@ -133,9 +118,7 @@ func TestCoreImageResource_basic(t *testing.T) {
133118
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
134119
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
135120
resource.TestCheckResourceAttrSet(resourceName, "id"),
136-
resource.TestCheckResourceAttr(resourceName, "image_source_details.#", "1"),
137-
resource.TestCheckResourceAttr(resourceName, "image_source_details.0.source_image_type", "QCOW2"),
138-
resource.TestCheckResourceAttr(resourceName, "image_source_details.0.source_type", "objectStorageTuple"),
121+
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
139122
resource.TestCheckResourceAttr(resourceName, "launch_mode", "NATIVE"),
140123
resource.TestCheckResourceAttrSet(resourceName, "operating_system"),
141124
resource.TestCheckResourceAttrSet(resourceName, "operating_system_version"),

oci/core_instance_resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,11 @@ func (s *InstanceResourceCrud) mapToInstanceSourceDetails(fieldKeyFormat string)
918918
}
919919

920920
func InstanceSourceDetailsToMap(obj *oci_core.InstanceSourceDetails, bootVolume *oci_core.BootVolume, sourceDetailsFromConfig map[string]interface{}) map[string]interface{} {
921-
result := map[string]interface{}{}
921+
// We need to use the values provided by the customer to prevent force new in case the service does not return the value
922+
result := sourceDetailsFromConfig
923+
if result == nil {
924+
result = map[string]interface{}{}
925+
}
922926
switch v := (*obj).(type) {
923927
case oci_core.InstanceSourceViaBootVolumeDetails:
924928
result["source_type"] = "bootVolume"
@@ -935,9 +939,6 @@ func InstanceSourceDetailsToMap(obj *oci_core.InstanceSourceDetails, bootVolume
935939
// The service could omit the boot volume size in the InstanceSourceViaImageDetails, so use the boot volume
936940
// SizeInGBs property if that's the case.
937941
result["boot_volume_size_in_gbs"] = strconv.FormatInt(*bootVolume.SizeInGBs, 10)
938-
} else if sourceDetailsFromConfig != nil {
939-
// Last resort. If we can't query the boot volume size from service, use the config value.
940-
result["boot_volume_size_in_gbs"] = sourceDetailsFromConfig["boot_volume_size_in_gbs"]
941942
}
942943

943944
if v.KmsKeyId != nil {

oci/core_instance_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
instanceRepresentation = map[string]interface{}{
3939
"availability_domain": Representation{repType: Required, create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
4040
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
41-
"shape": Representation{repType: Required, create: `VM.Standard1.8`},
41+
"shape": Representation{repType: Required, create: `VM.Standard2.1`},
4242
"create_vnic_details": RepresentationGroup{Optional, instanceCreateVnicDetailsRepresentation},
4343
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
4444
"display_name": Representation{repType: Optional, create: `displayName`, update: `displayName2`},
@@ -98,7 +98,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
9898
provider oci {
9999
test_time_maintenance_reboot_due = "2030-01-01 00:00:00"
100100
}
101-
` + commonTestVariables()
101+
` + commonTestVariables() + KeyResourceDependencyConfig
102102

103103
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
104104
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
@@ -123,7 +123,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
123123
Check: resource.ComposeAggregateTestCheckFunc(
124124
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
125125
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
126-
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard1.8"),
126+
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard2.1"),
127127
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
128128
resource.TestCheckResourceAttr(resourceName, "time_maintenance_reboot_due", ""),
129129

@@ -165,7 +165,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
165165
resource.TestCheckResourceAttr(resourceName, "ipxe_script", "ipxeScript"),
166166
resource.TestCheckResourceAttr(resourceName, "metadata.%", "1"),
167167
resource.TestCheckResourceAttrSet(resourceName, "region"),
168-
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard1.8"),
168+
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard2.1"),
169169
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
170170
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
171171
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
@@ -208,7 +208,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
208208
resource.TestCheckResourceAttr(resourceName, "ipxe_script", "ipxeScript"),
209209
resource.TestCheckResourceAttr(resourceName, "metadata.%", "2"),
210210
resource.TestCheckResourceAttrSet(resourceName, "region"),
211-
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard1.8"),
211+
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard2.1"),
212212
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
213213
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
214214
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
@@ -250,7 +250,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
250250
resource.TestCheckResourceAttr(datasourceName, "instances.0.ipxe_script", "ipxeScript"),
251251
resource.TestCheckResourceAttr(datasourceName, "instances.0.metadata.%", "2"),
252252
resource.TestCheckResourceAttrSet(datasourceName, "instances.0.region"),
253-
resource.TestCheckResourceAttr(datasourceName, "instances.0.shape", "VM.Standard1.8"),
253+
resource.TestCheckResourceAttr(datasourceName, "instances.0.shape", "VM.Standard2.1"),
254254
resource.TestCheckResourceAttr(datasourceName, "instances.0.source_details.#", "1"),
255255
resource.TestCheckResourceAttrSet(datasourceName, "instances.0.source_details.0.source_id"),
256256
resource.TestCheckResourceAttr(datasourceName, "instances.0.source_details.0.source_type", "image"),
@@ -279,7 +279,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
279279
resource.TestCheckResourceAttr(singularDatasourceName, "ipxe_script", "ipxeScript"),
280280
resource.TestCheckResourceAttr(singularDatasourceName, "metadata.%", "2"),
281281
resource.TestCheckResourceAttrSet(singularDatasourceName, "region"),
282-
resource.TestCheckResourceAttr(singularDatasourceName, "shape", "VM.Standard1.8"),
282+
resource.TestCheckResourceAttr(singularDatasourceName, "shape", "VM.Standard2.1"),
283283
resource.TestCheckResourceAttr(singularDatasourceName, "source_details.#", "1"),
284284
resource.TestCheckResourceAttr(singularDatasourceName, "source_details.0.source_type", "image"),
285285
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
@@ -306,6 +306,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
306306
"extended_metadata",
307307
"hostname_label",
308308
"subnet_id",
309+
"source_details.0.kms_key_id", //TODO: Service is not returning this value, remove when the service returns it. COM-26394
309310
},
310311
ResourceName: resourceName,
311312
},

0 commit comments

Comments
 (0)