Skip to content

Commit c91e49b

Browse files
committed
adding instance console connection resource
1 parent 401a360 commit c91e49b

File tree

10 files changed

+1065
-29
lines changed

10 files changed

+1065
-29
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# oci_core_instance_console_connection
2+
3+
## InstanceConsoleConnection Resource
4+
5+
### InstanceConsoleConnection Reference
6+
7+
The following attributes are exported:
8+
9+
* `compartment_id` - The OCID of the compartment to contain the console connection.
10+
* `connection_string` - The SSH connection string for the console connection.
11+
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
12+
* `fingerprint` - The SSH public key fingerprint for the console connection.
13+
* `freeform_tags` - 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.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
14+
* `id` - The OCID of the console connection.
15+
* `instance_id` - The OCID of the instance the console connection connects to.
16+
* `state` - The current state of the console connection.
17+
* `vnc_connection_string` - The SSH connection string for the SSH tunnel used to connect to the console connection over VNC.
18+
19+
20+
21+
### Create Operation
22+
Creates a new console connection to the specified instance.
23+
Once the console connection has been created and is available,
24+
you connect to the console using SSH.
25+
26+
For more information about console access, see [Accessing the Console](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/References/serialconsole.htm).
27+
28+
29+
The following arguments are supported:
30+
31+
* `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.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
32+
* `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.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
33+
* `instance_id` - (Required) The OCID of the instance to create the console connection to.
34+
* `public_key` - (Required) The SSH public key used to authenticate the console connection.
35+
36+
37+
### Update Operation
38+
39+
40+
The following arguments support updates:
41+
* NO arguments in this resource support updates
42+
43+
** IMPORTANT **
44+
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
45+
46+
### Example Usage
47+
48+
```hcl
49+
resource "oci_core_instance_console_connection" "test_instance_console_connection" {
50+
#Required
51+
instance_id = "${oci_core_instance.test_instance.id}"
52+
public_key = "${var.instance_console_connection_public_key}"
53+
54+
#Optional
55+
defined_tags = {"Operations.CostCenter"= "42"}
56+
freeform_tags = {"Department"= "Finance"}
57+
}
58+
```
59+
60+
# oci_core_instance_console_connections
61+
62+
## InstanceConsoleConnection DataSource
63+
64+
Gets a list of instance_console_connections.
65+
66+
### List Operation
67+
Lists the console connections for the specified compartment or instance.
68+
69+
For more information about console access, see [Accessing the Console](https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/References/serialconsole.htm).
70+
71+
The following arguments are supported:
72+
73+
* `compartment_id` - (Required) The OCID of the compartment.
74+
* `instance_id` - (Optional) The OCID of the instance.
75+
76+
77+
The following attributes are exported:
78+
79+
* `instance_console_connections` - The list of instance_console_connections.
80+
81+
### Example Usage
82+
83+
```hcl
84+
data "oci_core_instance_console_connections" "test_instance_console_connections" {
85+
#Required
86+
compartment_id = "${var.compartment_id}"
87+
88+
#Optional
89+
instance_id = "${oci_core_instance.test_instance.id}"
90+
}
91+
```
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
variable "tenancy_ocid" {}
2+
variable "user_ocid" {}
3+
variable "fingerprint" {}
4+
variable "private_key_path" {}
5+
variable "region" {}
6+
7+
variable "compartment_ocid" {}
8+
variable "ssh_public_key" {}
9+
variable "ssh_private_key" {}
10+
11+
# Choose an Availability Domain
12+
variable "AD" {
13+
default = "1"
14+
}
15+
16+
variable "InstanceImageOCID" {
17+
type = "map"
18+
default = {
19+
// See https://docs.us-phoenix-1.oraclecloud.com/images/
20+
// Oracle-provided image "Oracle-Linux-7.4-2018.02.21-1"
21+
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaupbfz5f5hdvejulmalhyb6goieolullgkpumorbvxlwkaowglslq"
22+
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaajlw3xfie2t5t52uegyhiq2npx7bqyu4uvi2zyu3w3mqayc2bxmaa"
23+
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaa7d3fsb6272srnftyi4dphdgfjf6gurxqhmv6ileds7ba3m2gltxq"
24+
uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaaa6h6gj6v4n56mqrbgnosskq63blyv2752g36zerymy63cfkojiiq"
25+
}
26+
}
27+
28+
variable "InstanceShape" {
29+
default = "VM.Standard1.2"
30+
}
31+
32+
provider "oci" {
33+
tenancy_ocid = "${var.tenancy_ocid}"
34+
user_ocid = "${var.user_ocid}"
35+
fingerprint = "${var.fingerprint}"
36+
private_key_path = "${var.private_key_path}"
37+
region = "${var.region}"
38+
}
39+
40+
# Gets a list of Availability Domains
41+
data "oci_identity_availability_domains" "ADs" {
42+
compartment_id = "${var.tenancy_ocid}"
43+
}
44+
45+
resource "oci_core_virtual_network" "ExampleVCN" {
46+
cidr_block = "10.1.0.0/16"
47+
compartment_id = "${var.compartment_ocid}"
48+
display_name = "TFExampleVCN"
49+
dns_label = "tfexamplevcn"
50+
}
51+
52+
resource "oci_core_subnet" "ExampleSubnet" {
53+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
54+
cidr_block = "10.1.20.0/24"
55+
display_name = "TFExampleSubnet"
56+
dns_label = "tfexamplesubnet"
57+
security_list_ids = ["${oci_core_virtual_network.ExampleVCN.default_security_list_id}"]
58+
compartment_id = "${var.compartment_ocid}"
59+
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
60+
route_table_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
61+
dhcp_options_id = "${oci_core_virtual_network.ExampleVCN.default_dhcp_options_id}"
62+
}
63+
64+
resource "oci_core_internet_gateway" "ExampleIG" {
65+
compartment_id = "${var.compartment_ocid}"
66+
display_name = "TFExampleIG"
67+
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
68+
}
69+
70+
resource "oci_core_default_route_table" "ExampleRT" {
71+
manage_default_resource_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
72+
route_rules {
73+
cidr_block = "0.0.0.0/0"
74+
network_entity_id = "${oci_core_internet_gateway.ExampleIG.id}"
75+
}
76+
}
77+
78+
# Gets a list of vNIC attachments on the instance
79+
data "oci_core_vnic_attachments" "InstanceVnics" {
80+
compartment_id = "${var.compartment_ocid}"
81+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
82+
instance_id = "${oci_core_instance.TFInstance.id}"
83+
}
84+
85+
# Gets the OCID of the first (default) vNIC
86+
data "oci_core_vnic" "InstanceVnic" {
87+
vnic_id = "${lookup(data.oci_core_vnic_attachments.InstanceVnics.vnic_attachments[0],"vnic_id")}"
88+
}
89+
90+
resource "oci_core_instance" "TFInstance" {
91+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
92+
compartment_id = "${var.compartment_ocid}"
93+
display_name = "TFInstance"
94+
shape = "${var.InstanceShape}"
95+
96+
create_vnic_details {
97+
subnet_id = "${oci_core_subnet.ExampleSubnet.id}"
98+
display_name = "primaryvnic"
99+
assign_public_ip = true
100+
hostname_label = "tfexampleinstance"
101+
}
102+
103+
source_details {
104+
source_type = "image"
105+
source_id = "${var.InstanceImageOCID[var.region]}"
106+
}
107+
108+
metadata {
109+
ssh_authorized_keys = "${var.ssh_public_key}"
110+
}
111+
112+
timeouts {
113+
create = "60m"
114+
}
115+
}
116+
117+
resource "oci_core_instance_console_connection" "test_instance_console_connection" {
118+
#Required
119+
instance_id = "${oci_core_instance.TFInstance.id}"
120+
public_key = "${var.ssh_public_key}"
121+
122+
}
123+
124+
output "connect_with_ssh" {
125+
value = "${oci_core_instance_console_connection.test_instance_console_connection.connection_string}"
126+
}
127+
128+
output "connect_with_vnc" {
129+
value = "${oci_core_instance_console_connection.test_instance_console_connection.vnc_connection_string}"
130+
}
131+
132+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### Authentication details
2+
export TF_VAR_tenancy_ocid="<tenancy OCID>"
3+
export TF_VAR_user_ocid="<user OCID>"
4+
export TF_VAR_fingerprint="<PEM key fingerprint>"
5+
export TF_VAR_private_key_path="<path to the private key that matches the fingerprint above>"
6+
7+
### Region
8+
export TF_VAR_region="<region in which to operate, example: us-ashburn-1, us-phoenix-1>"
9+
10+
### Compartment
11+
export TF_VAR_compartment_ocid="<compartment OCID>"
12+
13+
### Public/private keys used on the instance
14+
export TF_VAR_ssh_public_key=$(cat <path to public key>)
15+
export TF_VAR_ssh_private_key=$(cat <path to private key>)
16+
## NOTE: These are not your api keys. More info on the right keys see
17+
## https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingkeypairs.htm

