|
| 1 | +# oci-quickstart-template |
| 2 | + |
| 3 | +The [Oracle Cloud Infrastructure (OCI) Quick Start](https://github.com/oracle-quickstart?q=oci-quickstart) is a collection of examples that allow Oracle Cloud Infrastructure users to get a quick start deploying advanced infrastructure on OCI. |
| 4 | + |
| 5 | +The oci-quickstart-template repository contains the template that can be used for accelerating the construction of quickstarts that runs from local Terraform CLI, [OCI Resource Manager](https://docs.cloud.oracle.com/en-us/iaas/Content/ResourceManager/Concepts/resourcemanager.htm) and [OCI Cloud Shell](https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/cloudshellintro.htm). |
| 6 | + |
| 7 | +Simple is a sample quickstart terraform template that deploys a virtual machine on a Virtual Cloud Network. |
| 8 | +Simple can be customized to subscribe and launch Marketplace images, Platform images or Custom images. |
| 9 | + |
| 10 | +This repo is under active development. Building open source software is a community effort. We're excited to engage with the community building this. |
| 11 | + |
| 12 | +## Resource Manager Deployment |
| 13 | + |
| 14 | +This Quick Start uses [OCI Resource Manager](https://docs.cloud.oracle.com/iaas/Content/ResourceManager/Concepts/resourcemanager.htm) to make deployment easy, sign up for an [OCI account](https://cloud.oracle.com/en_US/tryit) if you don't have one, and just click the button below: |
| 15 | + |
| 16 | +[](https://console.us-ashburn-1.oraclecloud.com/resourcemanager/stacks/create?region=home&zipUrl=https://github.com/oracle-quickstart/oci-quickstart-template/archive/master.zip) |
| 17 | + |
| 18 | +After logging into the console you'll be taken through the same steps described |
| 19 | +in the [Deploy](#deploy) section below. |
| 20 | + |
| 21 | +Note, if you use this template to create another repo you'll need to change the link for the button to point at your repo. |
| 22 | + |
| 23 | +## Local Development |
| 24 | + |
| 25 | +First off we'll need to do some pre deploy setup. That's all detailed [here](https://github.com/oracle/oci-quickstart-prerequisites). |
| 26 | + |
| 27 | +Note, the instructions below build a `.zip` file from you local copy for use in ORM. |
| 28 | +If you want to not use ORM and deploy with the terraform CLI you need to rename |
| 29 | +`provider.tf.cli -> provider.tf`. This is because authentication works slightly |
| 30 | +differently in ORM vs the CLI. This file is ignored by the build process below. |
| 31 | + |
| 32 | +Make sure you have terraform v0.12+ cli installed and accessible from your terminal. |
| 33 | + |
| 34 | +```bash |
| 35 | +terraform -v |
| 36 | + |
| 37 | +Terraform v0.12.24 |
| 38 | ++ provider.null v2.1.2 |
| 39 | ++ provider.oci v3.71.0 |
| 40 | +``` |
| 41 | + |
| 42 | +### Build |
| 43 | + |
| 44 | +Simply `build` your package and follow the [Resource Manager instructions](https://docs.cloud.oracle.com/en-us/iaas/Content/ResourceManager/Tasks/managingstacksandjobs.htm#console) for how to create a stack. Prior to building the Stack, you may want to modify some parts of the deployment detailed below. |
| 45 | + |
| 46 | +In order to `build` the zip file with the latest changes you made to this code, you can simply go to [build-orm](./build-orm) folder and use terraform to generate a new zip file: |
| 47 | + |
| 48 | +At first time, you are required to initialize the terraform modules used by the template with `terraform init` command: |
| 49 | + |
| 50 | +```bash |
| 51 | +$ terraform init |
| 52 | + |
| 53 | +Initializing the backend... |
| 54 | + |
| 55 | +Initializing provider plugins... |
| 56 | +- Checking for available provider plugins... |
| 57 | +- Downloading plugin for provider "archive" (hashicorp/archive) 1.3.0... |
| 58 | + |
| 59 | +The following providers do not have any version constraints in configuration, |
| 60 | +so the latest version was installed. |
| 61 | + |
| 62 | +To prevent automatic upgrades to new major versions that may contain breaking |
| 63 | +changes, it is recommended to add version = "..." constraints to the |
| 64 | +corresponding provider blocks in configuration, with the constraint strings |
| 65 | +suggested below. |
| 66 | + |
| 67 | +* provider.archive: version = "~> 1.3" |
| 68 | + |
| 69 | +Terraform has been successfully initialized! |
| 70 | + |
| 71 | +You may now begin working with Terraform. Try running "terraform plan" to see |
| 72 | +any changes that are required for your infrastructure. All Terraform commands |
| 73 | +should now work. |
| 74 | + |
| 75 | +If you ever set or change modules or backend configuration for Terraform, |
| 76 | +rerun this command to reinitialize your working directory. If you forget, other |
| 77 | +commands will detect it and remind you to do so if necessary. |
| 78 | +``` |
| 79 | +
|
| 80 | +Once terraform is initialized, just run `terraform apply` to generate ORM zip file. |
| 81 | +
|
| 82 | +```bash |
| 83 | +$ terraform apply |
| 84 | + |
| 85 | +data.archive_file.generate_zip: Refreshing state... |
| 86 | + |
| 87 | +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. |
| 88 | +``` |
| 89 | +
|
| 90 | +This command will package the content of `simple` folder into a zip and will store it in the `build-orm\dist` folder. You can check the content of the file by running `unzip -l dist/orm.zip`: |
| 91 | +
|
| 92 | +```bash |
| 93 | +$ unzip -l dist/orm.zip |
| 94 | +Archive: dist/orm.zip |
| 95 | + Length Date Time Name |
| 96 | +--------- ---------- ----- ---- |
| 97 | + 5324 01-01-2049 00:00 README_simple.md |
| 98 | + 1140 01-01-2049 00:00 compute.tf |
| 99 | + 680 01-01-2049 00:00 data_sources.tf |
| 100 | + 1632 01-01-2049 00:00 image_subscription.tf |
| 101 | + 1359 01-01-2049 00:00 locals.tf |
| 102 | + 13540 01-01-2049 00:00 marketplace.yaml |
| 103 | + 2001 01-01-2049 00:00 network.tf |
| 104 | + 2478 01-01-2049 00:00 nsg.tf |
| 105 | + 1092 01-01-2049 00:00 outputs.tf |
| 106 | + 44 01-01-2049 00:00 scripts/example.sh |
| 107 | + 4848 01-01-2049 00:00 variables.tf |
| 108 | + 46 01-01-2049 00:00 versions.tf |
| 109 | +--------- ------- |
| 110 | + 34184 12 files |
| 111 | +``` |
| 112 | +
|
| 113 | +### Deploy |
| 114 | +
|
| 115 | +1. [Login](https://console.us-ashburn-1.oraclecloud.com/resourcemanager/stacks/create) to Oracle Cloud Infrastructure to import the stack |
| 116 | + > `Home > Solutions & Platform > Resource Manager > Stacks > Create Stack` |
| 117 | +
|
| 118 | +2. Upload the `orm.zip` and provide a name and description for the stack |
| 119 | + |
| 120 | +
|
| 121 | +3. Configure the Stack. The UI will present the variables to the user dynamically, based on their selections. These are the configuration options: |
| 122 | +
|
| 123 | +> Compute Configuration |
| 124 | +
|
| 125 | +| VARIABLE | DESCRIPTION | |
| 126 | +|----------------------------|-----------------------------------------------------------------------| |
| 127 | +|COMPUTE COMPARTMENT | Compartment for Compute resources, including Marketplace subscription | |
| 128 | +|INSTANCE NAME | Compute instance name| |
| 129 | +|DNS HOSTNAME LABEL | DNS Hostname| |
| 130 | +|COMPUTE SHAPE | Compatible Compute shape| |
| 131 | +|FLEX SHAPE OCPUS | Number of OCPUs, only available for VM.Standard.E3.Flex compute shape| |
| 132 | +|AVAILABILITY DOMAIN | Availability Domain| |
| 133 | +|PUBLIC SSH KEY STRING | RSA PUBLIC SSH key string used for sign in to the OS| |
| 134 | +
|
| 135 | +> Virtual Cloud Network |
| 136 | +
|
| 137 | +| VARIABLE | DESCRIPTION | |
| 138 | +|----------------------------|-----------------------------------------------------------------------| |
| 139 | +|NETWORK COMPARTMENT | Compartment for all Virtual Cloud Nettwork resources| |
| 140 | +|NETWORK STRATEGY | `Create New VCN and Subnet`: Create new network resources during apply. <br> `Use Existing VCN and Subnet`: Let user select pre-existent network resources.| |
| 141 | +|CONFIGURATION STRATEGY | `Use Recommended Configuration`: Use default configuration defined by the Terraform template. <br> `Customize Network Configuration`: Allow user to customize network configuration such as name, dns label, cidr block for VCN and Subnet.| |
| 142 | +
|
| 143 | +> Virtual Cloud Network - Customize Network Configuration |
| 144 | +
|
| 145 | +| VARIABLE | DESCRIPTION | |
| 146 | +|----------------------------|-----------------------------------------------------------------------| |
| 147 | +|NAME | VCN Display Name| |
| 148 | +|DNS LABEL | VCN DNS LABEL| |
| 149 | +|CIDR BLOCK | The CIDR of the new Virtual Cloud Network (VCN). If you plan to peer this VCN with another VCN, the VCNs must not have overlapping CIDRs.| |
| 150 | +
|
| 151 | +> Simple Subnet (visible only when `Customize Network Configuration` is selected) |
| 152 | +
|
| 153 | +| VARIABLE | DESCRIPTION | |
| 154 | +|----------------------------|-----------------------------------------------------------------------| |
| 155 | +|SUBNET TYPE | `Public Subnet` or `Private Subnet`| |
| 156 | +|NAME | Subnet Display Name| |
| 157 | +|DNS LABEL | Subnet DNS LABEL| |
| 158 | +|CIDR BLOCK | The CIDR of the Subnet. Should not overlap with any other subnet CIDRs| |
| 159 | +|NETWORK SECURITY GROUP CONFIGURATION| `Use Recommended Configuration`: Use default configuration defined by the Terraform template. <br> `Customize Network Security Group`: Allow user to customize some basic network security group settings.| |
| 160 | +
|
| 161 | +> Network Security Group (visible only when `Customize Network Security Group` is selected) |
| 162 | +
|
| 163 | +| VARIABLE | DESCRIPTION | |
| 164 | +|----------------------------|-----------------------------------------------------------------------| |
| 165 | +|NAME | NSG Display Name| |
| 166 | +|ALLOWED INGRESS TRAFFIC (CIDR BLOCK)| WHITELISTED CIDR BLOCK for ingress traffic| |
| 167 | +|SSH PORT NUMBER | Default SSH PORT for ingress traffic| |
| 168 | +|HTTP PORT NUMBER | Default HTTP PORT for ingress traffic| |
| 169 | +|HTTPS PORT NUMBER | Default HTTPS PORT for ingress traffic| |
| 170 | +
|
| 171 | +> Additional Configuration Options |
| 172 | +
|
| 173 | +| VARIABLE | DESCRIPTION | |
| 174 | +|----------------------------|-----------------------------------------------------------------------| |
| 175 | +|TAG KEY NAME | Free-form tag key name| |
| 176 | +|TAG VALUE | Free-form tag value| |
| 177 | +
|
| 178 | +4. Click Next and Review the configuration. |
| 179 | +5. Click Create button to confirm and create your ORM Stack. |
| 180 | +6. On Stack Details page, you can now run `Terraform` commands to manage your infrastructure. You typically start with a plan then run apply to create and make changes to the infrastructure. More details below: |
| 181 | +
|
| 182 | +| TERRAFORM ACTIONS | DESCRIPTION | |
| 183 | +|----------------------------|-----------------------------------------------------------------------| |
| 184 | +|Plan | `terraform plan` is used to create an execution plan. This command is a convenient way to check the execution plan prior to make any changes to the infrastructure resources.| |
| 185 | +|Apply | `terraform apply` is used to apply the changes required to reach the desired state of the configuration described by the template.| |
| 186 | +|Destroy | `terraform destroy` is used to destroy the Terraform-managed infrastructure.| |
| 187 | +
|
| 188 | +## Customize for Marketplace |
| 189 | +
|
| 190 | +In case you wanted to make changes to this template to use a Marketplace image rather than a platform image or custom image, you need to make the following changes. |
| 191 | +
|
| 192 | +1. Configure Marketplace listing variables on [`variables.tf`](./variables.tf). |
| 193 | +
|
| 194 | +| VARIABLES | DESCRIPTION | |
| 195 | +|----------------------------|-----------------------------------------------------------------------| |
| 196 | +|mp_subscription_enabled | Enable subscription to Marketplace.| |
| 197 | +|mp_listing_id | Marketplace App Catalog Listing OCID.| |
| 198 | +|mp_listing_resource_id | Marketplace Listing Image OCID.| |
| 199 | +|mp_listing_resource_version | Marketplace Listing Package/Resource Version (Reference value)| |
| 200 | +
|
| 201 | +2. Modify [`compute.tf`](./compute.tf) set `source_details` to refer to `local.compute_image_id` rather than `platform_image_id`. The `local.compute_image_id` holds the logic to either refer to the marketplace image or a custom image, based on the `mp_subscription_enabled` flag. |
| 202 | +
|
| 203 | +```hcl |
| 204 | +resource "oci_core_instance" "simple-vm" { |
| 205 | + availability_domain = local.availability_domain |
| 206 | + compartment_id = var.compute_compartment_ocid |
| 207 | + display_name = var.vm_display_name |
| 208 | + shape = var.vm_compute_shape |
| 209 | +
|
| 210 | + dynamic "shape_config" { |
| 211 | + for_each = local.is_flex_shape |
| 212 | + content { |
| 213 | + ocpus = shape_config.value |
| 214 | + } |
| 215 | + } |
| 216 | +
|
| 217 | +
|
| 218 | + create_vnic_details { |
| 219 | + subnet_id = local.use_existing_network ? var.subnet_id : oci_core_subnet.simple_subnet[0].id |
| 220 | + display_name = var.subnet_display_name |
| 221 | + assign_public_ip = local.is_public_subnet |
| 222 | + hostname_label = var.hostname_label |
| 223 | + skip_source_dest_check = false |
| 224 | + nsg_ids = [oci_core_network_security_group.simple_nsg.id] |
| 225 | + } |
| 226 | +
|
| 227 | + source_details { |
| 228 | + source_type = "image" |
| 229 | + #use a marketplace image or custom image: |
| 230 | + source_id = local.compute_image_id |
| 231 | + } |
| 232 | +
|
| 233 | +``` |
| 234 | +
|
| 235 | +2. Run your tests using the Terraform CLI or build a new package and deploy on ORM. |
0 commit comments