Skip to content

Commit 6a3fd70

Browse files
Sync instance subnet and hostname_label (#316)
An instances have 2 ways to set subnet_id and hostname_label: either at the root level, or in create_vnic_details. By syncing both sets of properties with the VNIC and setting all of these to computed, this change allows users to switch between which version is used without causing changes to their plan. This was partly in place before, but this change puts a few missing pieces in place.
1 parent c71b2c2 commit 6a3fd70

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

resource_obmcs_core_instance.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func InstanceResource() *schema.Resource {
5858
Type: schema.TypeString,
5959
Optional: true,
6060
Computed: true,
61+
ForceNew: true,
6162
},
6263
"id": {
6364
Type: schema.TypeString,
@@ -71,6 +72,7 @@ func InstanceResource() *schema.Resource {
7172
"ipxe_script": {
7273
Type: schema.TypeString,
7374
Optional: true,
75+
ForceNew: true,
7476
},
7577
"metadata": {
7678
Type: schema.TypeMap,
@@ -100,6 +102,7 @@ func InstanceResource() *schema.Resource {
100102
"subnet_id": {
101103
Type: schema.TypeString,
102104
Optional: true,
105+
Computed: true,
103106
ForceNew: true,
104107
},
105108
"time_created": {
@@ -108,12 +111,10 @@ func InstanceResource() *schema.Resource {
108111
},
109112
"public_ip": {
110113
Type: schema.TypeString,
111-
Required: false,
112114
Computed: true,
113115
},
114116
"private_ip": {
115117
Type: schema.TypeString,
116-
Required: false,
117118
Computed: true,
118119
},
119120
},
@@ -352,8 +353,10 @@ func (s *InstanceResourceCrud) SetData() {
352353
return
353354
}
354355

356+
s.D.Set("hostname_label", vnic.HostnameLabel)
355357
s.D.Set("public_ip", vnic.PublicIPAddress)
356358
s.D.Set("private_ip", vnic.PrivateIPAddress)
359+
s.D.Set("subnet_id", vnic.SubnetID)
357360

358361
RefreshCreateVnicDetails(s.D, vnic)
359362
}

resource_obmcs_core_instance_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
8383
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
8484
compartment_id = "${var.compartment_id}"
8585
subnet_id = "${oci_core_subnet.t.id}"
86+
hostname_label = "hostname1"
8687
image = "${data.oci_core_images.t.images.0.id}"
8788
shape = "VM.Standard1.1"
8889
metadata {
@@ -105,7 +106,31 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
105106
},
106107
),
107108
},
108-
// verify update
109+
// Switching to create_vnic_details for subnet_id and hostname_label should not lead to a change.
110+
{
111+
ImportState: true,
112+
ImportStateVerify: true,
113+
Config: s.Config + `
114+
resource "oci_core_instance" "t" {
115+
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
116+
compartment_id = "${var.compartment_id}"
117+
create_vnic_details {
118+
subnet_id = "${oci_core_subnet.t.id}"
119+
hostname_label = "hostname1"
120+
}
121+
image = "${data.oci_core_images.t.images.0.id}"
122+
shape = "VM.Standard1.1"
123+
metadata {
124+
ssh_authorized_keys = "${var.ssh_public_key}"
125+
}
126+
timeouts {
127+
create = "15m"
128+
}
129+
}`,
130+
ExpectNonEmptyPlan: false,
131+
PlanOnly: true,
132+
},
133+
// verify update - adds display name
109134
{
110135
ImportState: true,
111136
ImportStateVerify: true,
@@ -114,6 +139,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
114139
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
115140
compartment_id = "${var.compartment_id}"
116141
subnet_id = "${oci_core_subnet.t.id}"
142+
hostname_label = "hostname1"
117143
image = "${data.oci_core_images.t.images.0.id}"
118144
shape = "VM.Standard1.1"
119145
display_name = "-tf-instance"
@@ -132,7 +158,7 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_basic() {
132158
},
133159
),
134160
},
135-
// Adding create_vnic_details with the same subnet_id and an updateable fields should cause an update only.
161+
// Adding create_vnic_details with the same subnet_id and an updatable fields should cause an update only.
136162
{
137163
ImportState: true,
138164
ImportStateVerify: true,

0 commit comments

Comments
 (0)