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

AWS Auth in Terraform #1771

Merged
merged 5 commits into from
Feb 19, 2025
Merged

AWS Auth in Terraform #1771

merged 5 commits into from
Feb 19, 2025

Conversation

ben851
Copy link
Contributor

@ben851 ben851 commented Feb 18, 2025

Summary | Résumé

Moving AWS auth configuration to Terraform for dev and staging. Eventually will be pushed to prod, but let's test it first.

Removes it from kustomize/helmfile and eliminates the issue we have where migrating it from Kustomize to Helmfile breaks the authentication to K8s.

Related Issues | Cartes liées

Before merging this PR

Read code suggestions left by the
cds-ai-codereviewer bot. Address
valid suggestions and shortly write down reasons to not address others. To help
with the classification of the comments, please use these reactions on each of the
comments made by the AI review:

Classification Reaction Emoticon
Useful +1 👍
Noisy eyes 👀
Hallucination confused 😕
Wrong but teachable rocket 🚀
Wrong and incorrect -1 👎

The classifications will be extracted and summarized into an analysis of how helpful
or not the AI code review really is.

Test instructions | Instructions pour tester la modification

TF Apply in staging
Verify we can still access the k8s cluster

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

[review]
@@ -1,11 +1,12 @@
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "dev"
config_context = var.env

Choose a reason for hiding this comment

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

The change from a hardcoded context to using var.env is good for flexibility, but ensure that var.env is properly defined and validated to avoid potential issues.

}

data "aws_caller_identity" "current" {}

module "eks" {
count = var.env != "production" ? 1 : 0

Choose a reason for hiding this comment

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

The count parameter is being set based on the environment. Ensure that var.env is correctly set to either 'production' or another value to avoid unexpected behavior.

@@ -0,0 +1,9 @@
terraform {
source = "${get_env("ENVIRONMENT") == "production" ? "git::https://github.com/cds-snc/notification-terraform//aws/aws-auth?ref=v${get_env("INFRASTRUCTURE_VERSION")}" : "../../../aws//aws-auth"}"

Choose a reason for hiding this comment

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

Consider using a variable for the repository URL to avoid hardcoding it multiple times in the codebase. This will make it easier to update the URL in the future if needed.

path = find_in_parent_folders()
}


Choose a reason for hiding this comment

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

There is an extra blank line at the end of the file. It is generally good practice to keep the file clean by removing unnecessary blank lines.

@@ -0,0 +1,9 @@
terraform {
source = "${get_env("ENVIRONMENT") == "production" ? "git::https://github.com/cds-snc/notification-terraform//aws/aws-auth?ref=v${get_env("INFRASTRUCTURE_VERSION")}" : "../../../aws//aws-auth"}"

Choose a reason for hiding this comment

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

Consider using a variable for the environment check instead of directly using get_env("ENVIRONMENT") for better readability and maintainability.

path = find_in_parent_folders()
}


Choose a reason for hiding this comment

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

There is an extra empty line at the end of the file. Consider removing it to maintain consistent formatting.

@@ -0,0 +1,9 @@
terraform {
source = "${get_env("ENVIRONMENT") == "production" ? "git::https://github.com/cds-snc/notification-terraform//aws/aws-auth?ref=v${get_env("INFRASTRUCTURE_VERSION")}" : "../../../aws//aws-auth"}"

Choose a reason for hiding this comment

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

Consider using a more readable format for the source attribute to improve maintainability. For example, you can use string interpolation for the URL and the version separately.

Ben Larabie added 3 commits February 18, 2025 15:20
@@ -1,11 +1,12 @@
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = "dev"
config_context = var.env

Choose a reason for hiding this comment

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

Consider renaming the variable var.env to something more descriptive, such as var.environment, to improve code readability.

}

data "aws_caller_identity" "current" {}

module "eks" {
count = var.env != "production" ? 1 : 0

Choose a reason for hiding this comment

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

The count parameter logic could be simplified by using a boolean variable for production environment check. For example, var.is_production ? 0 : 1.

@@ -0,0 +1,7 @@
terraform {
source = "${get_env("ENVIRONMENT") == "production" ? "git::https://github.com/cds-snc/notification-terraform//aws/aws-auth?ref=v${get_env("INFRASTRUCTURE_VERSION")}" : "../../../aws//aws-auth"}"

Choose a reason for hiding this comment

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

Consider breaking the source value into multiple lines for better readability. For example:

source = get_env("ENVIRONMENT") == "production" ? \
  "git::https://github.com/cds-snc/notification-terraform//aws/aws-auth?ref=v${get_env("INFRASTRUCTURE_VERSION")}" : \
  "../../../aws//aws-auth"

Copy link

staging: aws-auth

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 1 to add, 0 to change, 0 to destroy
Show summary
CHANGE NAME
add module.eks[0].kubernetes_config_map_v1_data.aws_auth[0]
Show plan
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.eks[0].kubernetes_config_map_v1_data.aws_auth[0] will be created
  + resource "kubernetes_config_map_v1_data" "aws_auth" {
      + data          = {
          + "mapAccounts" = (sensitive value)
          + "mapRoles"    = (sensitive value)
          + "mapUsers"    = jsonencode([])
        }
      + field_manager = "Terraform"
      + force         = true
      + id            = (known after apply)

      + metadata {
          + name      = "aws-auth"
          + namespace = "kube-system"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
20 tests, 20 passed, 0 warnings, 0 failures, 0 exceptions

@ben851 ben851 changed the title formatting AWS Auth in Terraform Feb 19, 2025
@ben851 ben851 requested a review from a team February 19, 2025 15:18
@ben851 ben851 marked this pull request as ready for review February 19, 2025 15:19
@ben851 ben851 requested a review from jimleroyer as a code owner February 19, 2025 15:19
Copy link
Contributor

@P0NDER0SA P0NDER0SA left a comment

Choose a reason for hiding this comment

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

interesting.... wanna see this work

@ben851 ben851 merged commit a38dbf9 into main Feb 19, 2025
30 checks passed
@ben851 ben851 deleted the aws-auth branch February 19, 2025 19:26
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