Skip to content

Commit 1043d10

Browse files
Oke tfvars and instance principal (#89)
* Updated private networking docs to include kubernetes tfvars example, and removed deployment button. * Include instance principal in OKE setup and remove it from console. * Added instance_principal to examples. * Don't use instance principal by default. * Updated instance principal description.
1 parent f589b5a commit 1043d10

File tree

9 files changed

+135
-23
lines changed

9 files changed

+135
-23
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2020-2024 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
5+
locals {
6+
# Authentication configuration
7+
auth_config = {
8+
use_instance_principal = var.use_instance_principal
9+
auth_method = var.use_instance_principal ? "InstancePrincipal" : "UserCredentials"
10+
}
11+
}

cluster_creation_terraform/outputs.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,25 @@ output "endpoint_subnet_id" {
7575
value = local.endpoint_subnet_id
7676
}
7777

78+
# Authentication verification outputs
79+
output "authentication_method" {
80+
value = var.use_instance_principal ? "InstancePrincipal" : "UserCredentials"
81+
description = "The authentication method being used for OCI provider"
82+
}
83+
84+
output "use_instance_principal" {
85+
value = var.use_instance_principal
86+
description = "Whether Instance Principal authentication is enabled"
87+
}
88+
89+
output "auth_config_summary" {
90+
value = {
91+
use_instance_principal = var.use_instance_principal
92+
auth_method = var.use_instance_principal ? "InstancePrincipal" : "UserCredentials"
93+
user_ocid_set = var.use_instance_principal ? false : (var.user_ocid != "" && var.user_ocid != null)
94+
fingerprint_set = var.use_instance_principal ? false : (var.fingerprint != "" && var.fingerprint != null)
95+
private_key_path_set = var.use_instance_principal ? false : (var.private_key_path != "" && var.private_key_path != null)
96+
}
97+
description = "Summary of authentication configuration"
98+
}
99+

cluster_creation_terraform/providers.tf

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,33 @@
55
provider "oci" {
66
tenancy_ocid = var.tenancy_ocid
77
region = var.region
8+
auth = var.use_instance_principal ? "InstancePrincipal" : null
9+
10+
user_ocid = var.use_instance_principal ? null : var.user_ocid
11+
fingerprint = var.use_instance_principal ? null : var.fingerprint
12+
private_key_path = var.use_instance_principal ? null : var.private_key_path
813
}
914

1015
provider "oci" {
1116
alias = "home_region"
1217
tenancy_ocid = var.tenancy_ocid
1318
region = lookup(data.oci_identity_regions.home_region.regions[0], "name")
19+
auth = var.use_instance_principal ? "InstancePrincipal" : null
1420

15-
user_ocid = var.user_ocid
21+
user_ocid = var.use_instance_principal ? null : var.user_ocid
22+
fingerprint = var.use_instance_principal ? null : var.fingerprint
23+
private_key_path = var.use_instance_principal ? null : var.private_key_path
1624
}
1725

1826
provider "oci" {
1927
alias = "current_region"
2028
tenancy_ocid = var.tenancy_ocid
2129
region = var.region
30+
auth = var.use_instance_principal ? "InstancePrincipal" : null
2231

23-
user_ocid = var.user_ocid
32+
user_ocid = var.use_instance_principal ? null : var.user_ocid
33+
fingerprint = var.use_instance_principal ? null : var.fingerprint
34+
private_key_path = var.use_instance_principal ? null : var.private_key_path
2435
}
2536

2637
# New configuration to avoid Terraform Kubernetes provider interpolation. https://registry.terraform.io/providers/hashicorp/kubernetes/2.2.0/docs#stacking-with-managed-kubernetes-cluster-resources
@@ -55,4 +66,4 @@ locals {
5566
cluster_ca_certificate = base64decode(yamldecode(data.oci_containerengine_cluster_kube_config.oke.content)["clusters"][0]["cluster"]["certificate-authority-data"])
5667
cluster_id = yamldecode(data.oci_containerengine_cluster_kube_config.oke.content)["users"][0]["user"]["exec"]["args"][4]
5768
cluster_region = yamldecode(data.oci_containerengine_cluster_kube_config.oke.content)["users"][0]["user"]["exec"]["args"][6]
58-
}
69+
}

cluster_creation_terraform/schema.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ variableGroups:
2828
- title: "Advanced Configuration?"
2929
variables:
3030
- show_advanced
31+
32+
- title: "Authentication Method"
33+
variables:
34+
- use_instance_principal
35+
visible:
36+
and:
37+
- show_advanced
3138

