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

Repurpose PSE terraform config to initialize cloud resources #2

Merged
merged 6 commits into from
Mar 8, 2024

Conversation

zschira
Copy link
Member

@zschira zschira commented Feb 27, 2024

This PR takes sets up cloud infrastructure using terraform. We will be using similar infrastructure to that used for the PSE project, so most of this was repurposed from there. Specifically, we will have storage bucket with raw 10-K filings, and postgres instance containing filing metadata. This will be used during development so we can quickly search through filings, manually inspect them, and do experimental development with minimal hassle. Eventually this infrastructure will likely be taken down, as all of the dev work for mozilla should be migrated into PUDL, and we will access filings using our normal archiver workflow.

@zschira zschira requested a review from jdangerx February 27, 2024 17:43

variable "project_id" {
type = string
default = "catalyst-cooperative-pudl"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything weird about using the PUDL project from a different repo? Should we just create a mozilla project?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're billing infrastructure costs to Mozilla, we should probably make a separate mozilla project - that will make the bookkeeping much easier.

If not, I think it's fine to use the same GCP project - though if we do that, I'd rather this terraform configuration live in the pudl repo. I think one tfstate per GCP project is easier to think about.

Copy link
Member

@jdangerx jdangerx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terraform stuff is a little funky. I personally think we should make a new Mozilla project in GCP, and set stuff up for that.

But if we're going to end up reusing a bunch of this infrastructure for PUDL one day, it might make sense to bring it into the main project + terraform state.


variable "project_id" {
type = string
default = "catalyst-cooperative-pudl"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're billing infrastructure costs to Mozilla, we should probably make a separate mozilla project - that will make the bookkeeping much easier.

If not, I think it's fine to use the same GCP project - though if we do that, I'd rather this terraform configuration live in the pudl repo. I think one tfstate per GCP project is easier to think about.

terraform/main.tf Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add @bendnorman too.

}

resource "google_storage_bucket" "tfstate" {
name = "${random_id.bucket_prefix.hex}-tfstate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we create a new Mozilla project, we'll need to actually follow this guide which basically says:

  1. use a block such as this one to create a bucket to hold tfstate
  2. only then do you configure the tfstate to be remote like in lines 1-4 - though point the gcs backend at the new bucket

If you want to stay in the PUDL project because the billing isn't separate, you can avoid making this new bucket and just use what we have already set up (the f344... bucket).

terraform/main.tf Show resolved Hide resolved
terraform/main.tf Show resolved Hide resolved
type = "CLOUD_IAM_USER"
}

resource "google_secret_manager_secret" "postgres_pass" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you'll have to create a new "secret version" manually to actually hold a secret password value.

@zschira
Copy link
Member Author

zschira commented Feb 28, 2024

Ok so I've switched to using a dedicated mozilla project. We do have some funding for cloud resources, so we should be billing separately. It seems like that solves many of these problems.

I think I need someone else to create the project though, as I don't have permission

Copy link
Member

@jdangerx jdangerx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it'll mostly work, except for the whole "remote tfstate has to have a bucket, but the bucket has to be created by terraform first" thing. 🐣 I'm happy to pair on the operations of that if that makes life easier for you!

@@ -0,0 +1,140 @@
terraform {
backend "gcs" {
bucket = "f3441e415e6e5e7d-bucket-tfstate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right shape of things, but you'll run into issues with f34... bucket not existing in the new project! You'll have to:

  1. take away this gcs backend
  2. create a new state bucket with a new random prefix
  3. re-configure this gcs backend with the new state bucket

It's fine to do that all locally before committing the changes, which should look exactly like this but with a different bucket name.

display_name = "Mozilla dev"
}

resource "random_id" "bucket_prefix" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit: might be a little easier to read later if this bucket prefix is defined right next to the only place it's used - the tfstate bucket.

@jdangerx
Copy link
Member

jdangerx commented Mar 1, 2024

Oh and I think either @zaneselvans or @bendnorman have permissions to create a new project.


resource "google_project_iam_binding" "catalyst_people_editors" {
project = var.project_id
role = "roles/editor"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this making everyone an editor on the entire project?

@zschira zschira merged commit b48b769 into main Mar 8, 2024
11 checks passed
@zschira zschira deleted the init_infra branch March 8, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants