Skip to content

Commit 02521e1

Browse files
authored
Merge pull request #686 from terraform-providers/v3.11.2
Revert "Add a customdiff into Instance resource to track nested metad…
2 parents ced8eef + 564decb commit 02521e1

File tree

11 files changed

+35
-329
lines changed

11 files changed

+35
-329
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 3.11.2 (Unreleased)
2+
3+
### Fixed
4+
- Reverted previous fix for immutable `metadata` fields `ssh_authorized_keys` and `user_data` that results in new instances due to a crash when using interpolations in TypeMap with customdiff (Issue #685)
5+
26
## 3.11.1 (January 08, 2019)
37

48
### Changed

oci/core_instance_resource.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/hashicorp/terraform/helper/customdiff"
15-
1614
"github.com/hashicorp/terraform/helper/schema"
1715
"github.com/hashicorp/terraform/helper/validation"
1816

@@ -326,15 +324,6 @@ func InstanceResource() *schema.Resource {
326324
Computed: true,
327325
},
328326
},
329-
// CustomizeDiff for Instance resource
330-
// Updates of 'ssh_authorized_keys' and 'user_data' in Instance 'metadata' should result in Force New
331-
CustomizeDiff: customdiff.All(
332-
customdiff.ForceNewIfChange("metadata", func(old, new, meta interface{}) bool {
333-
oldMetadataMap := objectMapToStringMap(old.(map[string]interface{}))
334-
newMetadataMap := objectMapToStringMap(new.(map[string]interface{}))
335-
return (oldMetadataMap["ssh_authorized_keys"] != newMetadataMap["ssh_authorized_keys"]) || (oldMetadataMap["user_data"] != newMetadataMap["user_data"])
336-
}),
337-
),
338327
}
339328
}
340329

