Skip to content

Commit 8d36924

Browse files
committed
Added unique key to avoid naming conflicts
1 parent ab35cb0 commit 8d36924

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

MtdrSpring/terraform/containerengine.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource "oci_containerengine_cluster" "mtdrworkshop_cluster" {
99
subnet_id = oci_core_subnet.endpoint.id
1010
}
1111
kubernetes_version = "v1.25.4"
12-
name = "mtdrworkshopcluster"
12+
name = "mtdrworkshopcluster-${var.mtdrKey}"
1313
vcn_id = oci_core_vcn.okevcn.id
1414
#optional
1515

MtdrSpring/terraform/core.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resource "oci_core_vcn" "okevcn" {
33
cidr_block = "10.0.0.0/16"
44
compartment_id = var.ociCompartmentOcid
5-
display_name = "mtdrworkshop"
5+
display_name = "mtdrworkshop-${var.mtdrKey}"
66
dns_label = "mtdrworkshop"
77
}
88
resource "oci_core_internet_gateway" "igw" {

MtdrSpring/terraform/main-var.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ variable "ociUserOcid" {}
55
variable "ociCompartmentOcid" {}
66
variable "ociRegionIdentifier" {}
77
variable "mtdrDbName" {}
8-
variable "runName" {}
8+
variable "runName" {}
9+
10+
# mtdrKey is a unique generated id
11+
variable "mtdrKey" {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "oci_artifacts_container_repository" todolist {
22
#Required
33
compartment_id = var.ociCompartmentOcid
4-
display_name = "${var.runName}/todolistapp-springboot"
4+
display_name = "${var.runName}/${var.mtdrKey}/todolistapp-springboot"
55
is_public = true
66
}

MtdrSpring/utils/main-setup.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ while ! state_done USER_NAME; do
6767
state_set USER_NAME "$USER_NAME"
6868
done
6969

70+
# Generate Unique Key
71+
while ! state_done MTDR_KEY; do
72+
state_set MTDR_KEY $(python "$MTDRWORKSHOP_LOCATION/utils/python-scripts/generate-unique-key.py")
73+
done
74+
7075

7176
#Get Run Name from directory name
7277
while ! state_done RUN_NAME; do
@@ -178,7 +183,7 @@ while ! state_done DOCKER_REGISTRY; do
178183
while test $RETRIES -le 30; do
179184
if echo "$TOKEN" | docker login -u "$(state_get NAMESPACE)/$(state_get USER_NAME)" --password-stdin "$(state_get REGION).ocir.io" &>/dev/null; then
180185
echo "Docker login completed"
181-
state_set DOCKER_REGISTRY "$(state_get REGION).ocir.io/$(state_get NAMESPACE)/$(state_get RUN_NAME)"
186+
state_set DOCKER_REGISTRY "$(state_get REGION).ocir.io/$(state_get NAMESPACE)/$(state_get RUN_NAME)/$(state_get MTDR_KEY)"
182187
export OCI_CLI_PROFILE=$(state_get REGION)
183188
break
184189
else
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import random
2+
import string
3+
4+
def get_random_key(length):
5+
letters = string.ascii_lowercase
6+
digits = string.digits
7+
length = length
8+
result_str = ''.join(random.choice(letters + digits) for i in range(length))
9+
print(result_str)
10+
11+
get_random_key(5)

MtdrSpring/utils/terraform.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if ! state_done PROVISIONING; then
1414
export TF_VAR_ociRegionIdentifier="$(state_get REGION)"
1515
export TF_VAR_runName="$(state_get RUN_NAME)"
1616
export TF_VAR_mtdrDbName="$(state_get MTDR_DB_NAME)"
17+
export TF_VAR_mtdrKey="$(state_get MTDR_KEY)"
1718
#export TF_VAR_inventoryDbName="$(state_get INVENTORY_DB_NAME)"
1819

1920
if state_done K8S_PROVISIONING; then

0 commit comments

Comments
 (0)