Skip to content

Commit bbd9048

Browse files
Yi Fanrashik-bhasin
authored andcommitted
Add Update API for Instance Console Connections
1 parent f312a8e commit bbd9048

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 3.95.0 (Unreleased)
22
- Support for query parameters added to `object_storage` `object` resource
33
- Support for custom certificates added to `apigateway` `certificate` resource
4+
- Support added for update Instance Console Connections
45

56
## 3.94.0 (September 23, 2020)
67

oci/core_instance_console_connection_resource.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func CoreInstanceConsoleConnectionResource() *schema.Resource {
2323
Timeouts: DefaultTimeout,
2424
Create: createCoreInstanceConsoleConnection,
2525
Read: readCoreInstanceConsoleConnection,
26+
Update: updateCoreInstanceConsoleConnection,
2627
Delete: deleteCoreInstanceConsoleConnection,
2728
Schema: map[string]*schema.Schema{
2829
// Required
@@ -42,15 +43,13 @@ func CoreInstanceConsoleConnectionResource() *schema.Resource {
4243
Type: schema.TypeMap,
4344
Optional: true,
4445
Computed: true,
45-
ForceNew: true,
4646
DiffSuppressFunc: definedTagsDiffSuppressFunction,
4747
Elem: schema.TypeString,
4848
},
4949
"freeform_tags": {
5050
Type: schema.TypeMap,
5151
Optional: true,
5252
Computed: true,
53-
ForceNew: true,
5453
Elem: schema.TypeString,
5554
},
5655

@@ -95,6 +94,14 @@ func readCoreInstanceConsoleConnection(d *schema.ResourceData, m interface{}) er
9594
return ReadResource(sync)
9695
}
9796

97+
func updateCoreInstanceConsoleConnection(d *schema.ResourceData, m interface{}) error {
98+
sync := &CoreInstanceConsoleConnectionResourceCrud{}
99+
sync.D = d
100+
sync.Client = m.(*OracleClients).computeClient()
101+
102+
return UpdateResource(d, sync)
103+
}
104+
98105
func deleteCoreInstanceConsoleConnection(d *schema.ResourceData, m interface{}) error {
99106
sync := &CoreInstanceConsoleConnectionResourceCrud{}
100107
sync.D = d
@@ -192,6 +199,35 @@ func (s *CoreInstanceConsoleConnectionResourceCrud) Get() error {
192199
return nil
193200
}
194201

202+
func (s *CoreInstanceConsoleConnectionResourceCrud) Update() error {
203+
request := oci_core.UpdateInstanceConsoleConnectionRequest{}
204+
205+
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
206+
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
207+
if err != nil {
208+
return err
209+
}
210+
request.DefinedTags = convertedDefinedTags
211+
}
212+
213+
if freeformTags, ok := s.D.GetOkExists("freeform_tags"); ok {
214+
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
215+
}
216+
217+
tmp := s.D.Id()
218+
request.InstanceConsoleConnectionId = &tmp
219+
220+
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "core")
221+
222+
response, err := s.Client.UpdateInstanceConsoleConnection(context.Background(), request)
223+
if err != nil {
224+
return err
225+
}
226+
227+
s.Res = &response.InstanceConsoleConnection
228+
return nil
229+
}
230+
195231
func (s *CoreInstanceConsoleConnectionResourceCrud) Delete() error {
196232
request := oci_core.DeleteInstanceConsoleConnectionRequest{}
197233

oci/core_instance_console_connection_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestCoreInstanceConsoleConnectionResource_basic(t *testing.T) {
6060
resourceName := "oci_core_instance_console_connection.test_instance_console_connection"
6161
datasourceName := "data.oci_core_instance_console_connections.test_instance_console_connections"
6262

63-
var resId string
63+
var resId, resId2 string
6464

6565
resource.Test(t, resource.TestCase{
6666
PreCheck: func() { testAccPreCheck(t) },
@@ -76,6 +76,11 @@ func TestCoreInstanceConsoleConnectionResource_basic(t *testing.T) {
7676
Check: resource.ComposeAggregateTestCheckFunc(
7777
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
7878
resource.TestCheckResourceAttr(resourceName, "public_key", "ssh-rsa KKKLK3NzaC1yc2EAAAADAQABAAABAQC+UC9MFNA55NIVtKPIBCNw7++ACXhD0hx+Zyj25JfHykjz/QU3Q5FAU3DxDbVXyubgXfb/GJnrKRY8O4QDdvnZZRvQFFEOaApThAmCAM5MuFUIHdFvlqP+0W+ZQnmtDhwVe2NCfcmOrMuaPEgOKO3DOW6I/qOOdO691Xe2S9NgT9HhN0ZfFtEODVgvYulgXuCCXsJs+NUqcHAOxxFUmwkbPvYi0P0e2DT8JKeiOOC8VKUEgvVx+GKmqasm+Y6zHFW7vv3g2GstE1aRs3mttHRoC/JPM86PRyIxeWXEMzyG5wHqUu4XZpDbnWNxi6ugxnAGiL3CrIFdCgRNgHz5qS1l MustWin"),
79+
80+
func(s *terraform.State) (err error) {
81+
resId, err = fromInstanceState(s, resourceName, "id")
82+
return err
83+
},
7984
),
8085
},
8186

@@ -104,6 +109,25 @@ func TestCoreInstanceConsoleConnectionResource_basic(t *testing.T) {
104109
),
105110
},
106111

112+
// verify updates to updatable parameters
113+
{
114+
Config: config + compartmentIdVariableStr + InstanceConsoleConnectionResourceDependencies +
115+
generateResourceFromRepresentationMap("oci_core_instance_console_connection", "test_instance_console_connection", Optional, Update, instanceConsoleConnectionRepresentation),
116+
Check: resource.ComposeAggregateTestCheckFunc(
117+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
118+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
119+
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
120+
resource.TestCheckResourceAttr(resourceName, "public_key", "ssh-rsa KKKLK3NzaC1yc2EAAAADAQABAAABAQC+UC9MFNA55NIVtKPIBCNw7++ACXhD0hx+Zyj25JfHykjz/QU3Q5FAU3DxDbVXyubgXfb/GJnrKRY8O4QDdvnZZRvQFFEOaApThAmCAM5MuFUIHdFvlqP+0W+ZQnmtDhwVe2NCfcmOrMuaPEgOKO3DOW6I/qOOdO691Xe2S9NgT9HhN0ZfFtEODVgvYulgXuCCXsJs+NUqcHAOxxFUmwkbPvYi0P0e2DT8JKeiOOC8VKUEgvVx+GKmqasm+Y6zHFW7vv3g2GstE1aRs3mttHRoC/JPM86PRyIxeWXEMzyG5wHqUu4XZpDbnWNxi6ugxnAGiL3CrIFdCgRNgHz5qS1l MustWin"),
121+
122+
func(s *terraform.State) (err error) {
123+
resId2, err = fromInstanceState(s, resourceName, "id")
124+
if resId != resId2 {
125+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
126+
}
127+
return err
128+
},
129+
),
130+
},
107131
// verify datasource
108132
{
109133
Config: config +

website/docs/r/core_instance_console_connection.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ resource "oci_core_instance_console_connection" "test_instance_console_connectio
3535

3636
The following arguments are supported:
3737

38-
* `defined_tags` - (Optional) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
39-
* `freeform_tags` - (Optional) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
38+
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
39+
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
4040
* `instance_id` - (Required) The OCID of the instance to create the console connection to.
4141
* `public_key` - (Required) The SSH public key used to authenticate the console connection.
4242

0 commit comments

Comments
 (0)