3239
- title: "Network Configuration"
3340
variables:
@@ -63,6 +70,16 @@ variables:
6370
description: "Shows advanced options, allowing enable customer-managed encryption keys, select your ssh key, select/unselect cluster utilities, do not create policies, and other advanced options"
6471
visible: true
6572

73+
use_instance_principal:
74+
description: "Terraform provider will use Instance Principal authentication instead of user credentials. Requires the compute instance to have appropriate IAM policies."
75+
visible: false
76+
77+
fingerprint:
78+
visible: false
79+
80+
private_key_path:
81+
visible: false
82+
6683
network_configuration_mode:
6784
type: enum
6885
enum:

cluster_creation_terraform/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

5+
# Authentication Configuration
6+
variable "use_instance_principal" {
7+
type = bool
8+
default = false
9+
description = "Whether to use Instance Principal for authentication. If false, user credentials will be used."
10+
}
11+
12+
variable "fingerprint" {
13+
type = string
14+
default = ""
15+
description = "API Key Fingerprint for user authentication. Required when use_instance_principal is false."
16+
}
17+
18+
variable "private_key_path" {
19+
type = string
20+
default = ""
21+
description = "Path to the private key file for user authentication. Required when use_instance_principal is false."
22+
}
23+
524
# Networking Configuration Mode
625
variable "network_configuration_mode" {
726
default = "create_new"

docs/advanced/deploying_blueprints_to_private_networks/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ We do not create new completely locked down private subnets, but we do support t
88

99
Deploying into a private subnet may likely mean the subsequent Blueprints deployment cannot be installed with the "Stack", as the stack communicates with the cluster over a public endpoint from the internet. If it is acceptable for you to have a public API endpoint but only private worker nodes, **return to the original deployment in [getting started](../../../GETTING_STARTED_README.md)**, otherwise continue.
1010

11-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-quickstart/oci-ai-blueprints/releases/download/v1.0.3/v1.0.3_cluster.zip)
11+
## Terraform Setup
1212