docs/examples/compute/instance/compute.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ resource "oci_core_instance" "TFInstance" {
3535

3636
defined_tags = "${
3737
map(
38-
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag2.name}", "awesome-app-server",
38+
"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag2.name}", "awesome-app-server"
3939
)
4040
}"
4141

provider/core_boot_volume_test.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,9 @@ const (
1515
1616
`
1717
BootVolumePropertyVariables = `
18-
variable "InstanceImageOCID" {
19-
type = "map"
20-
default = {
21-
// See https://docs.us-phoenix-1.oraclecloud.com/images/
22-
// Oracle-provided image "Oracle-Linux-7.4-2018.02.21-1"
23-
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaupbfz5f5hdvejulmalhyb6goieolullgkpumorbvxlwkaowglslq"
24-
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaajlw3xfie2t5t52uegyhiq2npx7bqyu4uvi2zyu3w3mqayc2bxmaa"
25-
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaa7d3fsb6272srnftyi4dphdgfjf6gurxqhmv6ileds7ba3m2gltxq"
26-
uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaaa6h6gj6v4n56mqrbgnosskq63blyv2752g36zerymy63cfkojiiq"
27-
}
28-
}
2918
`
30-
InstanceResourceConfigs = `
31-
resource "oci_core_instance" "test_instance" {
32-
availability_domain = "${oci_core_subnet.test_subnet.availability_domain}"
33-
compartment_id = "${var.compartment_id}"
34-
display_name = "-tf-instance"
35-
image = "${var.InstanceImageOCID[var.region]}"
36-
shape = "VM.Standard1.1"
37-
subnet_id = "${oci_core_subnet.test_subnet.id}"
38-
metadata {
39-
ssh_authorized_keys = "${var.ssh_public_key}"
40-
}
4119

42-
timeouts {
43-
create = "15m"
44-
}
45-
}`
46-
47-
BootVolumeResourceDependencies = BootVolumePropertyVariables + SubnetPropertyVariables + SubnetRequiredOnlyResource + InstanceResourceConfigs
20+
BootVolumeResourceDependencies = BootVolumePropertyVariables + InstancePropertyVariables + InstanceResourceAsDependencyConfig
4821
)
4922

5023
func TestCoreBootVolumeResource_basic(t *testing.T) {

0 commit comments

Comments
 (0)