Skip to content

Commit

Permalink
Use random_pet to create unique names for the VPC, EKS and S3 bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
eldada committed Jan 30, 2025
1 parent 2cc41ec commit e64954b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is used to create an AWS EKS cluster and the managed node group(s)

locals {
cluster_name = var.cluster_name
cluster_name = "${var.cluster_name}-${random_pet.unique_name.id}"
}

resource "aws_security_group_rule" "allow_management_from_my_ip" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ provider "kubernetes" {
# Fetch the JFrog Platform Helm chart and untar it to the current directory so we can use the sizing files to create the final values files
resource "null_resource" "fetch_platform_chart" {
provisioner "local-exec" {
command = "rm -rf xray-*.tgz"
command = "rm -rf jfrog-platform-*.tgz"
}
provisioner "local-exec" {
command = "helm fetch jfrog-platform --version ${var.jfrog_platform_chart_version} --repo https://charts.jfrog.io --untar"
Expand Down Expand Up @@ -98,7 +98,7 @@ resource "local_file" "jfrog_platform_values" {
maxCacheSize: "${local.cache-fs-size}000000000"
awsS3V3:
region: "${var.region}"
bucketName: "artifactory-${var.region}-${var.s3_bucket_name_suffix}"
bucketName: "${local.artifactory_s3_bucket_name}"
database:
url: "jdbc:postgresql://${aws_db_instance.artifactory_db.endpoint}/${var.artifactory_db_name}?sslmode=require"
Expand Down
6 changes: 5 additions & 1 deletion examples/terraform-examples/jfrog-platform-aws-install/s3.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# This file is used to create an S3 bucket for Artifactory to store binaries

locals {
artifactory_s3_bucket_name = "artifactory-${var.region}-${var.s3_bucket_name_suffix}-${random_pet.unique_name.id}"
}

resource "aws_s3_bucket" "artifactory_binarystore" {
bucket = "artifactory-${var.region}-${var.s3_bucket_name_suffix}"
bucket = local.artifactory_s3_bucket_name

# WARNING: This will force the bucket to be destroyed even if it's not empty
force_destroy = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ variable "xray_db_password" {
}

variable "cluster_name" {
default = "jfrog-eks-cluster"
default = "jfrog"
}

variable "namespace" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ data "aws_availability_zones" "available" {
}
}

resource "random_pet" "unique_name" {
keepers = {
# Generate a new pet name each time we switch to a new region
string = var.region
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"

name = "jfrog-vpc-${random_pet.unique.id}"
name = "jfrog-vpc-${random_pet.unique_name.id}"

cidr = var.vpc_cidr
azs = slice(data.aws_availability_zones.available.names, 0, 3)
Expand Down

0 comments on commit e64954b

Please sign in to comment.