Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post dev-prod split #32

Merged
merged 188 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
2b5f6b2
getting a sketching related error that I won't worry about yet, servi…
GondekNP Jan 23, 2024
06e7535
re-org for clarity
GondekNP Jan 23, 2024
d5245b4
AOI draw for upload
GondekNP Jan 24, 2024
05471f7
upload form reorf
GondekNP Jan 24, 2024
e258755
upload elements for /upload-drawn-aoi
GondekNP Jan 24, 2024
d3bed42
Collect TODO comments
todo-actions[bot] Jan 24, 2024
18d9a38
Update TODO references: #13
todo-actions[bot] Jan 24, 2024
89179ef
long overdue linting and styling
GondekNP Jan 24, 2024
e89f5ca
issue todo
GondekNP Jan 24, 2024
57d1747
todo
GondekNP Jan 24, 2024
5322f10
Collect TODO comments
todo-actions[bot] Jan 24, 2024
c3bad61
Update TODO references: #14
todo-actions[bot] Jan 24, 2024
54a187e
set up derived boundary logic
GondekNP Jan 24, 2024
f067977
Collect TODO comments
todo-actions[bot] Jan 24, 2024
85b4839
Update TODO references: #15
todo-actions[bot] Jan 24, 2024
36db13b
go thru regular workflow to test boundaries in ui for derived bounds
GondekNP Jan 25, 2024
94388b9
go thru regular workflow to test boundaries in ui for derived bounds
GondekNP Jan 25, 2024
0358648
working derived burn boundary from approx polygon - need a little cle…
GondekNP Jan 25, 2024
a3e86fc
Collect TODO comments
todo-actions[bot] Jan 25, 2024
377b97e
Update TODO references: #16, #17, #18
todo-actions[bot] Jan 25, 2024
061c897
working to actually use the derived boundary for downstream EDIT, but…
GondekNP Jan 25, 2024
91f9f33
working upload with derived boundary
GondekNP Jan 25, 2024
3f52690
working with zip flow as well as AOI flow
GondekNP Jan 25, 2024
cb89bfa
convert to smart open and rebuild:
GondekNP Jan 25, 2024
c051c17
tofu changes to decommission SFTP for s3 backend service solely thru …
GondekNP Jan 26, 2024
8bfe24b
src changes to decommision sftp for s3 smart-open
GondekNP Jan 26, 2024
d858fca
going to rebuild with newer tofu build (officiaal stable release with…
GondekNP Jan 26, 2024
f490061
1.6.1 tofu from 1.5.9
GondekNP Jan 26, 2024
2b61212
auth with oidc for s3
GondekNP Jan 26, 2024
22f0a06
refactor for service account impersonation
GondekNP Jan 26, 2024
6b07f98
rename for clarity
GondekNP Jan 26, 2024
69a78fa
fix issues with quotes
GondekNP Jan 26, 2024
1de2975
woof - very confusing oidc string mapping from gcp to aws but hey we …
GondekNP Jan 29, 2024
c2de8db
some refactor likely needed - don't think my abstractions are ideal f…
GondekNP Jan 29, 2024
fdc7c5a
minor tweaks to manifest logic to reflect location of manifest json
GondekNP Jan 29, 2024
32b09a4
final cleanup pre-merge to close #9
GondekNP Jan 29, 2024
611d411
Merge pull request #19 from SchmidtDSE/sftp_to_smart_open
Jan 29, 2024
4da84fe
Collect TODO comments
todo-actions[bot] Jan 29, 2024
4ca0649
Update TODO references: #20, #21
todo-actions[bot] Jan 29, 2024
8cc956d
exploratory stuff and last incidental merge from sftp branch whoops
GondekNP Jan 30, 2024
ccb3b92
coords minimal for york
GondekNP Jan 30, 2024
5316edd
Collect TODO comments
todo-actions[bot] Jan 30, 2024
116e003
Update TODO references: #22
todo-actions[bot] Jan 30, 2024
4638c5e
export burn obs as geojson in exploratory - manually uploaded to york…
GondekNP Jan 30, 2024
accc922
todo
GondekNP Jan 30, 2024
eec15bb
add linters and stylers to devcontainer
GondekNP Jan 30, 2024
822ee35
rangeland analysis platform layer
GondekNP Jan 30, 2024
cf9a819
add Rangeland Analysis Platform as Tiff since it's surprisingly painl…
GondekNP Jan 31, 2024
f892e4e
big ol black rectangle for RAP but just need to scale
GondekNP Feb 1, 2024
7d690bb
refactor rangeland analysis platform upload to split by band - this i…
GondekNP Feb 2, 2024
553fa10
Collect TODO comments
todo-actions[bot] Feb 2, 2024
0db0231
Update TODO references: #23
todo-actions[bot] Feb 2, 2024
283f7cb
split rap and fixed float issue
GondekNP Feb 2, 2024
01e320d
todo
GondekNP Feb 2, 2024
b5e782f
build latest on cloud
GondekNP Feb 2, 2024
60bdc92
update iam creds logic for gcp side
GondekNP Feb 2, 2024
0b416e0
auth fix - need to call the gcp native fetch id token rather than my …
GondekNP Feb 2, 2024
76a51de
add s3 role arn to gcp env
GondekNP Feb 2, 2024
efce167
minor tweak to interpreted point
GondekNP Feb 2, 2024
e289dd4
add self reference endpoint to burn backend - a little smelly but wil…
GondekNP Feb 2, 2024
7af090f
Collect TODO comments
todo-actions[bot] Feb 2, 2024
58b2938
Update TODO references: #24
todo-actions[bot] Feb 2, 2024
29a8623
cleanup
GondekNP Feb 5, 2024
57b75ee
form validation for time windows
GondekNP Feb 5, 2024
181a920
oops add to existing event loop
GondekNP Feb 5, 2024
4111ca4
validation that shapefile has been uploaded OR aoi drawn
GondekNP Feb 5, 2024
8b56c7b
try out sentry - out-of-the-box fast api error tracking
GondekNP Feb 6, 2024
6cf1a42
deal with some mismatch in env var after OIDC setup, and pepper in so…
GondekNP Feb 6, 2024
fec7a51
properly set sentry context
GondekNP Feb 7, 2024
6992a47
show rap indicator from start
GondekNP Feb 7, 2024
21d93bd
remove smelly cloud cover arg
GondekNP Feb 7, 2024
162e9d1
remove from try except wrapper to allow sentry to do its thing and ad…
GondekNP Feb 7, 2024
8fdc373
fix a frontend bug and more directly handle errors from sentry (that …
GondekNP Feb 7, 2024
a558d88
Merge pull request #25 from SchmidtDSE/error_tracking
Feb 7, 2024
cd7b165
base sts vs https
GondekNP Feb 7, 2024
4fa281f
more explicitly raise on error
GondekNP Feb 7, 2024
1c4210d
No longer make Burn Metrics exclusive so that we can deselect for RAP
GondekNP Feb 7, 2024
bd8ff54
color ramp for RAP and an endpoint to list all derived products from …
GondekNP Feb 8, 2024
1126999
Collect TODO comments
todo-actions[bot] Feb 8, 2024
7d698c1
Update TODO references: #26
todo-actions[bot] Feb 8, 2024
0ad62ca
add derived burn products into a nice list, add links to interactive …
GondekNP Feb 8, 2024
6154fd6
better formatting and loader indicator
GondekNP Feb 8, 2024
b85b003
todo
GondekNP Feb 8, 2024
31b3a12
better title
GondekNP Feb 8, 2024
b861d8e
favicon and cleanup
GondekNP Feb 8, 2024
b3815c2
basic directory page
GondekNP Feb 8, 2024
4b6cd98
expected error but firing ajax correctly to display boundary
GondekNP Feb 8, 2024
50ebcdb
whoops copy paste id error
GondekNP Feb 8, 2024
c23489a
working display of all products, burn analysis information, and displ…
GondekNP Feb 8, 2024
713b4ff
cleanup of directory page and a small tweak to reflet new manifest logic
GondekNP Feb 8, 2024
d3f4d1e
test homepage from md
GondekNP Feb 8, 2024
e0f5ab6
basic homepage with streamlined proposal / basic explainer on 'what t…
GondekNP Feb 8, 2024
0b563ac
Dev notes and how to
GondekNP Feb 8, 2024
4af6906
mailto
GondekNP Feb 8, 2024
47a4018
make geology the eg
GondekNP Feb 8, 2024
49f6dcf
re-org to put app within src
GondekNP Feb 12, 2024
ff1aaa6
refactor debug and dependencies
GondekNP Feb 12, 2024
7a50f48
upload shapefile zip reorg
GondekNP Feb 12, 2024
78580a9
reorg for upload drawn aoi and shapefile
GondekNP Feb 12, 2024
716ad30
reorg for upload drawn aoi and shapefile
GondekNP Feb 12, 2024
636c8fd
rename for consistency and for easier re-use and testing
GondekNP Feb 12, 2024
4b41f8e
whoops missing pandas import
GondekNP Feb 12, 2024
b399df1
rename endpoints for consistency
GondekNP Feb 12, 2024
760d7df
explicit that init_sentry returns none
GondekNP Feb 12, 2024
638648e
list derived products and add descriptions to analyze and fetch endpo…
GondekNP Feb 12, 2024
c1dd4bf
pages reorg to suit
GondekNP Feb 12, 2024
264da63
finish converting api endpoints, plus a log_text rather than info for…
GondekNP Feb 12, 2024
f8bb864
dashes over underscore for endpoint rap
GondekNP Feb 12, 2024
027f3ad
Merge pull request #27 from SchmidtDSE/endpoint-refactor
Feb 13, 2024
5558c16
test assets from stac
GondekNP Feb 13, 2024
1bc6632
Collect TODO comments
todo-actions[bot] Feb 13, 2024
3a4ad8a
Update TODO references: #28
todo-actions[bot] Feb 13, 2024
153ec66
no longer need to explicitly copy app in dockerfile as it is included…
GondekNP Feb 13, 2024
22e1b69
merge
GondekNP Feb 13, 2024
534be43
conftest setup for stac items and valid/invalid rasters
GondekNP Feb 13, 2024
1284e94
boundaries samples and added pytest to dev container
GondekNP Feb 13, 2024
1280a6d
black format working again
GondekNP Feb 13, 2024
d28a106
tests running but something fishy with the demo tiffs I made... for s…
GondekNP Feb 13, 2024
7611bfb
replace wonky tiffs with more legit pkls of subset of imagery data
GondekNP Feb 13, 2024
756e2ae
working with proper pickling of xarrays
GondekNP Feb 13, 2024
6a4c0be
use prod dockerfile and run tests on PR
GondekNP Feb 13, 2024
c4a583f
whoops prod doesn't have pytest, duh
GondekNP Feb 13, 2024
1e6b928
install pytest in conda env then use it, also ignore the entrypoint d…
GondekNP Feb 13, 2024
af35e68
mocking and patching for upload_fire_event
GondekNP Feb 13, 2024
eabe1a3
add pytest to prod deployment - see if this fixes hang issue, as its …
GondekNP Feb 14, 2024
7266500
update conftest to be more generic for later tests (we don't really c…
GondekNP Feb 14, 2024
0b49da7
hopefully more verbose pytest prints
GondekNP Feb 14, 2024
16395bd
test upload cogs
GondekNP Feb 14, 2024
987e955
try mounting tests as a volume - really don't want to have a seperate…
GondekNP Feb 14, 2024
8cb4c5a
add \
GondekNP Feb 14, 2024
94cc67f
test upload_rap
GondekNP Feb 14, 2024
e1fa30c
try adding pytest ini using the docker cp command and committing it
GondekNP Feb 14, 2024
b392868
actions v4 to avoid node warnings
GondekNP Feb 14, 2024
873166e
test_update_manifest
GondekNP Feb 14, 2024
c164a46
use test fixture for upload fire event
GondekNP Feb 14, 2024
a18bd7f
complicated mocking for get_derived_products
GondekNP Feb 15, 2024
f11de33
initial sphinx docstrings
GondekNP Feb 15, 2024
e265593
add sphinx as dep in dev
GondekNP Feb 15, 2024
18a9fe4
try out sphinx
GondekNP Feb 15, 2024
f12907b
clean up docstrings
GondekNP Feb 15, 2024
b520bfb
make docs conform in burn_severity
GondekNP Feb 15, 2024
9f098d9
add sphinx commands to dev readme
GondekNP Feb 15, 2024
5ed0490
rap docstring
GondekNP Feb 15, 2024
79c2cf9
docstring query_sentinel
GondekNP Feb 15, 2024
bdfbc96
docs for query soil
GondekNP Feb 16, 2024
e00c9b8
document titiler algorithms
GondekNP Feb 16, 2024
a46e59a
document cloud static io
GondekNP Feb 16, 2024
984c735
document secrets
GondekNP Feb 16, 2024
2926e32
document ingest_buyrn_zip and raster_to_poly
GondekNP Feb 16, 2024
d998633
document routers spectral burn metrics
GondekNP Feb 16, 2024
06082f7
document checks
GondekNP Feb 16, 2024
ee17916
document ecocclass, rap, and derived products
GondekNP Feb 16, 2024
53580d6
note where fast api injects dependencies in docs
GondekNP Feb 16, 2024
9b50286
cleanup and sphinx
GondekNP Feb 16, 2024
586cef3
reorg
GondekNP Feb 20, 2024
0df8ba4
fixture for geojsons
GondekNP Feb 20, 2024
a9633d9
mock return from RAP - but need to properly isel window...
GondekNP Feb 20, 2024
221bea1
pickle only the metadata and coords - that way, dynamically reconstru…
GondekNP Feb 22, 2024
5ac35bf
closer on rap test - window still erroneously clioping out all valid …
GondekNP Feb 22, 2024
4807ed4
working - setting the return of mock_open to and then mocking specif…
GondekNP Feb 22, 2024
2c4e239
tests for getting mapunitidpoly from sdm - plus bugfix to backoff tha…
GondekNP Feb 23, 2024
12bc33f
simple tests for proper status code handling from EDIT, once we have …
GondekNP Feb 23, 2024
94e6968
rewrite query rap test - now using a small tif to emulate the behavio…
GondekNP Feb 23, 2024
de9b863
rewrite query rap test - now using a small tif to emulate the behavio…
GondekNP Feb 23, 2024
0e95abf
Merge branch 'tests' of https://github.com/SchmidtDSE/burn-severity-m…
GondekNP Feb 23, 2024
eb095c1
rename for new fixtures, add small test_rap_tif
GondekNP Feb 23, 2024
0abe344
test invalid rap year
GondekNP Feb 23, 2024
1bade91
test query sentinel
GondekNP Feb 26, 2024
b7a9693
test query_fire_event
GondekNP Feb 26, 2024
87a96a8
test query_fire_event
GondekNP Feb 26, 2024
23a4619
test_derive_boundary
GondekNP Feb 26, 2024
7ef78ab
disable arrange stack test - weird rio.reproject issue that seems to …
GondekNP Feb 26, 2024
6121ab5
Merge pull request #29 from SchmidtDSE/tests
GondekNP Feb 27, 2024
2a52e6c
Collect TODO comments
todo-actions[bot] Feb 27, 2024
2d0c5a0
Update TODO references: #30
todo-actions[bot] Feb 27, 2024
1016806
using tofu workspace, init a second environment , and add logic to pu…
GondekNP Feb 27, 2024
ec8c5be
temporarily push branch to dev cloud run for testing
GondekNP Feb 27, 2024
9973e9a
fix path to container registry
GondekNP Feb 27, 2024
912c9df
make a diff cloud build yaml for dev and prod
GondekNP Feb 27, 2024
53ebc25
add conditional for hardcoded-ish service account unique id. there mu…
GondekNP Feb 27, 2024
d39f6fe
egg on face - remove the dumb conditional and realize that the uuid a…
GondekNP Feb 27, 2024
e8d9f38
add bucket name (with dev/prod split) as a tofu output, such that we …
GondekNP Feb 28, 2024
5854059
add s3_bucket_name as tofu var for burn_backedn
GondekNP Feb 28, 2024
eb94bf1
change to throughout for consistency - fix tests to reflect
GondekNP Feb 28, 2024
d48b74d
one last change from to - in log
GondekNP Feb 28, 2024
6e89ea8
update access policy for s3_from_gcp role, to reflect new bucket name…
GondekNP Feb 28, 2024
20deadb
disable workflow for this branch
GondekNP Feb 28, 2024
abee263
Merge pull request #31 from SchmidtDSE/dev-prod-split
GondekNP Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .deployment/cloudbuild.yml

This file was deleted.

7 changes: 3 additions & 4 deletions .deployment/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ RUN apt-get update && apt-get install -y \
unzip \
curl \
ssh \
--no-install-recommends && rm -rf /var/lib/apt/lists/*
--no-install-recommends && rm -rf /var/lib/apt/lists/* && echo "apt-get install completed"

# Copy necessary files into container
COPY src/ /src/
COPY app.py /
COPY .deployment/prod_environment.yml /

# Create a new conda environment from the environment.yml file
RUN mamba env create -f prod_environment.yml
RUN mamba env create -f prod_environment.yml && echo "conda env create completed"

# Make 'RUN' use the new environment:
SHELL ["conda", "run", "-n", "burn-severity-prod", "/bin/bash", "-c"]
Expand All @@ -26,4 +25,4 @@ SHELL ["conda", "run", "-n", "burn-severity-prod", "/bin/bash", "-c"]
EXPOSE 8080

# Start the REST API w/ the new environment:
ENTRYPOINT ["conda", "run", "-n", "burn-severity-prod", "uvicorn", "app:app", "--host=0.0.0.0", "--port=8080"]
ENTRYPOINT ["conda", "run", "-n", "burn-severity-prod", "uvicorn", "src.app:app", "--host=0.0.0.0", "--port=8080"]
16 changes: 16 additions & 0 deletions .deployment/prod_cloudbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:
- name: "gcr.io/cloud-builders/docker"
args:
- "build"
- "--tag=us-central1-docker.pkg.dev/dse-nps/burn-backend-prod/prod:latest"
- "--file=.deployment/prod.Dockerfile"
- "--no-cache"
- "."

- name: "gcr.io/cloud-builders/docker"
args:
- "push"
- "us-central1-docker.pkg.dev/dse-nps/burn-backend-prod/prod:latest"

options:
logging: CLOUD_LOGGING_ONLY
10 changes: 7 additions & 3 deletions .deployment/prod_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ dependencies:
- ipython
- boto3
- pystac-client
- markdown
- planetary-computer
- fastapi <0.108.0 #to avoid AssertionError bug w/ titiler
- paramiko
- smart_open
- sentry-sdk[fastapi]
- uvicorn
- pytest
- pyarrow
- pip
- pip:
- titiler.core
- python-multipart
- titiler.core
- python-multipart
28 changes: 15 additions & 13 deletions .deployment/tofu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,31 @@ provider "google" {
}

data "google_project" "project" {}

# Get the one secret we need - ssh key
data "google_secret_manager_secret_version" "burn_sftp_ssh_keys" {
secret = "burn_sftp_ssh_keys"
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}

locals {
ssh_pairs = jsondecode(data.google_secret_manager_secret_version.burn_sftp_ssh_keys.secret_data)
google_project_number = data.google_project.project.number
aws_account_id = data.aws_caller_identity.current.account_id
aws_region = data.aws_region.current.name
# oidc_provider_domain_url = "https://accounts.google.com"
oidc_provider_domain_url = "accounts.google.com"
# gcp_cloud_run_client_id = "${terraform.workspace}" == "prod" ? "117526146749746854545" : "101023653831248304550"
}


# Initialize the modules
module "sftp" {
source = "./modules/sftp"
ssh_pairs = local.ssh_pairs
module "static_io" {
source = "./modules/static_io"
google_project_number = local.google_project_number
gcp_service_account_s3_email = module.burn_backend.gcp_service_account_s3_email
gcp_cloud_run_client_id = module.burn_backend.gcp_burn_backend_service_account_unique_id
aws_account_id = local.aws_account_id
oidc_provider_domain_url = local.oidc_provider_domain_url
}

module "burn_backend" {
source = "./modules/burn_backend"
ssh_pairs = local.ssh_pairs
google_project_number = local.google_project_number
sftp_server_endpoint = module.sftp.sftp_server_endpoint
sftp_admin_username = module.sftp.sftp_admin_username
s3_from_gcp_role_arn = module.static_io.s3_from_gcp_role_arn
s3_bucket_name = module.static_io.s3_bucket_name
}
50 changes: 32 additions & 18 deletions .deployment/tofu/modules/burn_backend/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Create a VPC access connector, to let the Cloud Run service access the AWS Transfer server
resource "google_vpc_access_connector" "burn_backend_vpc_connector" {
name = "vpc-burn2023" # just to match aws naming reqs
name = "vpc-burn2023-${terraform.workspace}" # just to match aws naming reqs
# network = google_compute_network.burn_backend_network.id
subnet {
name = google_compute_subnetwork.burn_backend_subnetwork.name
Expand All @@ -12,34 +12,34 @@ resource "google_vpc_access_connector" "burn_backend_vpc_connector" {
}

resource "google_compute_subnetwork" "burn_backend_subnetwork" {
name = "run-subnetwork"
name = "run-subnetwork-${terraform.workspace}"
ip_cidr_range = "10.2.0.0/28"
region = "us-central1"
network = google_compute_network.burn_backend_network.id
depends_on = [google_compute_network.burn_backend_network]
}

resource "google_compute_network" "burn_backend_network" {
name = "burn-backend-run-network"
name = "burn-backend-run-network-${terraform.workspace}"
auto_create_subnetworks = false
}

# Create a Cloud Router
resource "google_compute_router" "burn_backend_router" {
name = "burn-backend-router"
name = "burn-backend-router-${terraform.workspace}"
network = google_compute_network.burn_backend_network.name
region = "us-central1"
}

# Reserve a static IP address
resource "google_compute_address" "burn_backend_static_ip" {
name = "burn-backend-static-ip"
name = "burn-backend-static-ip-${terraform.workspace}"
region = "us-central1"
}

# Set up Cloud NAT
resource "google_compute_router_nat" "burn_backend_nat" {
name = "burn-backend-nat"
name = "burn-backend-nat-${terraform.workspace}"
router = google_compute_router.burn_backend_router.name
region = "us-central1"

Expand Down Expand Up @@ -98,7 +98,7 @@ resource "google_compute_router_nat" "burn_backend_nat" {

# Create a Cloud Run service for burn-backend services
resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
name = "tf-rest-burn-severity"
name = "tf-rest-burn-severity-${terraform.workspace}"
location = "us-central1"

template {
Expand All @@ -111,12 +111,17 @@ resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
value = "CLOUD"
}
env {
name = "SFTP_SERVER_ENDPOINT"
value = var.sftp_server_endpoint
name = "S3_FROM_GCP_ROLE_ARN"
value = var.s3_from_gcp_role_arn
}
env {
name = "SFTP_ADMIN_USERNAME"
value = var.sftp_admin_username
name = "S3_BUCKET_NAME"
value = var.s3_bucket_name
}
## TODO [#24]: self-referential endpoint, will be solved by refactoring out titiler and/or making fully static
env {
name = "GCP_CLOUD_RUN_ENDPOINT"
value = "${terraform.workspace}" == "prod" ? "https://tf-rest-burn-severity-ohi6r6qs2a-uc.a.run.app" : "https://tf-rest-burn-severity-dev-ohi6r6qs2a-uc.a.run.appz"
}
env {
name = "CPL_VSIL_CURL_ALLOWED_EXTENSIONS"
Expand Down Expand Up @@ -193,14 +198,14 @@ resource "google_cloud_run_service_iam_member" "public" {

# Create the IAM workload identity pool and provider to auth GitHub Actions
resource "google_iam_workload_identity_pool" "pool" {
workload_identity_pool_id = "github-actions"
workload_identity_pool_id = "github-actions-${terraform.workspace}"
display_name = "Github Actions Pool"
description = "Workload identity pool for GitHub actions"
}

resource "google_iam_workload_identity_pool_provider" "oidc" {
depends_on = [google_iam_workload_identity_pool.pool]
workload_identity_pool_provider_id = "oidc-provider"
workload_identity_pool_provider_id = "oidc-provider-${terraform.workspace}"
workload_identity_pool_id = google_iam_workload_identity_pool.pool.workload_identity_pool_id

display_name = "GitHub OIDC Provider"
Expand All @@ -225,19 +230,22 @@ resource "google_service_account_iam_binding" "workload_identity_user" {
]
}

## TODO [#20]: Harcoded project string and others - now that tofu outputs are setup up, make more general
## Will be helpful as we move to other projects and environments

# Create the IAM service account for GitHub Actions
resource "google_service_account" "github_actions" {
account_id = "github-actions-service-account"
account_id = "github-actions-sa-${terraform.workspace}"
display_name = "Github Actions Service Account"
description = "This service account is used by GitHub Actions"
project = "dse-nps"
}

# Create the IAM service account for the Cloud Run service
resource "google_service_account" "burn-backend-service" {
account_id = "burn-backend-service"
display_name = "Cloud Run Service Account for burn backend"
description = "This service account is used by the Cloud Run service to access GCP Secrets Manager"
account_id = "burn-backend-service-${terraform.workspace}"
display_name = "Cloud Run Service Account for burn backend - ${terraform.workspace}"
description = "This service account is used by the Cloud Run service to access GCP Secrets Manager and authenticate with OIDC for AWS S3 access"
project = "dse-nps"
}

Expand All @@ -253,6 +261,12 @@ resource "google_project_iam_member" "log_writer" {
member = "serviceAccount:${google_service_account.burn-backend-service.email}"
}

resource "google_project_iam_member" "oidc_token_creator" {
project = "dse-nps"
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:${google_service_account.burn-backend-service.email}"
}

# Give the service account permissions to deploy to Cloud Run, and to Cloud Build, and to the Workload Identity Pool
resource "google_project_iam_member" "run_admin" {
project = "dse-nps"
Expand Down Expand Up @@ -286,7 +300,7 @@ resource "google_project_iam_member" "artifact_registry_writer" {

# Create an Artifact Registry repo for the container image
resource "google_artifact_registry_repository" "burn-backend" {
repository_id = "burn-backend"
repository_id = "burn-backend-${terraform.workspace}"
format = "DOCKER"
location = "us-central1"
}
15 changes: 15 additions & 0 deletions .deployment/tofu/modules/burn_backend/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
output "burn_backend_server_endpoint" {
description = "The endpoint of the Cloud Run burn-backend service"
value = google_cloud_run_v2_service.tf-rest-burn-severity.uri
}

output "burn_backend_server_uuid" {
description = "The UUID of the Cloud Run service"
value = google_cloud_run_v2_service.tf-rest-burn-severity.uid
}

output "gcp_service_account_s3_email" {
description = "The email of the service account used by the backend service on GCP Cloud Run"
value = google_service_account.burn-backend-service.email
}

output "gcp_burn_backend_service_account_unique_id" {
description = "The unique ID of the service account used by the backend service on GCP Cloud Run"
value = google_service_account.burn-backend-service.unique_id
}
17 changes: 6 additions & 11 deletions .deployment/tofu/modules/burn_backend/variables.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
variable "ssh_pairs" {
description = "SSH private/public key pairs for the normie and admin user"
type = any
}

variable "google_project_number" {
description = "Google project number"
type = string
}

variable "sftp_server_endpoint" {
description = "The endpoint of the SFTP server"
type = string
variable "s3_from_gcp_role_arn" {
description = "Role ARN to assume to access S3 from GCP"
type = string
}

variable "sftp_admin_username" {
description = "The username of the admin user"
type = string
variable "s3_bucket_name" {
description = "S3 bucket name"
type = string
}
Loading