diff --git a/admin-service/cloud/gcpcloudfunction/googlecloud.iml b/admin-service/cloud/gcpcloudfunction/googlecloud.iml new file mode 100644 index 00000000..8abcfa93 --- /dev/null +++ b/admin-service/cloud/gcpcloudfunction/googlecloud.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/cloud-function/gcpcloudfunction/README.md b/cloud-function/gcpcarfunction/README.md similarity index 97% rename from cloud-function/gcpcloudfunction/README.md rename to cloud-function/gcpcarfunction/README.md index be713e54..10ae79f0 100644 --- a/cloud-function/gcpcloudfunction/README.md +++ b/cloud-function/gcpcarfunction/README.md @@ -32,7 +32,7 @@ To utilize this project, follow the steps below + Deploy the cloud function to Google Cloud Platform. + Open the console and navigate to the project directory.Run the following command to deploy the cloud function. - gcloud alpha functions deploy cloud_function --entry-point pubsub.PubSubDataHandler --runtime java17 --trigger-topic topic_name + gcloud alpha functions deploy cloud_function --entry-point com.knoldus.cloudfunction.PubSubDataHandler --runtime java17 --trigger-topic topic_name ### Publishing a Message to the Topic After deploying the cloud function, publish a message to the configured topic. diff --git a/cloud-function/gcpcarfunction/gcpcarfunction.iml b/cloud-function/gcpcarfunction/gcpcarfunction.iml new file mode 100644 index 00000000..927cde0e --- /dev/null +++ b/cloud-function/gcpcarfunction/gcpcarfunction.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/cloud-function/gcpcarfunction/gcpfunction.iml b/cloud-function/gcpcarfunction/gcpfunction.iml new file mode 100644 index 00000000..b56bfd6d --- /dev/null +++ b/cloud-function/gcpcarfunction/gcpfunction.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/cloud-function/gcpcloudfunction/googlecloud.iml b/cloud-function/gcpcarfunction/googlecloud.iml similarity index 100% rename from cloud-function/gcpcloudfunction/googlecloud.iml rename to cloud-function/gcpcarfunction/googlecloud.iml diff --git a/cloud-function/gcpcloudfunction/pom.xml b/cloud-function/gcpcarfunction/pom.xml similarity index 98% rename from cloud-function/gcpcloudfunction/pom.xml rename to cloud-function/gcpcarfunction/pom.xml index 269bd0b6..7eb9f888 100644 --- a/cloud-function/gcpcloudfunction/pom.xml +++ b/cloud-function/gcpcarfunction/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.nashtech - gcpfunction + gcpcarfunction 1.0 diff --git a/cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/PubSubDataHandler.java b/cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/PubSubDataHandler.java similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/PubSubDataHandler.java rename to cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/PubSubDataHandler.java diff --git a/cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/model/Vehicle.java b/cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/model/Vehicle.java similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/model/Vehicle.java rename to cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/model/Vehicle.java diff --git a/cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/model/package-info.java b/cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/model/package-info.java similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/model/package-info.java rename to cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/model/package-info.java diff --git a/cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/package-info.java b/cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/package-info.java similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/java/com/knoldus/cloudfunction/package-info.java rename to cloud-function/gcpcarfunction/src/main/java/com/knoldus/cloudfunction/package-info.java diff --git a/cloud-function/gcpcloudfunction/src/main/resources/application.yml b/cloud-function/gcpcarfunction/src/main/resources/application.yml similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/resources/application.yml rename to cloud-function/gcpcarfunction/src/main/resources/application.yml diff --git a/cloud-function/gcpcloudfunction/src/main/resources/config.properties b/cloud-function/gcpcarfunction/src/main/resources/config.properties similarity index 100% rename from cloud-function/gcpcloudfunction/src/main/resources/config.properties rename to cloud-function/gcpcarfunction/src/main/resources/config.properties diff --git a/cloud-function/scripts/gcp-infra.sh b/cloud-function/scripts/outdated-gcp-infra.sh similarity index 93% rename from cloud-function/scripts/gcp-infra.sh rename to cloud-function/scripts/outdated-gcp-infra.sh index d50d1087..5c5af8cd 100644 --- a/cloud-function/scripts/gcp-infra.sh +++ b/cloud-function/scripts/outdated-gcp-infra.sh @@ -1,5 +1,5 @@ #!/bin/bash - +# this script is outdated please ref terraform deployment/gcpresources/terraform/main.tf # Set your GCP project ID and other variables PROJECT_ID="gcp-demo-project-399609" CLUSTER_NAME="cluster-gcp-deployment" diff --git a/deployment/gcpresources/terraform/main.tf b/deployment/gcpresources/terraform/main.tf index 4237f13b..a4916b5b 100644 --- a/deployment/gcpresources/terraform/main.tf +++ b/deployment/gcpresources/terraform/main.tf @@ -2,6 +2,7 @@ resource "random_id" "instance_id" { byte_length = 4 } + #----------------------------------------my-sql----------------------------- # create My SQL database instance resource "google_sql_database_instance" "my_sql" { @@ -132,17 +133,9 @@ resource "google_container_cluster" "car-demo-gke" { services_ipv4_cidr_block = "" } enable_autopilot = true - -} - -resource "null_resource" "external-secret-car-demo-gke" { - provisioner "local-exec" { - command = "/bin/bash external-secret-gcsm.sh car-demo-gke ${var.gcp_region_1}" - } - depends_on = [google_container_cluster.car-demo-gke] } -#-----------------------GKE Cluster for axon-server---------------------------- +#GKE Cluster for axon-server resource "google_container_cluster" "axon-server-gke" { name = "axon-server-gke" location = var.gcp_region_1 @@ -151,7 +144,13 @@ resource "google_container_cluster" "axon-server-gke" { services_ipv4_cidr_block = "" } enable_autopilot = true +} +resource "null_resource" "external-secret-car-demo-gke" { + provisioner "local-exec" { + command = "/bin/bash external-secret-gcsm.sh car-demo-gke ${var.gcp_region_1}" + } + depends_on = [google_container_cluster.car-demo-gke] } resource "null_resource" "axon-server-gke" { @@ -169,12 +168,66 @@ resource "google_project_service" "firestore" { resource "google_firestore_database" "database" { project = var.app_project - name = "(default)" + name = "car-db" location_id = var.gcp_region_1 type = "FIRESTORE_NATIVE" depends_on = [google_project_service.firestore] } +#------------------------- Cloud function---------------------- +resource "google_storage_bucket" "function_bucket" { + name = "${random_id.instance_id.hex}-gcf-source" # Every bucket name must be globally unique + location = var.gcp_region_1 + uniform_bucket_level_access = true +} + +data "archive_file" "source" { + type = "zip" + output_path = "/tmp/function-source.zip" + source_dir = "/home/knoldus/IdeaProjects/car-demo/cloud-function/gcpcarfunction" +} + +resource "google_storage_bucket_object" "zip" { + name = "function-source.zip" + bucket = google_storage_bucket.function_bucket.name + source = data.archive_file.source.output_path # Add path to the zipped function source code + content_type = "application/zip" +} + +resource "google_cloudfunctions2_function" "function-v2" { + name = "car_cloud_function" + location = var.gcp_region_1 + + event_trigger { + trigger_region = var.gcp_region_1 + event_type = "google.cloud.pubsub.topic.v1.messagePublished" + pubsub_topic = google_pubsub_topic.vehicle.id + retry_policy = "RETRY_POLICY_RETRY" + } + + build_config { + runtime = "java17" + entry_point = "com.knoldus.cloudfunction.PubSubDataHandler" # Set the entry point + source { + storage_source { + bucket = google_storage_bucket.function_bucket.name + object = google_storage_bucket_object.zip.name + } + } + } + + service_config { + max_instance_count = 1 + available_memory = "256M" + timeout_seconds = 60 + } + + depends_on = [ + google_storage_bucket.function_bucket, # declared in `storage.tf` + google_storage_bucket_object.zip + ] +} + #------------------------- secret manger---------------------- resource "google_secret_manager_secret" "car-demo-secret" { secret_id = "car-demo-secret"