-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use existing identity provider in temporary environments #717
Conversation
fefca44
to
23c2732
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, had a comment about the new pattern of grouping related modules
client_secret_ssm_name = "/${var.app_name}-${var.environment}/identity-provider/client-secret" | ||
user_pool_access_policy_name = "${var.app_name}-${var.environment}-cognito-access" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the comment I left on infra/modules/identity-provider/README.md, but I think we can have a new pattern that eliminates the need for config variables that are used primarily for dependency management rather than for actual configuration. tldr; I think we can move the definition of these things to something like a modules/identity/interface/
module that can be used by both the module with data sources and the module that actually creates the resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great layout here 👍🏼 👍🏼 👍🏼
@lorenyu @coilysiren Re-requesting review. This PR has been re-architected to incorporate the feedback around module structure. The test can be seen: navapbc/platform-test#128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good just left some nits.
Wish we had platform-test-rails up so we can see it in action in the PR environment. Otherwise it's a little bit more of a leap of faith. But I think it's still ok.
infra/app/service/main.tf
Outdated
@@ -22,12 +22,20 @@ data "aws_subnets" "private" { | |||
} | |||
|
|||
locals { | |||
# The prefix key/value pair is used for Terraform Workspaces, which is useful for projects with multiple infrastructure developers. | |||
# By default, Terraform creates a workspace named “default.” If a non-default workspace is not created this prefix will equal “default”, | |||
# if you choose not to use workspaces set this value to "dev" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment. What does it mean to "choose not to use workspaces"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh funny. I copy/pasted this directly from
template-infra/infra/app/app-config/env-config/main.tf
Lines 2 to 5 in 7a9b157
# The prefix key/value pair is used for Terraform Workspaces, which is useful for projects with multiple infrastructure developers. | |
# By default, Terraform creates a workspace named “default.” If a non-default workspace is not created this prefix will equal “default”, | |
# if you choose not to use workspaces set this value to "dev" | |
prefix = terraform.workspace == "default" ? "" : "${terraform.workspace}-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was i thinking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we change the comment here and in /infra/app/app-config/env-config/main.tf
to this:
locals {
# The prefix is used to create uniquely named resources per terraform workspace, which
# are needed in CI/CD for preview environments and tests.
#
# To isolate changes during infrastructure development by using manually created
# terraform workspaces, see: /docs/infra/develop-and-test-infrastructure-in-isolation-using-workspaces.md.
prefix = terraform.workspace == "default" ? "" : "${terraform.workspace}-"
bucket_name = "${local.prefix}${var.project_name}-${var.app_name}-${var.environment}"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great
No objections to your nits. Let me do a quick test over at platform-test to verify everything is working as expected.
Agree about |
I see an error in the template CI I think you may need to set identity_provider_user_pool_id to null if enable_identity_provider is false |
Yeah, I'm looking at that error, too. Sadly, I think it's more complicated than that. I think there's a problem with using temporary environments to control whether or not to use an existing user pool. |
Loren and I chatted about this offline and I fixed the error. I was confusing this issue with a different problem. |
Ticket
Resolves #719
Changes
/infra/app/service
to use existing idp resources for temporary environmentsexisting-identity-provider
module as a wrapper for multiple data source callsidentity-provider-client
module and intoapp-config
to ensure the same name (e.g. ssm name or access policy) is used across modulesidentity_provider_name
Context for reviewers
In temporary environments, such as PR preview environments, we want to use the same Cognito User Pool as the default terraform workspace. That allows QA and UAT to use existing users instead of having to go through an account creation flow on every PR.
This PR checks to see if it's a temporary environment. If it is, it uses data sources to fetch existing resources. If it's not, it creates a new identity provider, just as before.
Testing
Tested at navapbc/platform-test#128
IAM role for the preview environment has default workspace access policy successfully attached:
ECS task definition for the preview environment service has correct cognito environment variables (I know I redacted the details out, but wanted to give the gist):
ECS task definition for the preview environment service has correct cognito secret arn:
Preview environment successfully applied the updates: