-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initielt terraform-oppsett for bigquery
Co-authored-by: richardmartinsen <Richard.Martinsen@nav.no>
- Loading branch information
1 parent
c43311f
commit ae285a0
Showing
8 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: "Terraform - Big Query" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- bigquery/** | ||
- .github/workflows/deploy-bigquery.yaml | ||
|
||
env: | ||
DEV_DIR: './bigquery/dev' | ||
# PROD_DIR: './bigquery/prod' | ||
|
||
jobs: | ||
terraform-plan-dev: | ||
name: "terraform plan gcp-dev" | ||
runs-on: ubuntu-latest | ||
concurrency: terraform-plan-dev | ||
defaults: | ||
run: | ||
working-directory: ${{ env.DEV_DIR }} | ||
|
||
env: | ||
GOOGLE_CREDENTIALS: ${{ secrets.GCP_SECRET_DEV }} | ||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run 'terraform setup' | ||
uses: hashicorp/setup-terraform@v3 | ||
|
||
- name: Run 'terraform init' | ||
run: terraform init | ||
|
||
- name: Run 'terraform fmt' | ||
run: terraform fmt -check | ||
|
||
- name: Run 'terraform validate' | ||
run: terraform validate | ||
|
||
- name: Run 'terraform plan' | ||
run: terraform plan | ||
|
||
terraform-apply-dev: | ||
needs: terraform-plan-dev | ||
name: "terraform apply gcp-dev" | ||
runs-on: ubuntu-latest | ||
concurrency: terraform-plan-dev, terraform-apply-dev | ||
defaults: | ||
run: | ||
working-directory: ${{ env.DEV_DIR }} | ||
|
||
env: | ||
GOOGLE_CREDENTIALS: ${{ secrets.GCP_SECRET_DEV }} | ||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run 'terraform setup' | ||
uses: hashicorp/setup-terraform@v3 | ||
|
||
- name: Run 'terraform init' | ||
run: terraform init | ||
|
||
- name: Run 'terraform apply' | ||
run: terraform apply -auto-approve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
**/.env | ||
**/.terraform/* | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
*.key | ||
|
||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
**/.idea | ||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Terraform-oppsett for BigQuery | ||
|
||
## Servicebruker | ||
|
||
Oppsettet forutsetter at det finnes en servicebruker med tilgang til BigQuery. Dette kan opprettes i Google Cloud Console. | ||
|
||
Brukeren som er opprettet heter "tpts-terraform" og har rollene "BigQuery Data Owner", "Editor", "Secret Manager Sercret Accessor" | ||
|
||
Brukeren må finnes i både tpts-dev og tpts-prod. | ||
|
||
## Secrets | ||
|
||
Workflow for å kjøre opp terraform krever at det finnes en secret ved navn "GCP_SECRET_DEV" (og _PROD). Denne kan opprettes på servicebrukeren og legges inn i github som en repo secret. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "5.33.0" | ||
} | ||
} | ||
|
||
backend "gcs" { | ||
bucket = "tpts-bigquery-terraform-state-dev" | ||
} | ||
} | ||
|
||
provider "google" { | ||
project = var.gcp_project["project"] | ||
region = var.gcp_project["region"] | ||
} | ||
|
||
data "google_project" "project" {} | ||
|
||
module "google_storage_bucket" { | ||
source = "../modules/google-cloud-storage" | ||
|
||
name = "tpts-bigquery-terraform-state-dev" | ||
location = var.gcp_project["region"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
variable "gcp_project" { | ||
description = "GCP project and region defaults." | ||
type = map(string) | ||
default = { | ||
region = "europe-north1", | ||
zone = "europe-north1-a", | ||
project = "tpts-dev-6211" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "google_storage_bucket" "bucket" { | ||
name = var.name | ||
location = var.location | ||
storage_class = var.storage_class | ||
force_destroy = var.force_destroy | ||
|
||
versioning { | ||
enabled = var.versioning | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
variable "name" { | ||
description = "The name of the bucket." | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
description = "The bucket location." | ||
type = string | ||
} | ||
|
||
variable "storage_class" { | ||
description = "The bucket storage class." | ||
type = string | ||
default = "STANDARD" | ||
} | ||
|
||
variable "versioning" { | ||
description = "If the bucket content should be versioned or not." | ||
type = bool | ||
default = true | ||
} | ||
variable "force_destroy" { | ||
description = "If the bucket can be deleted if it contains content." | ||
type = bool | ||
default = false | ||
} |