@@ -583,6 +572,16 @@ func (s *InstanceResourceCrud) Update() error {
583572

584573
response, err := s.Client.UpdateInstance(context.Background(), request)
585574
if err != nil {
575+
if response.RawResponse.StatusCode == 400 &&
576+
strings.Contains(err.Error(), "metadata field cannot be updated") {
577+
return fmt.Errorf(`%s
578+
579+
To change 'ssh_authorized_keys' or 'user_data' properties in the
580+
'metadata' field, the resource must be tainted and recreated.
581+
Use the terraform "taint" command to target this resource then
582+
run apply again.`, err)
583+
}
584+
586585
return err
587586
}
588587

oci/core_instance_resource_test.go

Lines changed: 20 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
8787
freeform_tags = { "Department" = "Accounting"}
8888
metadata {
8989
ssh_authorized_keys = "${var.ssh_public_key}"
90-
user_data = "ZWNobyBoZWxsbw=="
90+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
9191
}
9292
extended_metadata {
9393
keyA = "valA"
@@ -117,7 +117,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
117117
resource.TestCheckResourceAttr(s.ResourceName, "hostname_label", "hostname1"),
118118
resource.TestCheckResourceAttr(s.ResourceName, "shape", "VM.Standard1.8"),
119119
resource.TestCheckResourceAttr(s.ResourceName, "metadata.%", "2"),
120-
resource.TestCheckResourceAttr(s.ResourceName, "metadata.user_data", "ZWNobyBoZWxsbw=="),
120+
resource.TestCheckResourceAttr(s.ResourceName, "metadata.user_data", "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="),
121121
resource.TestCheckResourceAttrSet(s.ResourceName, "metadata.ssh_authorized_keys"),
122122
resource.TestCheckResourceAttr(s.ResourceName, "extended_metadata.%", "2"),
123123
resource.TestCheckResourceAttr(s.ResourceName, "extended_metadata.keyA", "valA"),
@@ -159,7 +159,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
159159
shape = "VM.Standard1.8"
160160
metadata {
161161
ssh_authorized_keys = "${var.ssh_public_key}"
162-
user_data = "ZWNobyBoZWxsbw=="
162+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
163163
}
164164
extended_metadata {
165165
keyA = "valA"
@@ -188,7 +188,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
188188
shape = "VM.Standard1.8"
189189
metadata {
190190
ssh_authorized_keys = "${var.ssh_public_key}"
191-
user_data = "ZWNobyBoZWxsbw=="
191+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
192192
}
193193
extended_metadata {
194194
keyA = "valA"
@@ -215,10 +215,10 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
215215
defined_tags = "${map(
216216
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value2"
217217
)}"
218-
freeform_tags = { "CostCenter" = "42"}
218+
freeform_tags = { "CostCenter" = "42"}
219219
metadata {
220220
ssh_authorized_keys = "${var.ssh_public_key}"
221-
user_data = "ZWNobyBoZWxsbw=="
221+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
222222
}
223223
extended_metadata {
224224
keyA = "valA"
@@ -248,7 +248,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
248248
subnet_id = "${oci_core_subnet.t.id}"
249249
metadata {
250250
ssh_authorized_keys = "${var.ssh_public_key}"
251-
user_data = "ZWNobyBoZWxsbw=="
251+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
252252
}
253253
extended_metadata {
254254
keyA = "valA"
@@ -295,7 +295,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
295295
subnet_id = "${oci_core_subnet.t.id}"
296296
metadata {
297297
ssh_authorized_keys = "${var.ssh_public_key}"
298-
user_data = "ZWNobyBoZWxsbw=="
298+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
299299
}
300300
extended_metadata {
301301
keyA = "valA"
@@ -329,7 +329,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
329329
subnet_id = "${oci_core_subnet.t.id}"
330330
metadata {
331331
ssh_authorized_keys = "${var.ssh_public_key}"
332-
user_data = "ZWNobyBoZWxsbw=="
332+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
333333
}
334334
extended_metadata {
335335
keyA = "valA"
@@ -377,7 +377,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
377377
display_name = "-tf-instance"
378378
metadata {
379379
ssh_authorized_keys = "${var.ssh_public_key}"
380-
user_data = "ZWNobyBoZWxsbw=="
380+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
381381
}
382382
extended_metadata {
383383
keyA = "valA"
@@ -392,7 +392,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
392392
defined_tags = "${map(
393393
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value"
394394
)}"
395-
freeform_tags = { "Department" = "Accounting" }
395+
freeform_tags = { "Department" = "Accounting" }
396396
}
397397
}
398398
data "oci_core_vnic_attachments" "t" {
@@ -432,7 +432,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
432432
display_name = "-tf-instance"
433433
metadata {
434434
ssh_authorized_keys = "${var.ssh_public_key}"
435-
user_data = "ZWNobyBoZWxsbw=="
435+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
436436
}
437437
extended_metadata {
438438
keyA = "valA"
@@ -447,7 +447,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
447447
defined_tags = "${map(
448448
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue"
449449
)}"
450-
freeform_tags = { "Department" = "Finance" }
450+
freeform_tags = { "Department" = "Finance" }
451451
}
452452
}
453453
data "oci_core_vnic_attachments" "t" {
@@ -470,58 +470,6 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
470470
},
471471
),
472472
},
473-
// verify force new by changing ssh_authorized_keys and user_data in metadata
474-
{
475-
Config: s.Config + `
476-
resource "oci_core_instance" "t" {
477-
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
478-
compartment_id = "${var.compartment_id}"
479-
image = "${var.InstanceImageOCID[var.region]}"
480-
shape = "VM.Standard1.8"
481-
display_name = "-tf-instance"
482-
metadata {
483-
ssh_authorized_keys = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"
484-
user_data = "ZWNobyB3b3JsZA=="
485-
}
486-
extended_metadata {
487-
keyA = "valA"
488-
keyB = "{\"keyB1\": \"valB1\", \"keyB2\": {\"keyB2\": \"valB2\"}}"
489-
}
490-
create_vnic_details {
491-
subnet_id = "${oci_core_subnet.t.id}"
492-
display_name = "-tf-vnic-2"
493-
assign_public_ip = false
494-
private_ip = "10.0.1.20"
495-
skip_source_dest_check = true
496-
defined_tags = "${map(
497-
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue"
498-
)}"
499-
freeform_tags = { "Department" = "Finance" }
500-
}
501-
}
502-
data "oci_core_vnic_attachments" "t" {
503-
compartment_id = "${var.compartment_id}"
504-
instance_id = "${oci_core_instance.t.id}"
505-
}
506-
data "oci_core_vnic" "t" {
507-
vnic_id = "${lookup(data.oci_core_vnic_attachments.t.vnic_attachments[0],"vnic_id")}"
508-
}`,
509-
Check: resource.ComposeAggregateTestCheckFunc(
510-
resource.TestCheckResourceAttr(s.ResourceName, "display_name", "-tf-instance"),
511-
resource.TestCheckResourceAttr(s.ResourceName, "private_ip", "10.0.1.20"),
512-
resource.TestCheckResourceAttr(s.ResourceName, "metadata.%", "2"),
513-
resource.TestCheckResourceAttr(s.ResourceName, "metadata.ssh_authorized_keys", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"),
514-
resource.TestCheckResourceAttr(s.ResourceName, "metadata.user_data", "ZWNobyB3b3JsZA=="),
515-
func(ts *terraform.State) (err error) {
516-
newId, err := fromInstanceState(ts, s.ResourceName, "id")
517-
if newId == instanceId {
518-
return fmt.Errorf("expected new instance ocid, got the same")
519-
}
520-
instanceId = newId
521-
return err
522-
},
523-
),
524-
},
525473
},
526474
})
527475
}
@@ -554,7 +502,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
554502
shape = "VM.Standard1.8"
555503
metadata {
556504
ssh_authorized_keys = "${var.ssh_public_key}"
557-
user_data = "ZWNobyBoZWxsbw=="
505+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
558506
}
559507
timeouts {
560508
create = "15m"
@@ -580,7 +528,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
580528
resource.TestCheckResourceAttr(s.ResourceName, "hostname_label", "hostname1"),
581529
resource.TestCheckResourceAttr(s.ResourceName, "shape", "VM.Standard1.8"),
582530
resource.TestCheckResourceAttr(s.ResourceName, "metadata.%", "2"),
583-
resource.TestCheckResourceAttr(s.ResourceName, "metadata.user_data", "ZWNobyBoZWxsbw=="),
531+
resource.TestCheckResourceAttr(s.ResourceName, "metadata.user_data", "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="),
584532
resource.TestCheckResourceAttrSet(s.ResourceName, "metadata.ssh_authorized_keys"),
585533
resource.TestCheckResourceAttrSet(s.ResourceName, "region"),
586534
resource.TestCheckResourceAttr(s.ResourceName, "create_vnic_details.#", "1"),
@@ -615,7 +563,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
615563
shape = "VM.Standard1.8"
616564
metadata {
617565
ssh_authorized_keys = "${var.ssh_public_key}"
618-
user_data = "ZWNobyBoZWxsbw=="
566+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
619567
}
620568
timeouts {
621569
create = "15m"
@@ -640,7 +588,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
640588
shape = "VM.Standard1.8"
641589
metadata {
642590
ssh_authorized_keys = "${var.ssh_public_key}"
643-
user_data = "ZWNobyBoZWxsbw=="
591+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
644592
}
645593
timeouts {
646594
create = "15m"
@@ -690,7 +638,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
690638
shape = "VM.Standard1.8"
691639
metadata {
692640
ssh_authorized_keys = "${var.ssh_public_key}"
693-
user_data = "ZWNobyBoZWxsbw=="
641+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
694642
}
695643
timeouts {
696644
create = "15m"
@@ -747,7 +695,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
747695
shape = "VM.Standard1.8"
748696
metadata {
749697
ssh_authorized_keys = "${var.ssh_public_key}"
750-
user_data = "ZWNobyBoZWxsbw=="
698+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
751699
}
752700
timeouts {
753701
create = "15m"
@@ -794,7 +742,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
794742
shape = "VM.Standard1.8"
795743
metadata {
796744
ssh_authorized_keys = "${var.ssh_public_key}"
797-
user_data = "ZWNobyBoZWxsbw=="
745+
user_data = "SWYgeW91IGNhbiBzZWUgdGhpcywgdGhlbiBpdCB3b3JrZWQgbWF5YmUuCg=="
798746
}
799747
timeouts {
800748
create = "15m"

oci/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
)
88

9-
const Version = "3.11.1"
9+
const Version = "3.11.2"
1010

1111
func PrintVersion() {
1212
log.Printf("[INFO] terraform-provider-oci %s\n", Version)

vendor/github.com/hashicorp/terraform/helper/customdiff/compose.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

vendor/github.com/hashicorp/terraform/helper/customdiff/computed.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)