Skip to content

Commit

Permalink
Merge pull request #6 from sr33hari/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
sr33hari authored Jul 11, 2024
2 parents e4451b8 + 7d0f060 commit 15aa142
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ cython_debug/
.terraform/
.DS_Store

set_google_env.sh
set_google_env.sh
terraform.tfvars
45 changes: 32 additions & 13 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions gcp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

eval "$(jq -r '@sh "PROJECT_ID=\(.project_id) REGION=\(.region) REPOSITORY_ID=\(.repository_id)"')"

repository=$(gcloud artifacts repositories describe $REPOSITORY_ID --location=$REGION --project=$PROJECT_ID --format=json)

if [[ $? -eq 0 ]]; then
jq -n --arg name "$REPOSITORY_ID" '{name:"'$REPOSITORY_ID'"}'
else
jq -n --arg name "" '{name:""}'
fi
18 changes: 12 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ provider "google-beta" {
region = var.region
}

data "google_artifact_registry_repository" "existing_repo" {
provider = google-beta
project = var.project_id
location = var.region
repository_id = var.repository_id
data "external" "get_artifact_registry_repo" {
program = ["bash", "gcp.sh"]
query = {
project_id = var.project_id
region = var.region
repository_id = var.repository_id
}
}

output "artifact_registry_repo" {
value = data.external.get_artifact_registry_repo.result.name
}

resource "google_artifact_registry_repository" "my_repo" {
Expand All @@ -25,7 +31,7 @@ resource "google_artifact_registry_repository" "my_repo" {
env = "main"
}

count = length(data.google_artifact_registry_repository.existing_repo.repository_id) == 0 ? 1 : 0
count = data.external.get_artifact_registry_repo.result.name == "" ? 1 : 0
}

resource "null_resource" "build_and_push_image" {
Expand Down
43 changes: 43 additions & 0 deletions terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": 4,
"terraform_version": "1.9.1",
"serial": 1,
"lineage": "fa60b86f-33f2-256f-c0db-9bcfe7642e0d",
"outputs": {
"artifact_registry_repo": {
"value": "",
"type": "string"
}
},
"resources": [
{
"mode": "data",
"type": "external",
"name": "get_artifact_registry_repo",
"provider": "provider[\"registry.terraform.io/hashicorp/external\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "-",
"program": [
"bash",
"gcp.sh"
],
"query": {
"project_id": "circle-429006",
"region": "us-west2",
"repository_id": "circle-artifacts"
},
"result": {
"name": ""
},
"working_dir": null
},
"sensitive_attributes": []
}
]
}
],
"check_results": null
}
7 changes: 0 additions & 7 deletions terraform.tfvars

This file was deleted.

5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
variable "project_id" {
description = "The ID of the Google Cloud project"
type = string
default = "circle-429006"
}

variable "region" {
description = "The region where resources will be deployed"
type = string
default = "us-west2"
}

variable "zone" {
description = "The zone where the Compute Engine instance will be deployed"
type = string
default = "us-west2-b"
}

variable "repository_id" {
description = "The ID of the Artifact Registry repository"
type = string
default = "circle-artifacts"
}

variable "service_account_email" {
description = "Email of the service account to be used"
type = string
default = "circle-service@circle-429006.iam.gserviceaccount.com"
}

variable "image_tag" {
Expand Down

0 comments on commit 15aa142

Please sign in to comment.