Skip to content

Commit

Permalink
working with local setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicain committed Jun 21, 2023
1 parent cfa6011 commit c127eca
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 124 deletions.
8 changes: 0 additions & 8 deletions config.env

This file was deleted.

26 changes: 9 additions & 17 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@
# limitations under the License.
set -e

if [ -z "$(git status --porcelain)" ]; then
REVISION="$(git rev-parse --short HEAD)"
else
echo "Git repo is dirty, continuing anyway..."
REVISION="DIRTY_REPO"
# echo "Git repo is dirty, cancelling deployment..."
# exit 1
fi

source config.env
export PROJECT_ID="velociraptor-16p1-test-0"
export TF_PLAN_STORAGE_BUCKET="${PROJECT_ID?}-tf"
export BUCKET_NAME=${TF_PLAN_STORAGE_BUCKET?}-main
export TERRAFORM_IMAGE="hashicorp/terraform:1.4.6"
export PREFIX="terraform/${PROJECT_ID?}"

DESTROY=
while (( ${#} > 0 )); do
Expand All @@ -37,12 +32,12 @@ while (( ${#} > 0 )); do
done

gcloud config set project "${PROJECT_ID?}"
gcloud --quiet auth login "${PRINCIPAL?}" --no-launch-browser
gcloud --quiet auth login "$(whoami)@google.com" --no-launch-browser
gcloud services enable cloudresourcemanager.googleapis.com

sudo docker run \
-w /app \
-v "$(pwd)"/terraform:/app \
-v "$(pwd)":/app \
"${TERRAFORM_IMAGE?}" \
init \
-upgrade \
Expand All @@ -53,14 +48,11 @@ sudo docker run \

sudo docker run \
-w /app \
-v "$(pwd)"/terraform:/app \
-v "$(pwd)":/app \
-e GOOGLE_OAUTH_ACCESS_TOKEN="$(gcloud auth print-access-token)" \
"${TERRAFORM_IMAGE?}" \
apply \
--auto-approve \
-var project_id="${PROJECT_ID?}" \
-var region="${REGION?}" \
-var bucket="${BUCKET?}" \
-var principal="${PRINCIPAL?}" \
-var revision="${REVISION?}" \
-var bucket_name="${BUCKET_NAME?}" \
"${DESTROY?}"
25 changes: 0 additions & 25 deletions examples/simple_example/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions examples/simple_example/main.tf

This file was deleted.

36 changes: 25 additions & 11 deletions terraform/main.tf → main.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

data "google_project" "project" {
project_id = var.project_id
}

terraform {
backend "gcs" {
bucket = null
prefix = null
}
}

resource "google_project_service" "serviceusage" {
service = "serviceusage.googleapis.com"
project = var.project_id
Expand Down Expand Up @@ -120,7 +129,7 @@ data "archive_file" "webhook" {

resource "google_storage_bucket_object" "webhook" {
name = "${var.webhook_name}.${data.archive_file.webhook.output_base64sha256}.zip"
bucket = var.bucket
bucket = google_storage_bucket.main.name
source = data.archive_file.webhook.output_path
}

Expand Down Expand Up @@ -188,7 +197,7 @@ resource "google_cloudfunctions2_function" "webhook" {
entry_point = "entrypoint"
source {
storage_source {
bucket = var.bucket
bucket = var.bucket_name
object = google_storage_bucket_object.webhook.name
}
}
Expand All @@ -204,9 +213,7 @@ resource "google_cloudfunctions2_function" "webhook" {
timeout_seconds = var.timeout_seconds
environment_variables = {
PROJECT_ID = var.project_id
PRINCIPAL = var.principal
LOCATION = var.region
REVISION = var.revision
OUTPUT_BUCKET = google_storage_bucket.output.name
DATASET_ID = google_bigquery_dataset.default.dataset_id
TABLE_ID = google_bigquery_table.default.table_id
Expand Down Expand Up @@ -287,6 +294,13 @@ resource "google_storage_bucket" "output" {
uniform_bucket_level_access = true
}

resource "google_storage_bucket" "main" {
project = var.project_id
name = var.bucket_name
location = "US"
uniform_bucket_level_access = true
}

resource "google_service_account" "upload_trigger" {
project = var.project_id
account_id = "upload-trigger-service-account"
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_example/outputs.tf → outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/

output "bucket_name" {
description = "The name of the bucket."
value = module.gen_ai_document_summarization.bucket_name
description = "Name of the bucket"
value = google_storage_bucket.main.name
}
35 changes: 0 additions & 35 deletions terraform/variables.tf

This file was deleted.

24 changes: 22 additions & 2 deletions examples/simple_example/variables.tf → variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@
*/

variable "project_id" {
description = "The ID of the project in which to provision resources."
description = "The project ID to deploy to"
type = string
}

variable "bucket_name" {
description = "The name of the bucket to create."
description = "The name of the bucket to create"
type = string
}

variable "region" {
type = string
default = "us-central1"
}

variable "webhook_name" {
type = string
default = "webhook"
}

variable "timeout_seconds" {
type = number
default = 900
}

variable "zone" {
default = "us-central1-a"
type = string
}
13 changes: 11 additions & 2 deletions examples/simple_example/versions.tf → versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
*/

terraform {
required_version = ">= 0.13"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.0"
version = ">= 3.53, < 5.0"
}
}
required_version = ">= 0.13"

provider_meta "google" {
module_name = "blueprints/terraform/gen-ai-document-summarization/v0.0.1"
}

backend "gcs" {
bucket = null
prefix = null
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c127eca

Please sign in to comment.