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(terraform): allow traffic routing to be controlled by boolean #241

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

JoshuaLicense
Copy link
Contributor

@JoshuaLicense JoshuaLicense commented Aug 14, 2024

Description

This PR adds a boolean that will control traffic between EC2 and ECS. When true, respective load balances will route traffic to ECS infrastructure. When false, traffic will route to existing EC2 infrastructure. This can be controlled per service per environment.

This can be controlled per service and will hopefully be incredibly useful for:

  • testing infrastructure in isolation (NFT)
  • provisioning infrastructure without routing traffic.
  • migrating services individually (Internal infrastructure first? Lots of options for go-live).

The plans are clean as the load balancer rules are already active. How a plan would look if set to false:

Terraform will perform the following actions:

  # module.service.aws_lb_listener_rule.this["api"] will be destroyed
  # (because key ["api"] is not in for_each map)
  - resource "aws_lb_listener_rule" "this" {
      - arn          = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-SVCS-ALB/b21df94bee7afbcc/079795fb21af88e7/ac713009f1bb70df" -> null
      - id           = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-SVCS-ALB/b21df94bee7afbcc/079795fb21af88e7/ac713009f1bb70df" -> null
      - listener_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener/app/DEVAPPQA-OLCS-PRI-SVCS-ALB/b21df94bee7afbcc/079795fb21af88e7" -> null
      - priority     = 10 -> null
      - tags         = {} -> null
      - tags_all     = {
          - "Environment" = "int"
          - "Repository"  = "https://github.com/dvsa/vol-app"
        } -> null

      - action {
          - order            = 1 -> null
          - target_group_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:targetgroup/vol-app-int-api-tg/2b786c10b8b4079b" -> null
          - type             = "forward" -> null
        }

      - condition {
          - host_header {
              - values = [
                  - "api.*",
                ] -> null
            }
        }
    }

  # module.service.aws_lb_listener_rule.this["internal"] will be destroyed
  # (because key ["internal"] is not in for_each map)
  - resource "aws_lb_listener_rule" "this" {
      - arn          = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-IUWEB-ALB/5d7b89e0d93d5b1e/4c6cdab6c475f605/cc6edb08c117ccf7" -> null
      - id           = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-IUWEB-ALB/5d7b89e0d93d5b1e/4c6cdab6c475f605/cc6edb08c117ccf7" -> null
      - listener_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener/app/DEVAPPQA-OLCS-PRI-IUWEB-ALB/5d7b89e0d93d5b1e/4c6cdab6c475f605" -> null
      - priority     = 10 -> null
      - tags         = {} -> null
      - tags_all     = {
          - "Environment" = "int"
          - "Repository"  = "https://github.com/dvsa/vol-app"
        } -> null

      - action {
          - order            = 1 -> null
          - target_group_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:targetgroup/vol-app-int-internal-tg/7c77473c0fe6480c" -> null
          - type             = "forward" -> null
        }

      - condition {
          - host_header {
              - values = [
                  - "iuweb.*",
                ] -> null
            }
        }
    }

  # module.service.aws_lb_listener_rule.this["selfserve"] will be destroyed
  # (because key ["selfserve"] is not in for_each map)
  - resource "aws_lb_listener_rule" "this" {
      - arn          = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-SSWEB-ALB/becaba98d0276fd3/b92208df7025b367/61de61b2ba6399d2" -> null
      - id           = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener-rule/app/DEVAPPQA-OLCS-PRI-SSWEB-ALB/becaba98d0276fd3/b92208df7025b367/61de61b2ba6399d2" -> null
      - listener_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:listener/app/DEVAPPQA-OLCS-PRI-SSWEB-ALB/becaba98d0276fd3/b92208df7025b367" -> null
      - priority     = 10 -> null
      - tags         = {} -> null
      - tags_all     = {
          - "Environment" = "int"
          - "Repository"  = "https://github.com/dvsa/vol-app"
        } -> null

      - action {
          - order            = 1 -> null
          - target_group_arn = "arn:aws:elasticloadbalancing:eu-west-1:054614622558:targetgroup/vol-app-int-selfserve-tg/f92f8b41d86a9527" -> null
          - type             = "forward" -> null
        }

      - condition {
          - host_header {
              - values = [
                  - "ssweb.*",
                ] -> null
            }
        }
    }

This can be removed once EC2 infrastructure is decommissioned.

Also, includes documentation.

Related issue: https://dvsa.atlassian.net/browse/VOL-5730

Before submitting (or marking as "ready for review")

  • Does the pull request title follow the conventional commit specification?
  • Have you performed a self-review of the code
  • Have you have added tests that prove the fix or feature is effective and working
  • Did you make sure to update any documentation relating to this change?

@JoshuaLicense JoshuaLicense self-assigned this Aug 14, 2024
Copy link
Contributor

github-actions bot commented Aug 14, 2024

Terraform plan for environment: int

Commit: 6094a08

API version: a66abc4
CLI version: a66abc4
Selfserve version: a66abc4
Internal version: a66abc4

Plan summary

0 to add, 0 to change, 0 to destroy


Show full plan
No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

Copy link
Contributor

github-actions bot commented Aug 14, 2024

Terraform plan for environment: dev

Commit: 6094a08

API version: a66abc4
CLI version: a66abc4
Selfserve version: a66abc4
Internal version: a66abc4

Plan summary

0 to add, 0 to change, 0 to destroy


Show full plan
No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

@JoshuaLicense JoshuaLicense merged commit 74f3af5 into main Aug 15, 2024
23 checks passed
@JoshuaLicense JoshuaLicense deleted the add-toggleable-listener-rule branch August 15, 2024 08:42
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