Skip to content

Commit 3a407d5

Browse files
authored
secret changes and added variable validation (#374)
* variable validation,secret change * updated variables with default values
1 parent 1856b36 commit 3a407d5

File tree

5 files changed

+53
-64
lines changed

5 files changed

+53
-64
lines changed

modules/extensions/locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ locals {
8080
}
8181
)
8282

83-
secret_template = templatefile("${path.module}/scripts/secret.py",
83+
secret_template = templatefile("${path.module}/scripts/secret.sh",
8484
{
8585
compartment_id = var.compartment_id
8686
region = var.region

modules/extensions/scripts/secret.py

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Copyright 2017, 2020, Oracle Corporation and/or affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
4+
5+
cat <<EOF | kubectl apply -f -
6+
apiVersion: v1
7+
kind: Namespace
8+
metadata:
9+
name: ${secret_namespace}
10+
EOF
11+
12+
crtsecret=$(kubectl create secret docker-registry ${secret_name} -n ${secret_namespace} --docker-server=${region_registry} --docker-username=${tenancy_namespace}/${username} --docker-email=${email_address} --docker-password=`oci secrets secret-bundle get --raw-output --secret-id ${secret_id} --query "data.\"secret-bundle-content\".content" | base64 -d` --dry-run=client -o yaml | kubectl apply -f -)

modules/extensions/secrets.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
resource "null_resource" "secret" {
55
triggers = {
6-
secret_id = var.secret_id
6+
always_run = "${timestamp()}"
77
}
88
connection {
99
host = var.operator_private_ip
@@ -21,15 +21,15 @@ resource "null_resource" "secret" {
2121

2222
provisioner "file" {
2323
content = local.secret_template
24-
destination = "~/secret.py"
24+
destination = "~/secret.sh"
2525
}
2626

2727
provisioner "remote-exec" {
2828
inline = [
29-
"chmod +x $HOME/secret.py",
30-
"$HOME/secret.py",
29+
"chmod +x $HOME/secret.sh",
30+
"$HOME/secret.sh",
3131
"sleep 10",
32-
"rm -f $HOME/secret.py"
32+
"rm -f $HOME/secret.sh"
3333
]
3434
}
3535

variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ variable "bastion_state" {
196196
description = "The target state for the bastion instance. Could be set to RUNNING or STOPPED. (Updatable)"
197197
default = "RUNNING"
198198
type = string
199+
validation {
200+
condition = contains(["RUNNING", "STOPPED"], var.bastion_state)
201+
error_message = "Accepted values are RUNNING or STOPPED."
202+
}
199203
}
200204

201205
variable "bastion_timezone" {
@@ -208,6 +212,11 @@ variable "bastion_type" {
208212
description = "Whether to make the bastion host public or private."
209213
default = "public"
210214
type = string
215+
216+
validation {
217+
condition = contains(["public", "private"], var.bastion_type)
218+
error_message = "Accepted values are public or private."
219+
}
211220
}
212221

213222
variable "upgrade_bastion" {
@@ -313,6 +322,11 @@ variable "operator_state" {
313322
description = "The target state for the operator instance. Could be set to RUNNING or STOPPED. (Updatable)"
314323
default = "RUNNING"
315324
type = string
325+
validation {
326+
condition = contains(["RUNNING", "STOPPED"], var.operator_state)
327+
error_message = "Accepted values are RUNNING or STOPPED."
328+
}
329+
316330
}
317331

318332
variable "operator_timezone" {
@@ -399,6 +413,11 @@ variable "control_plane_access" {
399413
default = "public"
400414
description = "Whether to allow public or private access to the control plane endpoint"
401415
type = string
416+
417+
validation {
418+
condition = contains(["public", "private"], var.control_plane_access)
419+
error_message = "Accepted values are public, or private."
420+
}
402421
}
403422

404423
variable "control_plane_access_source" {
@@ -469,6 +488,10 @@ variable "check_node_active" {
469488
description = "check worker node is active"
470489
type = string
471490
default = "none"
491+
validation {
492+
condition = contains(["none", "one", "all"], var.check_node_active)
493+
error_message = "Accepted values are none, one or all."
494+
}
472495
}
473496

474497
variable "node_pools" {
@@ -509,6 +532,10 @@ variable "worker_mode" {
509532
default = "private"
510533
description = "Whether to provision public or private workers."
511534
type = string
535+
validation {
536+
condition = contains(["public", "private"], var.worker_mode)
537+
error_message = "Accepted values are public or private."
538+
}
512539
}
513540

514541
# upgrade of existing node pools
@@ -537,6 +564,10 @@ variable "lb_subnet_type" {
537564
default = "public"
538565
description = "The type of load balancer subnets to create."
539566
type = string
567+
validation {
568+
condition = contains(["public", "internal", "both"], var.lb_subnet_type)
569+
error_message = "Accepted values are public, internal or both."
570+
}
540571
}
541572

542573
variable "preferred_lb_subnet_type" {
@@ -545,6 +576,10 @@ variable "preferred_lb_subnet_type" {
545576
default = "public"
546577
description = "The preferred load balancer subnets that OKE will automatically choose when creating a load balancer. valid values are public or internal. if 'public' is chosen, the value for lb_subnet_type must be either 'public' or 'both'. If 'private' is chosen, the value for lb_subnet_type must be either 'internal' or 'both'."
547578
type = string
579+
validation {
580+
condition = contains(["public", "internal"], var.preferred_lb_subnet_type)
581+
error_message = "Accepted values are public or internal."
582+
}
548583
}
549584

550585
variable "public_lb_ports" {

0 commit comments

Comments
 (0)