Skip to content

Commit 6c6aec8

Browse files
committed
feat: add support for Always Free
Signed-off-by: Andrea Marchesini <[email protected]>
1 parent 32aaaa2 commit 6c6aec8

File tree

7 files changed

+196
-112
lines changed

7 files changed

+196
-112
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ This project enables you to create and configure network and compute resources o
2929

3030
Under *Stack Information* (the first screen), check the box *I have reviewed and accept the Oracle Terms of Use*. Once that box is checked, the information for the stack will be populated automatically.
3131

32-
3. Click **Next** at the bottom of the screen. This will take you to the **Configure Variables** page. On this page you can optionally provide/change these variables:
33-
- **Compartment** (_optional_): select the compartment where do you want to deploy the stack
32+
3. Click **Next** at the bottom of the screen. This will take you to the **Configure Variables** page. On this page you can provide/change these variables:
33+
- **Compartment**: select the compartment where do you want to deploy the stack
3434
- **SSH public key** (_optional_): the key will allow you to login into the instance.
35-
- **Instance Name** (_optional_): Name of the instance [_default: oci-code-server_]
36-
- **Shape** (_optional_): Instance shape [_default: VM.Standard.E4.Flex_]. If you want your Compute instance to function after your Free Trial ends, check the box for an Always Free Shape.
37-
- **OCPUs number** (_optional_): Only if you have selected a Flex shape [_default: 1_]
38-
35+
- **Use Always Free eligible shape**:
36+
If checked, the Always Free shape (_VM.Standard.E2.1.Micro_) is used. Make sure you are in a region where this Always Free shape is available
37+
If not checked:
38+
- **Instance Shape**: (_optional_): select the shape that will be used for the VM [default: _VM.Standard.E4.Flex_]
39+
- **Availability Domain**: select the Availability Domain (AD) you want the instance to be deployed to. If you have checked Always Free, make sure to select the Always Free elegible AD.
40+
- ***Show Advanced***
41+
- **Instance Name** (_optional_): Name of the instance [_default: oci-code-server_]
42+
- **Flex Instance OCPUs number** (_optional_): Only if you have selected a Flex shape, you can select the number of OCPUs to assign to the flexible shape. [_default: 1_]
43+
44+
45+
3946
Then click **Next** again.
4047

