Skip to content

Commit 9308fab

Browse files
committed
Container Instance Tutorial Update
1 parent b28d4a4 commit 9308fab

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

ci-automation/1-automation-basics.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ This tutorial assumes you already have some Terraform and/or OCI CLI experience.
4848

4949
### CLIs
5050

51-
CLIs are a little bit better than GUIs for helping you manage critical issues. Instead of pointing-and-clicking, commands are directly issued into the application. When you get down to it, CLIs are really just a text user interface. Most CLIs allow for running "headless", meaning they don't require continuous user input (all input can be provided at runtime). One benefit is that it's easier to use CLIs with automated workflows, so it's definitely a step in the right direction. By themselves though, it's impossible to embed any sort of logic when using CLIs, unless there's some sort of scripting (shell scripts, Ruby, Python, etc.) involved. This means that it's great to send a single command (or even a series of commands), but it can be difficult to maintain a high level of assurance without more involved scripting logic being used with the CLI.
51+
CLIs are a little bit better than GUIs for helping you manage critical issues. Instead of pointing-and-clicking, commands are directly issued into the application. When you get down to it, CLIs are really just a text user interface. Most CLIs allow for running "headless", meaning they don't require continuous user input (all input can be provided at runtime). One benefit is that it's easier to use CLIs with automated workflows, so it's definitely a step in the right direction. By themselves though, it's impossible to embed any sort of logic when using CLIs, this is where some sort of scripting (shell scripts, Ruby, Python, etc.) can add significant benefit. After determining the set of CLI commands to run, you can utilize the scripting tool of choice to implement logic and create repeatable automation activities.
5252

5353
### IaC tools
5454

5555
When you really need to tailor your environment and maximize control over how it performs, IaC tools are what you need. IaC tools are designed from the ground-up to manage infrastructure resources using code. Resources are defined within the code, with the tool itself providing the necessary structure and logic to quickly and easily build a definition of what you need or want an environment to be. The basic "scaffolding" (logic elements, API interactions, etc.) are all abstracted, allowing you to focus on describing the resources you need or want to exist in the environment.
5656

57-
By far, this is one of the easiest and fastest ways to build and maintain cloud environments. But this isn't just limited to the cloud, on-premesis resources can often be managed with IaC tools as well. Are you using multiple cloud providers? Even more reason to utilize IaC in managing your IT infrastructure.
57+
By far, this is one of the easiest and fastest ways to build and maintain cloud environments. But this isn't just limited to the cloud; on-premesis resources can often be managed with IaC tools as well. Are you using multiple cloud providers? Even more reason to utilize IaC in managing your IT infrastructure.
5858

5959
With IaC, it's common to use Git on the back-end. Git allows you to get a deep history of changes and its robust version control system enables easy and rapid rollbacks. Additionally, if you use Git for storing the code definitions, you're able to use standard processes and tools to monitor/approve/manage changes before they're made. Whether using policy-as-code (such as [Open Policy Agent](https://www.openpolicyagent.org), with implementations such as [Policy-as-Code on OCI using Open Policy Agent](https://github.com/oracle-devrel/oci-pac-opa)) or a manual pull request (PR)/merge request (MR) review process, you can have a really solid review/approval/compliance mechanism (not to mention yet another audit trail that's separate from the cloud/platform itself).
6060

