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

feat: Add MySQL support #138

Merged
merged 18 commits into from
Sep 16, 2024
Merged

feat: Add MySQL support #138

merged 18 commits into from
Sep 16, 2024

Conversation

akashgangil
Copy link
Contributor

@akashgangil akashgangil commented Jul 17, 2024

Introduces a new variable database_type to configure
the three tier web app to use either MySQL or PostgreSQL.

Resuses gcr.io/sic-container-repo/todo-api, due to this MySQL
instance authentication is configured via a databases user/password
instead of IAM service account like PG.

MySQL

module "three_tier_app" {
  source                 = "GoogleCloudPlatform/three-tier-web-app/google"
  version                = "~> 0.1"
  project_id             = <dummy>
  database_type          = "mysql"
  region                 = "us-central1"
  zone                   = "us-central1-a"
}

PostgreSQL

module "three_tier_app" {
  source                 = "GoogleCloudPlatform/three-tier-web-app/google"
  version                = "~> 0.1"
  project_id             = <dummy>
  database_type          =  "postgres"
  region                 = "us-central1"
  zone                   = "us-central1-a"
}

Introduces a new variable database_type
@akashgangil akashgangil requested review from tpryan and a team as code owners July 17, 2024 10:56
@NimJay
Copy link
Contributor

NimJay commented Jul 23, 2024

/gcbrun

@NimJay NimJay changed the title Add mysql support to three tier web app feat: Add MySQL support Jul 24, 2024
Copy link
Contributor

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

Thanks so much for working on these updates, @akashgangil!
Overall, it's looks good. I've left some comments.

We'll also need to add an integration test for the MySQL option.
We'll need to:

variables.tf Show resolved Hide resolved
instance = google_sql_database_instance.main.name
deletion_policy = "ABANDON"
name = var.database_type == "postgres" ? "${google_service_account.runsa.account_id}@${var.project_id}.iam" : "foo"
type = var.database_type == "postgres" ? "CLOUD_IAM_SERVICE_ACCOUNT" : null
password = var.database_type == "mysql" ? "bar" : null
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Does MySQL allow us to use type = CLOUD_IAM_SERVICE_ACCOUNT? I want to see if we can use the same google_sql_user definition for both PostgreSQL and MySQL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it but didn't work for me just right out of the box. Maybe we can take this in a follow up PR if this is not blocking?

Copy link
Contributor

@NimJay NimJay Sep 16, 2024

Choose a reason for hiding this comment

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

Agreed (let's move this type = CLOUD_IAM_SERVICE_ACCOUNT issue out of scope from this pull-request).
Issue created: #151

main.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
@@ -19,7 +19,7 @@ data "google_project" "project" {
}

locals {
api_image = "gcr.io/sic-container-repo/todo-api-postgres:latest"
api_image = (var.database_type == "mysql" ? "gcr.io/sic-container-repo/todo-api" : "gcr.io/sic-container-repo/todo-api-postgres:latest")
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: Thanks for digging into the differences between these two images! :) I didn't realize to original 3-tier web app used MySQL.

@NimJay
Copy link
Contributor

NimJay commented Jul 24, 2024

/gcbrun

@akashgangil
Copy link
Contributor Author

Thanks so much for working on these updates, @akashgangil! Overall, it's looks good. I've left some comments.

We'll also need to add an integration test for the MySQL option. We'll need to:

Done.

Thanks Nim for the review. Addressed all your comments

@NimJay
Copy link
Contributor

NimJay commented Sep 12, 2024

/gcbrun (to trigger the integration tests)

Before this change, we would:
1. Test (deploy, verify, and destroy) simple_example
2. Wait for simple_example to destroy
3. Test two new (parallel) deployments of simple_example

With this change, we now:
1. Test two deployments in parallel: the simple_example (which uses PostgreSQL); and the MySQL version.
@NimJay
Copy link
Contributor

NimJay commented Sep 13, 2024

/gcbrun (to trigger the integration tests)

@NimJay
Copy link
Contributor

NimJay commented Sep 13, 2024

/gcbrun

@NimJay
Copy link
Contributor

NimJay commented Sep 13, 2024

/gcbrun

@NimJay NimJay self-assigned this Sep 13, 2024
@NimJay
Copy link
Contributor

NimJay commented Sep 13, 2024

/gcbrun

@NimJay
Copy link
Contributor

NimJay commented Sep 14, 2024

/gcbrun

examples/mysql/main.tf Outdated Show resolved Hide resolved
@NimJay
Copy link
Contributor

NimJay commented Sep 14, 2024

/gcbrun

Copy link
Contributor

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

I've updated the integration tests such that:

  1. we now deploy the MySQL variation — in parallel to the PostgreSQL version
  2. we no longer deploy the pre-existing "multiple instance" test since it's now redundant

I've also made some minor lint-related tweaks.

Thank you so much, @akashgangil, for doing this (and addressing all my feedback)! 👏 Everything looks good. Integration tests are passing. Approved. Merging.

@NimJay NimJay merged commit ab8330c into GoogleCloudPlatform:main Sep 16, 2024
4 checks passed
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.

2 participants