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

Set max_allocated_storage var and switch to updated Terraform db module #1312

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

KlaasH
Copy link
Collaborator

@KlaasH KlaasH commented Jun 20, 2023

Overview

In the course of dealing with issue #1307, I switched the database to using storage auto-scaling (and also to the gp3 storage type). But the Terraform module we're using for the database config hasn't been updated in a while and doesn't support auto-scaling. So I wasn't able to update the Terraform config then to match the changes I'd made in the console, but I left it at that. Turns out, having the deployed state differ from the Terraform config in a way that the config can't even represent is a bad plan, and it bit us, in the form of an attempt to run the Release action crashing and leaving the infrastructure in a somewhat broken in-between state.

So we need to update the Terraform config for the database to match how it is in production, that that's what this does. It switches to a fork of the module that has the max_allocated_storage parameter added.

I opened a PR on the module repo, but I'm not sure what the maintenance situation is for those modules these days, so I think it makes sense to just use the branch on my fork for now.

Checklist

  • Description of PR is in an appropriate section of CHANGELOG.md and grouped with similar changes, if possible

Demo

I made the same manual change to the staging database that I had made to production (changing to gp3 and turning on auto-scaling) then pushed a test branch to run a test deploy to staging. Per the logs, it noticed that the database had been changed outside of Terraform, but didn't find any changes that needed to be applied to it.

Testing Instructions

With this branch checked out, run the Terraform container:

DB_SETTINGS_BUCKET=districtbuilder-production-config-us-east-1 \
  DB_DEPLOYMENT_ENVIRONMENT=production \
  GIT_COMMIT=911fdcb \
  docker-compose -f docker-compose.ci.yml run --rm terraform

(that's the currently-deployed git commit, to avoid requiring that the app services get updated)

Inside that container, run ./scripts/infra plan. It will show some changes—I think that's a combination of the partial apply from the failed deploy and possibly some drift on the AWS side—but it shouldn't show any changes required for resource "aws_db_instance" "postgresql" (whereas if you check out develop and run it again, it will).

@KlaasH KlaasH requested a review from ddohler June 20, 2023 21:05
@KlaasH KlaasH force-pushed the feature/kjh/update-postgres-terraform-module branch from b08a596 to 25d9f42 Compare June 22, 2023 20:31
@KlaasH KlaasH requested review from aaronxsu and removed request for ddohler June 22, 2023 20:49
@KlaasH KlaasH assigned aaronxsu and unassigned ddohler Jun 22, 2023
Copy link
Collaborator

@aaronxsu aaronxsu left a comment

Choose a reason for hiding this comment

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

🤞🏼

@@ -75,14 +75,17 @@ resource "aws_db_parameter_group" "default" {
}

module "database" {
source = "github.com/azavea/terraform-aws-postgresql-rds?ref=3.0.0"
# TODO: go back to github.com/azavea/terraform-aws-postgresql-rds once it's updated
# (see https://github.com/azavea/terraform-aws-postgresql-rds/pull/48)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for leaving a commend here. I'd suggest we also create an issue in this repo so that we use that one to update the source once the PR is merged in the upstream.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I made #1316.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@@ -58,6 +58,11 @@ variable "rds_allocated_storage" {
type = string
}

variable "rds_max_allocated_storage" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd assume the tfvars in S3 is already updated- right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't updated it yet, but I will before I push the button to deploy to production. I'm going to watch the staging build after I merge and double-check the production vars against the staging ones to make sure they're how we want them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds like a plan to me 👍🏼

@KlaasH KlaasH force-pushed the feature/kjh/update-postgres-terraform-module branch from 25d9f42 to d9437b1 Compare June 23, 2023 18:28
@KlaasH KlaasH merged commit 8339bb7 into develop Jun 23, 2023
@KlaasH KlaasH deleted the feature/kjh/update-postgres-terraform-module branch June 23, 2023 18:29
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