@@ -66,15 +66,15 @@ One of the most common and popular IaC tools is [HashiCorp Terraform](https://ww
6666

6767
Sometimes infrastructure isn't your major concern and what you really need are tools that predominantly operate in the realm of configuration management, such as [Ansible](https://www.ansible.com) or [Chef](https://www.chef.io)/[Cinc](https://cinc.sh). These are all options for managing infrastructure as well, but you may be better off with tools that focus exclusively on *infrastructure management*. For OCI's part, it's certainly no exception in supporting many of these different platforms.
6868

69-
## IaC and Terraform
69+
## CLI and IaC (Terraform)
7070

71-
In the rest of this series, we're going to target using Terraform to manage OCI infrastructure. Why Terraform? It's fairly mature at this point, widely adopted, and has support for a wide variety of cloud platforms, including OCI. Additionally, there are plenty of resources available and Terraform enjoys strong user support, making it an ideal tool. Terraform is mainly targeted at managing infrastructure and not so much the configuration management side of things. But it's super powerful when combined with a traditional configuration management tool like Ansible.
71+
For the remainder of this series we are going to explore the capabilities of CLI and IaC for deploying and managing infrastructure. We'll compare the pros and cons of each so you can ultimately make the decision regarding which fits best for your particular situation.
7272

7373
## What's Next
7474

75-
By now, you should be a little more familiar with IaC and ready to get started with Terraform!
75+
By now, you should have a basic understanding of how to configure the tools (Command Line Interface and Terraform) illustrated in this tutorial. You're ready to dive right in and start automating.
7676

77-
Until your next lesson, happy coding! Take a look at the [next lesson](2-experiencing-terraform) in the Terraform 101 series and go through a very quick experience in using Terraform. From there, you'll dive into several aspects of how Terraform works.
77+
Until your next lesson, happy coding! Take a look at the [next lesson](2-automated-deployment-cli) in the Container Instances Automation 101 series, and go through the process of deploying resources using the OCI CLI. After that, you'll experiment with Terraform before moving on to some more advanced use cases.
7878

7979
To explore more information about development with Oracle products:
8080

ci-automation/2-automated-deployment-cli.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ slug: 2-automated-deployment-cli
2626

2727
In this tutorial we are going to build a simple virtual network environment and deploy an OCI Container Instance resource. The Container Instance will run two containers; WordPress in one, and MySQL in the other. All of the work is done at the command prompt and when you're finished, you could easily create a bash script for one-click deployment in the future.
2828

29-
If you do not yet have the CLI installed, [Click Here][1] to follow the instructions. WHen you're ready to go, dive right in!
29+
This tutorial is designed for use in the OCI Cloud Shell [OCI Cloud Shell][1]. The Cloud Shell is an easy-to-use terminal built right into the OCI Console, with integrated authorization. If your preference is to install the OCI CLI elsewhere, that is also a cinch, just [Click Here][2] to follow the instructions. When you're ready to go, dive right in!
3030

3131
### Gather Required Information
3232
The prep work involves identifying your preferred availability domain and working compartment. It is recommended you do not use the *root* compartment in your tenancy, however, the instructions will accommodate use of *root* if you so choose.
@@ -41,36 +41,36 @@ The command output is JSON so there are a few tricks we can use to easily captur
4141

4242
One more example before we move on. The following will query for the availability domain that includes "AD-1" in the name. If you'd like to use a different AD, just change the number.
4343

44-
oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].[id,name]' | sed 's/"//g'
44+
oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].[id,name]' --raw-output'
4545

4646
Capture the availability domain id and name in environment variables.
4747

48-
adId=($(oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].id' | sed 's/"//g'))
48+
adId=($(oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].id' --raw-output))
4949

50-
adName=($(oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].name' | sed 's/"//g'))
50+
adName=($(oci iam availability-domain list --query 'data[?contains ("name",`AD-1`)]|[0].name' --raw-output))
5151

5252
You can quickly echo the values to confirm they both loaded properly:
5353
![Screenshot of: echo command output][4]
5454

5555
The final piece of information required before creating resources is the Compartment OCID. In this example, our compartment name is **Training**.
5656

57-
compOcid=($(oci iam compartment list --query 'data[?name==`Training`]|[0].id' | sed 's/"//g'))
57+
compOcid=($(oci iam compartment list --query 'data[?name==`Training`]|[0].id' --raw-output))
5858

5959
If you prefer to use the root compartment, the query looks a little different:
6060

61-
compOcid=($(oci iam compartment list --query 'data[0]."compartment-id"' | sed 's/"//g'))
61+
compOcid=($(oci iam compartment list --query 'data[0]."compartment-id"' --raw-output))
6262

6363
### Create the network resources
6464
We are going to create a Virtual Cloud Network (VCN) with a single public subnet, a security list that allows ingress traffic on port 80 (to access the WordPress server), an Internet Gateway, and add a route for the Internet Gateway to the default route table. Let's do this!
6565

6666
Create the VCN! Here we are using 10.0.0.0/16 as the network CIDR. You may opt for a different range...if you do, just make sure you change it accordingly in subsequent steps.
6767
**Note** Because we are loading specific output directly to an environment variable, the command will return nothing to the screen unless there is an error.
6868

69-
vcnOcid=($(oci network vcn create --cidr-block 10.0.0.0/16 -c $compOcid --display-name ContainerInstance-VCN --dns-label cidemovcn --query 'data.id' | sed 's/"/g'))
69+
vcnOcid=($(oci network vcn create --cidr-block 10.0.0.0/16 -c $compOcid --display-name ContainerInstance-VCN --dns-label cidemovcn --query 'data.id' --raw-output))
7070

7171
Create the security list. When we create the subnet it expects an array of security list IDs, so we'll go ahead and store the array in the variable.
7272

73-
seclistOcid=('["'$(oci network security-list create --display-name PubSub1 --compartment-id $compOcid --vcn-id $vcnOcid --egress-security-rules '[{"destination": "0.0.0.0/0", "destination-type": "CIDR_BLOCK", "protocol": "all", "isStateless": false}]' --ingress-security-rules '[{"source": "0.0.0.0/0", "source-type": "CIDR_BLOCK", "protocol": 6, "isStateless": false, "tcp-options": {"destination-port-range": {"max": 80, "min": 80}}}]' --query 'data.id' | sed 's/"//g')'"]')
73+
seclistOcid=('["'$(oci network security-list create --display-name PubSub1 --compartment-id $compOcid --vcn-id $vcnOcid --egress-security-rules '[{"destination": "0.0.0.0/0", "destination-type": "CIDR_BLOCK", "protocol": "all", "isStateless": false}]' --ingress-security-rules '[{"source": "0.0.0.0/0", "source-type": "CIDR_BLOCK", "protocol": 6, "isStateless": false, "tcp-options": {"destination-port-range": {"max": 80, "min": 80}}}]' --query 'data.id' --raw-output)'"]')
7474

7575
Create the internet gateway, obtain the id of the default VCN route table, and add a new route to the default route to said route table.
7676

@@ -85,7 +85,7 @@ The final command will output the results of the action:
8585

8686
Now just create the subnet where the Container Instance will be deployed...easy as that!
8787

88-
pubsubId=($(oci network subnet create --cidr-block 10.0.10.0/24 -c $compOcid --vcn-id $vcnOcid --security-list-ids $seclistOcid --query 'data.id' | sed 's/"//g'))
88+
pubsubId=($(oci network subnet create --cidr-block 10.0.10.0/24 -c $compOcid --vcn-id $vcnOcid --security-list-ids $seclistOcid --query 'data.id' --raw-output))
8989

9090
### Container Instance Resources
9191

@@ -118,7 +118,7 @@ If you look near the end of the output you'll find a section for the *vnics* - a
118118

119119
In the JSON output from the command above, locate the **id** for the container instance and copy it (or store it in an environment variable). Then run:
120120

121-
oci container-instances --container-instance get --container-instance-id <the id you coiped above>
121+
oci container-instances --container-instance get --container-instance-id <the id you coieed above>
122122

123123
Now in the output you'll see an **id** for the vnic.
124124
![Screenshot of: Valid vnic id value][8]
@@ -208,12 +208,13 @@ There you have it, and well done! You've just completely provisioned OCI Contain
208208

209209

210210

211-
[1]: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm
212-
[2]: assets/ci-automation-cli-01.png
213-
[3]: https://jmespath.org/
214-
[4]: assets/ci-automation-cli-02.png
215-
[5]: assets/ci-automation-cli-03.png
216-
[6]: assets/ci-automation-cli-04.png
217-
[7]: assets/ci-automation-cli-05.png
218-
[8]: assets/ci-automation-cli-06.png
219-
[9]: assets/ci-automation-cli-07.png
211+
[1]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/cloudshellintro.htm
212+
[2]: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm
213+
[3]: assets/ci-automation-cli-01.png
214+
[4]: https://jmespath.org/
215+
[5]: assets/ci-automation-cli-02.png
216+
[6]: assets/ci-automation-cli-03.png
217+
[7]: assets/ci-automation-cli-04.png
218+
[8]: assets/ci-automation-cli-05.png
219+
[9]: assets/ci-automation-cli-06.png
220+
[10]: assets/ci-automation-cli-07.png

ci-automation/4-incorporate-ocir.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Automated Deployment with Terraform
3+
parent:
4+
- tutorials
5+
- ci-automation
6+
sidebar: series
7+
tags:
8+
- open-source
9+
- iac
10+
- terraform
11+
- devops
12+
- get-started
13+
categories:
14+
- iac
15+
- opensource
16+
thumbnail: assets/ci-automation.png
17+
date: 2023-02-01 12:00
18+
description: Now that you've seen the CLI in action, let's take a look at how to perform similar resource provisioning using Terraform.
19+
toc: true
20+
author: eli-schilling
21+
redirect_from: "/collections/tutorials/1-automation-basics/"
22+
mrm:
23+
xredirect: https://developer.oracle.com/tutorials/ci-automation/1-automation-basics/
24+
slug: 3-automated-deployment-tf.md
25+
---
26+
{% imgx aligncenter assets/ci-automation.png 400 400 "Automating Container Instances" "Container Instances Automation Tutorial Series" %}
17 KB
Loading

0 commit comments

Comments
 (0)