Skip to content

Commit d144489

Browse files
Make examples testable (#398)
Adds test cases TestExamplesPlan and TestExamplesApply, which will plan and apply every example under /docs/examples. (There's an exception for db_systems, which needs some work to make runnable using the stardard set of variables.) The tests ensure that all examples are runnable using the same set of variables. In the future we might consider updating this to enable concurrent runs.
1 parent 363c5df commit d144489

File tree

30 files changed

+347
-313
lines changed

30 files changed

+347
-313
lines changed

docs/examples/clusters/Mongodb/env-vars

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ export TF_VAR_compartment_ocid="<compartment OCID>"
1414
export TF_VAR_ssh_public_key=$(cat <path to public key>)
1515
export TF_VAR_ssh_private_key=$(cat <path to private key>)
1616

17-
## Specific to this example
18-
### Choose a subnet that exists in the AD and compartment you are launching the instance in
19-
export TF_VAR_SubnetOCID="<subnet>"
2017

docs/examples/compute/extended_metadata/env-vars

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ export TF_VAR_user_ocid="<user OCID>"
44
export TF_VAR_fingerprint="<PEM key fingerprint>"
55
export TF_VAR_private_key_path="<path to the private key that matches the fingerprint above>"
66

7-
87
### Public/private keys used on the instance
98
export TF_VAR_ssh_public_key=$(cat ~/.ssh/key.pub)
109
export TF_VAR_ssh_private_key=$(cat ~/.ssh/key)
11-
12-
## Specific to this example
13-
### Choose a subnet that exists in the AD and compartment you are launching the instance in
14-
export TF_VAR_SubnetOCID="<subnet OCID>"

docs/examples/compute/extended_metadata/extended_metadata.tf

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ variable "compartment_ocid" {}
88
variable "ssh_public_key" {}
99
variable "ssh_private_key" {}
1010

11-
variable "SubnetOCID" {}
12-
1311
# Choose an Availability Domain
1412
variable "AD" {
1513
default = "1"
@@ -28,6 +26,39 @@ data "oci_identity_availability_domains" "ADs" {
2826
compartment_id = "${var.tenancy_ocid}"
2927
}
3028

29+
resource "oci_core_virtual_network" "ExampleVCN" {
30+
cidr_block = "10.1.0.0/16"
31+
compartment_id = "${var.compartment_ocid}"
32+
display_name = "TFExampleVCN"
33+
dns_label = "tfexamplevcn"
34+
}
35+
36+
resource "oci_core_subnet" "ExampleSubnet" {
37+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
38+
cidr_block = "10.1.20.0/24"
39+
display_name = "TFExampleSubnet"
40+
dns_label = "tfexamplesubnet"
41+
security_list_ids = ["${oci_core_virtual_network.ExampleVCN.default_security_list_id}"]
42+
compartment_id = "${var.compartment_ocid}"
43+
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
44+
route_table_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
45+
dhcp_options_id = "${oci_core_virtual_network.ExampleVCN.default_dhcp_options_id}"
46+
}
47+
48+
resource "oci_core_internet_gateway" "ExampleIG" {
49+
compartment_id = "${var.compartment_ocid}"
50+
display_name = "TFExampleIG"
51+
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
52+
}
53+
54+
resource "oci_core_default_route_table" "ExampleRT" {
55+
manage_default_resource_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
56+
route_rules {
57+
cidr_block = "0.0.0.0/0"
58+
network_entity_id = "${oci_core_internet_gateway.ExampleIG.id}"
59+
}
60+
}
61+
3162
# Gets the OCID of the image. This technique is for example purposes only. The results of oci_core_images may
3263
# change over time for Oracle-provided images, so the only sure way to get the correct OCID is to supply it directly.
3364
data "oci_core_images" "OLImageOCID" {
@@ -54,7 +85,7 @@ resource "oci_core_instance" "TFInstance1" {
5485
hostname_label = "instance3"
5586
image = "${lookup(data.oci_core_images.OLImageOCID.images[0], "id")}"
5687
shape = "VM.Standard1.2"
57-
subnet_id = "${var.SubnetOCID}"
88+
subnet_id = "${oci_core_subnet.ExampleSubnet.id}"
5889
extended_metadata {
5990
ssh_authorized_keys = "${var.ssh_public_key}"
6091
some_string = "stringA"

docs/examples/compute/instance/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# \___/|_| \_/_/ \_\____|_____|_____|
66
***
77
## Manage an instance
8-
This example launches an instance into an existing subnet, includes a user-data script in the instance launch, remote executes a command, and outputs the public and private IP address of the instance.
8+
This example launches an instance, includes a user-data script in the instance launch, remote executes a command, and outputs the public and private IP address of the instance.
99

1010
### Using this example
1111
* Update env-vars with the required information. Most examples use the same set of environment variables so you only need to do this once.

docs/examples/compute/instance/compute.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ resource "oci_core_instance" "TFInstance" {
22
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
33
compartment_id = "${var.compartment_ocid}"
44
display_name = "TFInstance"
5-
hostname_label = "instance1"
65
image = "${lookup(data.oci_core_images.OLImageOCID.images[0], "id")}"
76
shape = "${var.InstanceShape}"
8-
subnet_id = "${var.SubnetOCID}"
7+
8+
create_vnic_details {
9+
subnet_id = "${oci_core_subnet.ExampleSubnet.id}"
10+
display_name = "primaryvnic"
11+
assign_public_ip = true
12+
hostname_label = "tfexampleinstance"
13+
},
14+
915
metadata {
1016
ssh_authorized_keys = "${var.ssh_public_key}"
1117
user_data = "${base64encode(file(var.BootStrapFile))}"

docs/examples/compute/instance/env-vars

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@ export TF_VAR_ssh_private_key=$(cat <path to private key>)
1616
## NOTE: These are not your api keys. More info on the right keys see
1717
## https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingkeypairs.htm
1818

19-
## Specific to this example
20-
### Choose a subnet that exists in the AD and compartment you are launching the instance in
21-
export TF_VAR_SubnetOCID="<subnet>"
2219

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "oci_core_virtual_network" "ExampleVCN" {
2+
cidr_block = "10.1.0.0/16"
3+
compartment_id = "${var.compartment_ocid}"
4+
display_name = "TFExampleVCN"
5+
dns_label = "tfexamplevcn"
6+
}
7+
8+
resource "oci_core_subnet" "ExampleSubnet" {
9+
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
10+
cidr_block = "10.1.20.0/24"
11+
display_name = "TFExampleSubnet"
12+
dns_label = "tfexamplesubnet"
13+
security_list_ids = ["${oci_core_virtual_network.ExampleVCN.default_security_list_id}"]
14+
compartment_id = "${var.compartment_ocid}"
15+
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
16+
route_table_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
17+
dhcp_options_id = "${oci_core_virtual_network.ExampleVCN.default_dhcp_options_id}"
18+
}

docs/examples/compute/instance/variables.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ variable "compartment_ocid" {}
88
variable "ssh_public_key" {}
99
variable "ssh_private_key" {}
1010

11-
variable "SubnetOCID" {}
12-
1311
# Choose an Availability Domain
1412
variable "AD" {
1513
default = "1"

docs/examples/compute/instance_lite/instance_lite.tf

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

docs/examples/compute/multi_vnic/multi_vnic.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ resource "oci_core_virtual_network" "ExampleVCN" {
4545
resource "oci_core_subnet" "ExampleSubnet" {
4646
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
4747
cidr_block = "10.0.1.0/24"
48-
display_name = "ExampleSubnet"
48+
display_name = "TFExampleSubnet"
4949
compartment_id = "${var.compartment_ocid}"
5050
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
5151
route_table_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
@@ -64,7 +64,7 @@ data "oci_core_images" "OLImageOCID" {
6464
resource "oci_core_instance" "ExampleInstance" {
6565
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.AD - 1],"name")}"
6666
compartment_id = "${var.compartment_ocid}"
67-
display_name = "ExampleInstance"
67+
display_name = "TFExampleInstance"
6868
image = "${lookup(data.oci_core_images.OLImageOCID.images[0], "id")}"
6969
shape = "${var.InstanceShape}"
7070
subnet_id = "${oci_core_subnet.ExampleSubnet.id}"

0 commit comments

Comments
 (0)