13-
1. Click **Deploy to Oracle Cloud** above.
13+
It may be preferable for some users to deploy with terraform in the scenario where you bring your own network. If your networking setup does not allow for installation via the stack deployment in the OCI console, it is still possible to deploy with terraform locally using the following steps:
14+
15+
1. Setup a bastion or get on a workstation with the ability to communicate with your cluster's API Endpoint. An example document is given above.
16+
2. Install the Terraform CLI from [here](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) from the bastioned host.
17+
3. Install the OCI CLI from [here](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm) and configure authentication in your `~/.oci/config` according to [this](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliconfigure.htm).
18+
4. Clone our GitHub repository locally, and change directory into `oci-ai-blueprints/oci_ai_blueprints_terraform`
19+
5. Initialize the terraform with `terraform init`.
20+
6. Create a tfvars file in that directory called `terraform.tfvars`. The minimum variables needed are in [example_cluster_tfvars.md](./example_cluster_tfvars.md) and [example_blueprints_tfvars.md](./example_blueprints_tfvars.md) for each respective stack.
21+
7. Run a `terraform plan` to ensure nothing is missing.
22+
8. Run a `terraform apply` to install the Blueprints platform on your OKE cluster.
23+
24+
**Note**: When deploying with terraform, it is important that you specify the correct stack version in the tfvars file. If you use an older version of the stack, this will be used for the blueprints version running in the control plane. If a mistake happens, it is very easy to modify the tfvars file to the correct stack version and reapply your changes, which would force an updated container pull.
25+
26+
## Console based deployment for OKE
27+
28+
1. Click on the deployment button in [this section](../../../GETTING_STARTED_README.md#step-2-deploy-the-vcn-and-oke-cluster), which will take you to the OKE deployment stack.
1429
2. In **Create Stack**:
1530
- Give your stack a **name** (e.g., _oke-stack_).
1631
- Select the **compartment** where you want OCI AI Blueprints deployed.
@@ -24,19 +39,8 @@ For documentation on access and networking configurations for locked down enviro
2439
- [Kubernetes API Endpoint Subnet Configuration](https://docs.oracle.com/en-us/iaas/Content/ContEng/Concepts/contengnetworkconfig.htm#subnetconfig__section_kcm_v2b_s4b)
2540
- [Setting Up a Bastion for Cluster Access](https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengsettingupbastion.htm#contengsettingupbastion)
2641

27-
---
28-
29-
## Deploying Blueprints with Terraform
30-
31-
If your networking setup does not allow for installation via the stack deployment in the OCI console, it is still possible to deploy with terraform locally using the following steps:
42+
## Console based deployment for Blueprints
3243

33-
1. Setup a bastion or get on a workstation with the ability to communicate with your cluster's API Endpoint. An example document is given above.
34-
2. Install the Terraform CLI from [here](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) from the bastioned host.
35-
3. Install the OCI CLI from [here](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm) and configure authentication in your `~/.oci/config` according to [this](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliconfigure.htm).
36-
4. Clone our GitHub repository locally, and change directory into `oci-ai-blueprints/oci_ai_blueprints_terraform`
37-
5. Initialize the terraform with `terraform init`.
38-
6. Create a tfvars file in that directory called `terraform.tfvars`. The minimum variables needed are in [example_tfvars.md](./example_tfvars.md).
39-
7. Run a `terraform plan` to ensure nothing is missing.
40-
8. Run a `terraform apply` to install the Blueprints platform on your OKE cluster.
44+
This document describes deploying blueprints into private networks. Since private networks are generally blocked from the console, see the terraform steps above.
4145

42-
Depending on your setup, you may need to either setup a windows server or submit API calls directly from code from trusted sources.
46+
If you are not blocked from the console, the only change to make from the default deployment is to set **Load Balancer Visibility** to **Private** which is under the **Public Endpoints** section.

docs/advanced/deploying_blueprints_to_private_networks/example_tfvars.md renamed to docs/advanced/deploying_blueprints_to_private_networks/example_blueprints_tfvars.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ corrino_admin_username = "admin" # use something else
99
corrino_admin_nonce = "password" # use something else
1010
corrino_admin_email = "[email protected]"
1111
12+
# If you want to authenticate with instance principal
13+
use_instance_principal = true
14+
1215
# Leave these
1316
ingress_nginx_enabled = true
1417
cert_manager_enabled = false
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```
2+
# Your actual region
3+
region = "us-ashburn-1"
4+
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa____za"
5+
compartment_ocid = "ocid1.compartment.oc1..aaaaaaaa____5a"
6+
7+
# If you want to authenticate with instance principal
8+
use_instance_principal = true
9+
10+
network_configuration_mode = "bring_your_own"
11+
existing_vcn_id = "ocid1.vcn.oc1.iad.amaaaaaam____a"
12+
existing_endpoint_subnet_id = "ocid1.subnet.oc1.iad.aaaaaaaa____q"
13+
existing_node_subnet_id = "ocid1.subnet.oc1.iad.aaaaaaaa____q"
14+
existing_lb_subnet_id = "ocid1.subnet.oc1.iad.aaaaaaaa____q"
15+
k8s_version = "v1.31.1"
16+
cluster_workers_visibility = "Private"
17+
cluster_endpoint_visibility_existing_vcn = "Private"
18+
num_pool_workers = 3
19+
node_pool_name = "control-plane"
20+
node_pool_instance_shape = {
21+
instanceShape = "VM.Standard.E3.Flex"
22+
ocpus = 6
23+
memory = 64
24+
}
25+
node_pool_boot_volume_size_in_gbs = 100
26+
```

oci_ai_blueprints_terraform/schema.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ variables:
508508
use_instance_principal:
509509
type: boolean
510510
title: "Use Instance Principal Authentication"
511-
description: "Enable this to use Instance Principal authentication instead of user credentials. Requires the compute instance to have appropriate IAM policies."
511+
description: "Terraform provider will use Instance Principal authentication instead of user credentials. Requires the compute instance to have appropriate IAM policies."
512512
default: false
513-
visible: true
513+
visible: false
514514

515515
private_key_path:
516516
visible: false
@@ -1395,6 +1395,5 @@ outputs:
13951395
use_instance_principal:
13961396
type: boolean
13971397
title: "Use Instance Principal Authentication"
1398-
description: "Enable this to use Instance Principal authentication instead of user credentials. Requires the compute instance to have appropriate IAM policies."
1399-
default: false
1398+
description: "Terraform provider will use Instance Principal authentication instead of user credentials. Requires the compute instance to have appropriate IAM policies."
14001399
visible: true

0 commit comments

Comments
 (0)