4148
4. On the **Review** page, be sure *Run Apply* is checked, and click **Create**.
@@ -50,6 +57,11 @@ For more information about `code-server`:
5057
* [code-server](https://github.com/coder/code-server)
5158
* [deploy-code-server](https://github.com/coder/deploy-code-server)
5259

60+
## Know Issues
61+
The code-server instance is launched with the `--link ` [flag](https://coder.com/docs/code-server/latest/link) to provide authentication through GitHub, TLS and a dedicated URL for accessing your VS Code. This feature presents some issues when you try to connect from a different geographic region than the one the instance is running and you encounter an error after the GitHub authentication. Current workaround is to use one of the other options provided by code-server guide to [expose it](https://github.com/coder/code-server/blob/main/docs/guide.md#expose-code-server):
62+
- using [SSH port forwarding](https://github.com/coder/code-server/blob/main/docs/guide.md#port-forwarding-via-ssh)
63+
- using [Let's Encrypt](https://letsencrypt.org/) with [Caddy](https://github.com/coder/code-server/blob/main/docs/guide.md#using-lets-encrypt-with-caddy) or [NGINX](https://github.com/coder/code-server/blob/main/docs/guide.md#using-lets-encrypt-with-nginx)
64+
5365
## Contributing
5466
This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open source community.
5567

datasources.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# get latest Ubuntu Linux 16.04 image
55
data "oci_core_images" "ubuntu-20-04" {
6-
compartment_id = var.compartment_ocid
6+
compartment_id = local.compartment_id
77
operating_system = "Canonical Ubuntu"
88
filter {
99
name = "display_name"
@@ -12,3 +12,13 @@ data "oci_core_images" "ubuntu-20-04" {
1212
}
1313
}
1414

15+
data "oci_identity_availability_domains" "ad" {
16+
compartment_id = local.compartment_id
17+
}
18+
19+
locals{
20+
ad_map = {for ad_number,ad in data.oci_identity_availability_domains.ad.availability_domains : "${ad.name}" => (ad_number+1) }
21+
}
22+
23+
24+

main.tf

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
11
# Copyright (c) 2019, 2021, Oracle Corporation and/or affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

4+
locals {
5+
compartment_id = var.compartment_ocid == "" ? var.tenancy_ocid : var.compartment_ocid
6+
ad_number = var.instance_ad_name == "" ? var.instance_ad_number : local.ad_map[var.instance_ad_name]
7+
}
48

59
module "vsc_instance" {
6-
# source = "oracle-terraform-modules/compute-instance/oci"
7-
source = "github.com/oracle-terraform-modules/terraform-oci-compute-instance"
10+
source = "oracle-terraform-modules/compute-instance/oci"
811
# general oci parameters
9-
compartment_ocid = var.compartment_ocid
10-
freeform_tags = var.freeform_tags
11-
defined_tags = var.defined_tags
12+
compartment_ocid = local.compartment_id
13+
freeform_tags = var.freeform_tags
14+
defined_tags = var.defined_tags
1215
# compute instance parameters
13-
ad_number = var.instance_ad_number
16+
ad_number = local.ad_number
1417
instance_count = 1
1518
instance_display_name = var.instance_display_name
1619
instance_state = "RUNNING"
17-
shape = var.shape
20+
shape = var.use_always_free ? local.always_free_shape : var.shape
1821
source_ocid = data.oci_core_images.ubuntu-20-04.images.0.id
1922
source_type = "image"
20-
instance_flex_memory_in_gbs = var.instance_flex_memory_in_gbs
21-
instance_flex_ocpus = var.instance_flex_ocpus
23+
instance_flex_memory_in_gbs = var.use_always_free ? null : var.instance_flex_memory_in_gbs
24+
instance_flex_ocpus = var.use_always_free ? 1 : var.instance_flex_ocpus
2225
# operating system parameters
23-
ssh_public_keys = var.ssh_public_keys != "" ? var.ssh_public_keys : var.ssh_public_key_path != "" ? file(var.ssh_public_key_path) :""
24-
user_data = base64encode(data.template_file.cloud-config.rendered)
26+
ssh_public_keys = var.ssh_public_keys != "" ? var.ssh_public_keys : var.ssh_public_key_path != "" ? file(var.ssh_public_key_path) : ""
27+
user_data = base64encode(data.template_file.cloud-config.rendered)
2528
# networking parameters
26-
public_ip = var.public_ip
27-
subnet_ocids = [oci_core_subnet.sub.id]
28-
primary_vnic_nsg_ids = [oci_core_network_security_group.nsg.id]
29+
public_ip = var.public_ip
30+
subnet_ocids = [oci_core_subnet.sub.id]
31+
primary_vnic_nsg_ids = [oci_core_network_security_group.nsg.id]
2932

3033
# storage parameters
31-
boot_volume_backup_policy = "disabled"
32-
block_storage_sizes_in_gbs = [50]
33-
}
34-
35-
data "template_file" "cloud-config" {
36-
template = <<YAML
37-
#cloud-config
38-
runcmd:
39-
- iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
40-
- netfilter-persistent save
41-
- while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do sleep 50; done;
42-
- wget https://raw.githubusercontent.com/coder/deploy-code-server/main/deploy-vm/launch-code-server.sh -O - | sh
43-
YAML
34+
boot_volume_backup_policy = "disabled"
35+
block_storage_sizes_in_gbs = [50]
4436
}
4537

4638

4739
module "vcn" {
4840
source = "oracle-terraform-modules/vcn/oci"
4941

5042
# general oci parameters
51-
compartment_id = var.compartment_ocid
52-
vcn_name = "vsc-network"
43+
compartment_id = local.compartment_id
44+
vcn_name = "vsc-network"
5345

5446
# vcn parameters
55-
lockdown_default_seclist = false
56-
vcn_cidrs = [var.vcn_cidr]
57-
create_internet_gateway=true
47+
lockdown_default_seclist = false
48+
vcn_cidrs = [var.vcn_cidr]
49+
create_internet_gateway = true
5850

5951
}
6052

6153
resource "oci_core_network_security_group" "nsg" {
6254
#Required
63-
compartment_id = var.compartment_ocid
55+
compartment_id = local.compartment_id
6456
vcn_id = module.vcn.vcn_id
6557

6658
#Optional
@@ -70,45 +62,45 @@ resource "oci_core_network_security_group" "nsg" {
7062

7163
resource "oci_core_subnet" "sub" {
7264
#Required
73-
cidr_block = cidrsubnet(var.vcn_cidr, lookup(var.subnets["vsc"], "newbits"), lookup(var.subnets["vsc"], "netnum"))
74-
compartment_id = var.compartment_ocid
75-
vcn_id = module.vcn.vcn_id
65+
cidr_block = cidrsubnet(var.vcn_cidr, lookup(var.subnets["vsc"], "newbits"), lookup(var.subnets["vsc"], "netnum"))
66+
compartment_id = local.compartment_id
67+
vcn_id = module.vcn.vcn_id
7668

7769
#Optional
7870
display_name = "vsc-sub"
7971
dns_label = "vscsub"
8072
prohibit_public_ip_on_vnic = false
81-
route_table_id = module.vcn.ig_route_id
82-
freeform_tags = var.freeform_tags
73+
route_table_id = module.vcn.ig_route_id
74+
freeform_tags = var.freeform_tags
8375
}
8476

8577

8678
module "oci_security_policies" {
87-
source = "github.com/oracle-terraform-modules/terraform-oci-tdf-network-security"
88-
89-
default_compartment_id = var.compartment_ocid
90-
default_freeform_tags = var.freeform_tags
91-
vcn_id = module.vcn.vcn_id
92-
93-
standalone_nsg_rules = {
94-
ingress_rules = [
79+
source = "github.com/oracle-terraform-modules/terraform-oci-tdf-network-security"
80+
81+
default_compartment_id = local.compartment_id
82+
default_freeform_tags = var.freeform_tags
83+
vcn_id = module.vcn.vcn_id
84+
85+
standalone_nsg_rules = {
86+
ingress_rules = [
9587
{
96-
nsg_id = oci_core_network_security_group.nsg.id
97-
description = "code-server"
98-
stateless = false
99-
protocol = "6"
100-
src = "0.0.0.0/0"
101-
src_type = "CIDR_BLOCK"
102-
src_port = null
103-
dst_port = {
104-
min = "80"
105-
max = "80"
88+
nsg_id = oci_core_network_security_group.nsg.id
89+
description = "code-server"
90+
stateless = false
91+
protocol = "6"
92+
src = "0.0.0.0/0"
93+
src_type = "CIDR_BLOCK"
94+
src_port = null
95+
dst_port = {
96+
min = "80"
97+
max = "80"
10698
}
107-
icmp_code = null
108-
icmp_type = null
99+
icmp_code = null
100+
icmp_type = null
109101
}
110102
]
111-
egress_rules = []
103+
egress_rules = []
112104
}
113105
}
114106

orm/schema.yaml

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,107 @@
11
# Title shown in Application Information tab.
22
title: Launch code-server instance
3+
informationalText: "Run VS Code on OCI compute instance and access it in the browser."
34
# Sub Title shown in Application Information tab.
4-
description: Launch a code-server instance on OCI
5+
description: code-server instance
56
schemaVersion: 1.1.0
67
version: 1.0
78
locale: en
89
variableGroups:
910
- title: "Hidden"
1011
variables:
11-
- ${tenancy_ocid}
12-
- ${user_ocid}
13-
- ${region}
14-
- ${api_fingerprint}
15-
- ${api_private_key_path}
16-
- ${region}
17-
- ${compartment_ocid}
18-
- ${ssh_public_key_path}
19-
- ${freeform_tags}
20-
- ${defined_tags}
21-
- ${instance_flex_memory_in_gbs}
22-
- ${instance_ad_number}
23-
- ${public_ip}
24-
- ${vcn_cidr}
25-
- ${subnets}
12+
- tenancy_ocid
13+
- user_ocid
14+
- region
15+
- api_fingerprint
16+
- api_private_key_path
17+
- ssh_public_key_path
18+
- freeform_tags
19+
- defined_tags
20+
- instance_flex_memory_in_gbs
21+
- public_ip
22+
- vcn_cidr
23+
- subnets
24+
- instance_ad_number
2625
visible: false
26+
2727
- title: "Configuration"
2828
variables:
29-
- ${compartment_ocid}
30-
- ${ssh_public_keys}
31-
- ${instance_display_name}
32-
- ${shape}
33-
- ${instance_flex_ocpus}
29+
- compartment_ocid
30+
- ssh_public_keys
31+
- use_always_free
32+
- shape
33+
- instance_ad_name
34+
- show_advanced
35+
36+
- title: "Advanced"
37+
visible:
38+
and:
39+
- show_advanced
40+
variables:
41+
- instance_display_name
42+
- instance_flex_ocpus
43+
3444

3545
variables:
3646
compartment_ocid:
3747
title: Compartment
3848
description: Compartment where to deploy the stack
3949
type: oci:identity:compartment:id
40-
required: false
50+
required: true
51+
visible: true
4152
ssh_public_keys:
4253
title: Compute SSH Public Key
4354
type: oci:core:ssh:publickey
4455
description: The public key to install on the instance for SSH access.
4556
required: false
46-
instance_display_name:
47-
title: Instance Name
48-
type: string
49-
description: The name to use for the compute instance
50-
default: oci-code-server
51-
required: false
57+
visible: true
58+
use_always_free:
59+
type: boolean
60+
title: "Use Always Free elegible shape"
61+
required: true
62+
default: true
63+
visible: true
5264
shape:
5365
title: Instance Shape
54-
type: string
66+
type: oci:core:instanceshape:name
5567
description: The shape name to use for the compute instance
56-
default: VM.Standard.E4.Flex
68+
#default: VM.Standard.E4.Flex
5769
required: false
70+
visible:
71+
not:
72+
- use_always_free
73+
dependsOn:
74+
compartmentId: compartment_ocid
75+
instance_ad_name:
76+
title: Availability Domain
77+
type: oci:identity:availabilitydomain:name
78+
description: If you have checked Always Free, make sure to select the Always Free elegible Availability Domain.
79+
#default: 1
80+
required: true
81+
dependsOn:
82+
compartmentId: compartment_ocid
83+
show_advanced:
84+
type: boolean
85+
title: "Show advanced options?"
86+
description: "Shows advanced options."
87+
visible: true
88+
default: false
5889
instance_flex_ocpus:
5990
title: Flex Instance OCPU number
6091
type: string
61-
description: The number of OCPUs. It applies to Flex Instance only
92+
description: The number of OCPUs. It applies to Flex Instances only
6293
default: 1
6394
required: false
95+
visible:
96+
not:
97+
- use_always_free
98+
instance_display_name:
99+
title: Instance Name
100+
type: string
101+
description: The name to use for the compute instance
102+
default: oci-code-server
103+
required: false
104+
64105

65106
outputs:
66107
code-server-publicIP:

outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ output "vsc_instance" {
1313
"OS version" = data.oci_core_images.ubuntu-20-04.images.0.display_name,
1414
}
1515
}
16-

user-data.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2019, 2021, Oracle Corporation and/or affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
data "template_file" "cloud-config" {
5+
template = <<YAML
6+
#cloud-config
7+
runcmd:
8+
- iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
9+
- netfilter-persistent save
10+
- while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do sleep 50; done;
11+
- wget https://raw.githubusercontent.com/coder/deploy-code-server/main/deploy-vm/launch-code-server.sh -O - | sh
12+
YAML
13+
}

0 commit comments

Comments
 (0)