Skip to content

Commit 269d3fd

Browse files
authored
fix: Ignore lifecycle changes, support Resource Manager variables (#583)
* Remove extraneous icmp_options reporting change each apply Signed-off-by: Devon Crouse <[email protected]> * Ignore node pool changes for automatic tagging and dynamic variables reporting change each apply Signed-off-by: Devon Crouse <[email protected]> * Use specific compartment for AD listing Signed-off-by: Devon Crouse <[email protected]> * Ignore cluster changes for automatic tagging reporting change each apply Signed-off-by: Devon Crouse <[email protected]> * Suppress reported output changes on each apply/destroy Signed-off-by: Devon Crouse <[email protected]> * Ignore dynamic kubeconfig changes reported each apply w/ refresh option Signed-off-by: Devon Crouse <[email protected]> * Support variable naming populated by Resource Manager Signed-off-by: Devon Crouse <[email protected]> * Provided bastion IP fallback if creation disabled, omit -i if no key file for output var Signed-off-by: Devon Crouse <[email protected]> * Use stable random suffix for dynamic group name Signed-off-by: Devon Crouse <[email protected]> * Fall back to provided bastion/operator addresses, user config Signed-off-by: Devon Crouse <[email protected]> * Clarify TF resource naming for operator IAM * Update modules: bastion 3.1.2, operator 3.1.1 Signed-off-by: Devon Crouse <[email protected]> Signed-off-by: Devon Crouse <[email protected]>
1 parent 87e2f2e commit 269d3fd

25 files changed

+211
-82
lines changed

datasource.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
data "oci_core_vcns" "vcns" {
55
count = var.create_vcn == true ? 0 : 1
66

7-
compartment_id = var.compartment_id
7+
compartment_id = local.compartment_id
88
display_name = var.vcn_display_name
99

1010
state = "AVAILABLE"
@@ -13,7 +13,7 @@ data "oci_core_vcns" "vcns" {
1313
data "oci_core_route_tables" "nat" {
1414
count = var.create_vcn == true ? 0 : 1
1515

16-
compartment_id = var.compartment_id
16+
compartment_id = local.compartment_id
1717

1818
display_name = var.nat_route_table_display_name
1919
vcn_id = local.vcn_id
@@ -24,7 +24,7 @@ data "oci_core_route_tables" "nat" {
2424
data "oci_core_route_tables" "ig" {
2525
count = var.create_vcn == true ? 0 : 1
2626

27-
compartment_id = var.compartment_id
27+
compartment_id = local.compartment_id
2828

2929
display_name = var.ig_route_table_display_name
3030
vcn_id = local.vcn_id

docs/instructions.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ export KUBECONFIG=generated/kubeconfig
241241
*Ensure you install the same kubectl version as the OKE Kubernetes version for compatibility.*
242242
****
243243

244+
****
245+
*To refresh the generated kubeconfig, run `terraform apply` with `update_kubeconfig: true`.*
246+
****
247+
244248
== Creating a Secret for OCIR
245249

246250
{uri-oci-ocir}[Oracle Cloud Infrastructure Registry] is a highly available private container registry service for storing and sharing container images within the same regions as the OKE Cluster. Use the following rules to determine if you need to create a Kubernetes Secret for OCIR:

docs/terraformoptions.adoc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
:uri-kubernetes-vpa: https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler
1717
:uri-metrics-server: https://github.com/kubernetes-incubator/metrics-server
1818
:uri-openpolicyagent-gatekeeper: https://open-policy-agent.github.io/gatekeeper/website/docs/
19+
:uri-oci-content: https://docs.cloud.oracle.com/iaas/Content
1920
:uri-oci-images: https://docs.cloud.oracle.com/iaas/images/
20-
:uri-oci-kms: https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm
21+
:uri-oci-kms: {uri-oci-content}/KeyManagement/Concepts/keyoverview.htm
2122
:uri-oci-loadbalancer-annotations: https://github.com/oracle/oci-cloud-controller-manager/blob/master/docs/load-balancer-annotations.md
22-
:uri-oci-region: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm
23-
:uri-oci-tags: https://docs.oracle.com/en-us/iaas/Content/Tagging/Tasks/managingtagsandtagnamespaces.htm#workdefined
23+
:uri-oci-provider-config: {uri-oci-content}/API/SDKDocs/terraformproviderconfiguration.htm
24+
:uri-oci-region: {uri-oci-content}/General/Concepts/regions.htm
25+
:uri-oci-rm-config: {uri-oci-content}/ResourceManager/Concepts/terraformconfigresourcemanager.htm#configvar
26+
:uri-oci-tags: {uri-oci-content}/Tagging/Tasks/managingtagsandtagnamespaces.htm#workdefined
2427
:uri-terraform-cidrsubnet: https://www.terraform.io/docs/configuration/functions/cidrsubnet.html
2528
:uri-terraform-dependencies: {uri-docs}/dependencies.adoc
2629
:uri-timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
@@ -32,6 +35,8 @@ Ensure you review the {uri-terraform-dependencies}[dependencies].
3235

3336
== OCI Provider parameters
3437

38+
See {uri-oci-provider-config}[Terraform OCI Provider] or {uri-oci-rm-config}[Resource Manager] configuration.
39+
3540
[stripes=odd,cols="1m,4d,2m,2m", options=header,width="100%"]
3641
|===
3742
|Parameter
@@ -332,6 +337,11 @@ EOT
332337
|7.9
333338
|7.9
334339

340+
|`bastion_user`
341+
|The user for SSH access to the bastion host. Always 'opc' on supported images.
342+
|opc
343+
|opc
344+
335345
|bastion_shape
336346
|The shape of bastion instance. *Required*
337347
|
@@ -447,6 +457,11 @@ EOT
447457
|e.g. 7.9, 8
448458
|8
449459

460+
|`operator_user`
461+
|The user for SSH access to the operator host. Always 'opc' on supported images.
462+
|opc
463+
|opc
464+
450465
|`operator_shape`
451466
|The shape of operator instance. *Required*
452467
|

locals.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
locals {
5-
bastion_public_ip = var.create_bastion_host == true ? module.bastion[0].bastion_public_ip : ""
6-
operator_private_ip = var.create_operator == true ? module.operator[0].operator_private_ip : ""
5+
tenancy_id = coalesce(var.tenancy_id, var.tenancy_ocid)
6+
compartment_id = coalesce(
7+
var.compartment_id, var.compartment_ocid,
8+
var.tenancy_id, var.tenancy_ocid,
9+
)
10+
11+
bastion_public_ip = var.create_bastion_host == true ? module.bastion[0].bastion_public_ip : coalesce(var.bastion_public_ip, "")
12+
operator_private_ip = var.create_operator == true ? module.operator[0].operator_private_ip : coalesce(var.operator_private_ip, "")
713
operator_instance_principal_group_name = var.create_operator == true ? module.operator[0].operator_instance_principal_group_name : ""
814

915
vcn_id = var.create_vcn == true ? module.vcn[0].vcn_id : coalesce(var.vcn_id, try(data.oci_core_vcns.vcns[0].virtual_networks[0].id,""))
1016
ig_route_id = var.create_vcn == true ? module.vcn[0].ig_route_id : coalesce(var.ig_route_table_id, try(data.oci_core_route_tables.ig[0].route_tables[0].id,""))
1117
nat_route_id = var.create_vcn == true ? module.vcn[0].nat_route_id : coalesce(var.nat_route_table_id, try(data.oci_core_route_tables.nat[0].route_tables[0].id,""))
1218

19+
ssh_key_arg = var.ssh_private_key_path == "none" ? "" : " -i ${var.ssh_private_key_path}"
1320
validate_drg_input = var.create_drg && (var.drg_id != null) ? tobool("[ERROR]: create_drg variable can not be true if drg_id is provided.]") : true
1421
}

main.tf

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module "vcn" {
66
version = "3.5.1"
77

88
# general oci parameters
9-
compartment_id = var.compartment_id
9+
compartment_id = local.compartment_id
1010
label_prefix = var.label_prefix
1111

1212
# gateways
@@ -35,12 +35,11 @@ module "vcn" {
3535
}
3636

3737
module "drg" {
38-
3938
source = "oracle-terraform-modules/drg/oci"
4039
version = "1.0.3"
4140

4241
# general oci parameters
43-
compartment_id = var.compartment_id
42+
compartment_id = local.compartment_id
4443
label_prefix = var.label_prefix
4544

4645
# drg parameters
@@ -60,10 +59,10 @@ module "drg" {
6059

6160
module "bastion" {
6261
source = "oracle-terraform-modules/bastion/oci"
63-
version = "3.1.1"
62+
version = "3.1.2"
6463

65-
tenancy_id = var.tenancy_id
66-
compartment_id = var.compartment_id
64+
tenancy_id = local.tenancy_id
65+
compartment_id = local.compartment_id
6766

6867
label_prefix = var.label_prefix
6968

@@ -109,12 +108,12 @@ module "bastion" {
109108

110109
module "operator" {
111110
source = "oracle-terraform-modules/operator/oci"
112-
version = "3.1.0"
111+
version = "3.1.1"
113112

114-
tenancy_id = var.tenancy_id
115113

116114
# general oci parameters
117-
compartment_id = var.compartment_id
115+
tenancy_id = local.tenancy_id
116+
compartment_id = local.compartment_id
118117
label_prefix = var.label_prefix
119118

120119
# networking
@@ -162,7 +161,7 @@ module "bastionsvc" {
162161
source = "./modules/bastionsvc"
163162

164163
# general oci parameters
165-
compartment_id = var.compartment_id
164+
compartment_id = local.compartment_id
166165
label_prefix = var.label_prefix
167166

168167
# bastion service parameters
@@ -184,7 +183,7 @@ module "network" {
184183
source = "./modules/network"
185184

186185
# general oci parameters
187-
compartment_id = var.compartment_id
186+
compartment_id = local.compartment_id
188187
label_prefix = var.label_prefix
189188

190189
# oke networking parameters
@@ -233,10 +232,10 @@ module "oke" {
233232
source = "./modules/oke"
234233

235234
# provider
236-
tenancy_id = var.tenancy_id
235+
tenancy_id = local.tenancy_id
237236

238237
# general oci parameters
239-
compartment_id = var.compartment_id
238+
compartment_id = local.compartment_id
240239
label_prefix = var.label_prefix
241240

242241
# ssh keys
@@ -301,8 +300,8 @@ module "storage" {
301300
source = "./modules/storage"
302301

303302
# general oci parameters
304-
tenancy_id = var.tenancy_id
305-
compartment_id = var.compartment_id
303+
tenancy_id = local.tenancy_id
304+
compartment_id = local.compartment_id
306305
availability_domain = var.availability_domains["fss"]
307306
label_prefix = var.label_prefix
308307

@@ -330,10 +329,10 @@ module "extensions" {
330329
source = "./modules/extensions"
331330

332331
# provider
333-
tenancy_id = var.tenancy_id
332+
tenancy_id = local.tenancy_id
334333

335334
# general oci parameters
336-
compartment_id = var.compartment_id
335+
compartment_id = local.compartment_id
337336
label_prefix = var.label_prefix
338337

339338
# region parameters
@@ -348,11 +347,13 @@ module "extensions" {
348347
# bastion
349348
create_bastion_host = var.create_bastion_host
350349
bastion_public_ip = local.bastion_public_ip
350+
bastion_user = var.bastion_user
351351
bastion_state = var.bastion_state
352352

353353
# operator details
354354
create_operator = var.create_operator
355355
operator_private_ip = local.operator_private_ip
356+
operator_user = var.operator_user
356357
operator_state = var.operator_state
357358
operator_dynamic_group = local.operator_instance_principal_group_name
358359
enable_operator_instance_principal = var.enable_operator_instance_principal
@@ -400,7 +401,8 @@ module "extensions" {
400401
nodepool_upgrade_method = var.nodepool_upgrade_method
401402
node_pools_to_drain = var.node_pools_to_drain
402403

403-
debug_mode = var.debug_mode
404+
debug_mode = var.debug_mode
405+
update_kubeconfig = var.update_kubeconfig
404406

405407
depends_on = [
406408
module.bastion,

modules/extensions/activeworker.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ resource "null_resource" "check_worker_active" {
1111
private_key = local.ssh_private_key
1212
timeout = "40m"
1313
type = "ssh"
14-
user = "opc"
14+
user = var.operator_user
1515

1616
bastion_host = var.bastion_public_ip
17-
bastion_user = "opc"
17+
bastion_user = var.bastion_user
1818
bastion_private_key = local.ssh_private_key
1919
}
2020

modules/extensions/calico.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ resource "null_resource" "install_calico" {
77
private_key = local.ssh_private_key
88
timeout = "40m"
99
type = "ssh"
10-
user = "opc"
10+
user = var.operator_user
1111

1212
bastion_host = var.bastion_public_ip
13-
bastion_user = "opc"
13+
bastion_user = var.bastion_user
1414
bastion_private_key = local.ssh_private_key
1515
}
1616

modules/extensions/drain.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ resource "null_resource" "drain_nodes" {
77
private_key = local.ssh_private_key
88
timeout = "40m"
99
type = "ssh"
10-
user = "opc"
10+
user = var.operator_user
1111

1212
bastion_host = var.bastion_public_ip
13-
bastion_user = "opc"
13+
bastion_user = var.bastion_user
1414
bastion_private_key = local.ssh_private_key
1515
}
1616

modules/extensions/gatekeeper.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ resource "null_resource" "enable_gatekeeper" {
77
private_key = local.ssh_private_key
88
timeout = "40m"
99
type = "ssh"
10-
user = "opc"
10+
user = var.operator_user
1111

1212
bastion_host = var.bastion_public_ip
13-
bastion_user = "opc"
13+
bastion_user = var.bastion_user
1414
bastion_private_key = local.ssh_private_key
1515
}
1616

modules/extensions/iam.tf

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,39 @@ terraform {
1414
}
1515

1616
locals {
17-
create_operator_instance_principal_dynamic_group = (var.use_cluster_encryption == true && var.create_policies == true && var.create_bastion_host == true && var.enable_operator_instance_principal == true)
17+
create_operator_dynamic_group_policy = (var.use_cluster_encryption == true && var.create_policies == true && var.create_bastion_host == true && var.enable_operator_instance_principal == true)
1818
}
1919

20-
resource "oci_identity_policy" "operator_instance_principal_dynamic_group" {
20+
resource "random_id" "dynamic_group_suffix" {
21+
keepers = {
22+
# Generate a new suffix only when variables are changed
23+
label_prefix = local.dynamic_group_prefix
24+
tenancy_id = var.tenancy_id
25+
}
26+
27+
byte_length = 8
28+
}
29+
30+
# TODO Move to Operator module
31+
resource "oci_identity_policy" "operator_use_dynamic_group_policy" {
2132
provider = oci.home
22-
compartment_id = var.tenancy_id
33+
compartment_id = random_id.dynamic_group_suffix.keepers.tenancy_id
2334
description = "policy to allow operator host to manage dynamic group"
24-
name = var.label_prefix == "none" ? "operator-instance-principal-dynamic-group-${substr(uuid(), 0, 8)}" : "${var.label_prefix}-operator-instance-principal-dynamic-group-${substr(uuid(), 0, 8)}"
35+
name = join("-", compact([
36+
random_id.dynamic_group_suffix.keepers.label_prefix,
37+
"operator-instance-principal-dynamic-group",
38+
random_id.dynamic_group_suffix.hex
39+
]))
2540
statements = ["Allow dynamic-group ${var.operator_dynamic_group} to use dynamic-groups in tenancy"]
26-
count = (local.create_operator_instance_principal_dynamic_group == true) ? 1 : 0
41+
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
2742
}
2843

2944
# 30s delay to allow policies to take effect globally
3045
resource "time_sleep" "wait_30_seconds" {
31-
depends_on = [oci_identity_policy.operator_instance_principal_dynamic_group]
46+
depends_on = [oci_identity_policy.operator_use_dynamic_group_policy]
3247

3348
create_duration = "30s"
34-
count = (local.create_operator_instance_principal_dynamic_group == true) ? 1 : 0
49+
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
3550
}
3651

3752
resource "null_resource" "update_dynamic_group" {
@@ -41,10 +56,10 @@ resource "null_resource" "update_dynamic_group" {
4156
private_key = local.ssh_private_key
4257
timeout = "40m"
4358
type = "ssh"
44-
user = "opc"
59+
user = var.operator_user
4560

4661
bastion_host = var.bastion_public_ip
47-
bastion_user = "opc"
62+
bastion_user = var.bastion_user
4863
bastion_private_key = local.ssh_private_key
4964
}
5065

@@ -61,5 +76,5 @@ resource "null_resource" "update_dynamic_group" {
6176
]
6277
}
6378

64-
count = (local.create_operator_instance_principal_dynamic_group && var.bastion_state == "RUNNING" ) ? 1 : 0
79+
count = (local.create_operator_dynamic_group_policy && var.bastion_state == "RUNNING" ) ? 1 : 0
6580
}

0 commit comments

Comments
 (0)