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 target group attachment capabilities #191

Merged
merged 10 commits into from
Apr 14, 2021

Conversation

veilig2000
Copy link
Contributor

@veilig2000 veilig2000 commented Mar 29, 2021

Description

Allows for the creation of a "targets" index inside the target_groups variable, where the parameters of the attachment can be defined. The same arguments that are used for the target_group_attachment resource, are the same arguments that should/can be defined. Any additional arguments are created during the "product mapping", but are not used in the resource, but allows for easy upgrading in the future if more arguments are added (only have to update on the resource function)

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment#argument-reference

Motivation and Context

Allow attaching EC2 instance(s) and Lambda functions to the target groups created by this module so all resources can be managed in one location. Currently, there's no functionality to add any attachments to the target groups this module creates and everything needs to be additionally defined/coded

Breaking Changes

This should be backwards compatible, if no "targets" are defined on the target_group variable, no attachments are created.

How Has This Been Tested?

[x] I have tested and validated these changes using one or more of the provided examples/* projects

This was manually tested in a sandbox AWS environment on actual ALB/EC2 resources. I currently don't work w/ lambda function attached to any type of LB, so I did not test that. But since the function calls are the same on the target_group_attachment resource between an EC2 instance and a Lambda Function and this is just a mapping of parameters to that function, I really don't anticipate any issues.

variable definition can look like this now

    target_groups = [
        {
            name = "tg-with-targets"
            backend_protocol = "HTTP"
            backend_port = "80"
            target_type = "instance"
            deregistration_delay = 300
            health_check = { ... }
            stickiness = { ... }
            targets = [
                {
                    target_id = "i-0123456789abcdefg"
                    port = 80
                },
               {
                    target_id = "i-a1b2c3d4e5f6g7h8i"
                    port = 8080
                }
            ]
        },
        {
            name = "tg-without-targets"
            backend_protocol = "HTTP"
            backend_port = "80"
            target_type = "instance"
            deregistration_delay = 300
            health_check = { ... }
            stickiness = { ... }
        }
    ]

veilig2000 and others added 2 commits March 29, 2021 15:35
Why is it necessary? (Bug fix, feature, improvements?)
- Allow attaching EC2 instance(s) and Lambda functions to the target
  groups created by this module so all resources can be managed in one
  location

How does the change address the issue?
- Allows for the creation of a "targets" index inside the target_groups
  variable, where the parameters of the attachment can be defined.
- The same arguments that are used for the target_group_attachment
  resource, are the same arguments that should/can be defined. Any
  additional arguments are created during the "product mapping", but are
  not used in the resource, but allows for easy upgrading in the future
  if more arguments are added (only have to update on the resource function)
  https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment#argument-reference

What side effects does this change have?
- This should be backwards compatible, if no "targets" are defined on
  the target_group variable, no attachments are created.

Include a link to the ticket, if any.
- N/A
@veilig2000 veilig2000 changed the title Add target group attachment capabilities feat: Add target group attachment capabilities Mar 30, 2021
@veilig2000
Copy link
Contributor Author

@bryantbiggs - was curious how do you test your change for e5f2627 ? I don't even know if that is the problem that I'm facing. I just saw a previous PR that didn't look like it was failing (like mine is) 8 days ago, your fix 4 days ago, and my PR 2 days ago and its failing - so I started looking if that was causing it.

I'm trying to debug why my pre-commit build is failing for the Max TF pre-commit (0.14.9). Everything locally is passing for me after checking w/ a couple TF versions.

 ▲ ~/code/terraform-aws-alb terraform -v                                master  1d ⬢
Terraform v0.14.8
+ provider registry.terraform.io/hashicorp/aws v3.34.0

Your version of Terraform is out of date! The latest version
is 0.14.9. You can update by downloading from https://www.terraform.io/downloads.html
 ▲ ~/code/terraform-aws-alb pre-commit run -a                           master  1d ⬢
Terraform fmt............................................................Passed
Terraform validate.......................................................Passed
Terraform docs...........................................................Passed
Terraform validate with tflint...........................................Passed
Check for merge conflicts................................................Passed
 ▲ ~/code/terraform-aws-alb tfswitch                               6s   master  1d ⬢
Reading required version from terraform file, constraint: >= 0.12.6
Matched version: 0.14.9
Switched terraform to version "0.14.9"
 ▲ ~/code/terraform-aws-alb pre-commit run -a                           master  1d ⬢
Terraform fmt............................................................Passed
Terraform validate.......................................................Passed
Terraform docs...........................................................Passed
Terraform validate with tflint...........................................Passed
Check for merge conflicts................................................Passed
 ▲ ~/code/terraform-aws-alb                                        6s   master  1d ⬢

I tried downloading act to debug some more, but I'm running into this yaml: unmarshal error now. So I was just curious how you test things?

 ▲ ~/code/terraform-aws-alb act --version                          master  1d ⬢
act version 0.2.21
 ▲ ~/code/terraform-aws-alb act -l                                 master  1d ⬢
Error: yaml: unmarshal errors:
  line 33: cannot unmarshal !!str `${{ fro...` into []interface {}

It's just complaining that it can't find terraform-docs

ERROR: terraform-docs is required by terraform_docs pre-commit hook but is not installed or in the system's PATH.

@veilig2000
Copy link
Contributor Author

veilig2000 commented Mar 31, 2021

figured it out

curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12.0-linux-amd64"

The grep on the latest version doesn't allow for patches and is hardcoded to v0.12.0, the latest right now is v0.12.1. Looking at best way to update that.

Why is it necessary? (Bug fix, feature, improvements?)
- the latest release will not always be tied to the v0.12.0 tag. Allow
  patches to the release

How does the change address the issue?
- use a regex to search for patches

What side effects does this change have?
- As soon as the latest release goes above the v0.12 version, this is
  going to break. A better way to do this will be to fetch all the tags
  and correlate the highest v0.12 release via the API, but thats going
  to take a little more work, as there's currently no way to fetch
  releases associated to a major/minor version that I can see.
- https://docs.github.com/en/rest/reference/repos#list-repository-tags
- https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name

Include a link to the ticket, if any.
- N/A
@bryantbiggs
Copy link
Member

oy, this damn terraform docs - my apologies @veilig2000 , let me see what I can do

@veilig2000
Copy link
Contributor Author

lol - I just updated it - it worked fine on the latest ubuntu docker image locally (just getting the tf-docs pulled down), now some other weird error is being generated :/

@veilig2000
Copy link
Contributor Author

@antonbabenko, this look good to merge?

Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

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

Amazing piece of code! Just a few comments and questions.

outputs.tf Outdated

output "target_group_attachments" {
description = "ARNs of the target group attachment IDs."
value = [
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to have this as a map so that users can identify both target_group (as a key) and a list of attachments (as a value)

main.tf Show resolved Hide resolved
@@ -293,6 +303,14 @@ module "alb" {
name_prefix = "l1-"
target_type = "lambda"
lambda_multi_value_headers_enabled = true
targets = [
{
target_id = "arn:aws:lambda:us-east-1:123456789012:function:lambda_function_1"
Copy link
Member

Choose a reason for hiding this comment

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

Will it work if you specify non-existing ARN? If not, we need to update the code to create a real Lambda function and use it.

Choose a reason for hiding this comment

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

^ bs

@veilig2000
Copy link
Contributor Author

Amazing piece of code! Just a few comments and questions.

I'll get all these reviewed quickly so we can merge, just been buried with work

@antonbabenko
Copy link
Member

@veilig2000 I will work on this later today.

@antonbabenko antonbabenko merged commit e72ba5d into terraform-aws-modules:master Apr 14, 2021
@antonbabenko
Copy link
Member

Thanks for your contribution, @veilig2000 !

v5.14.0 has been just released.

@lev112
Copy link

lev112 commented Apr 15, 2021

this PR introduces a breaking change
I'm using terraform 0.12.29, and depend on the module with ~> 5.0
so if I'm running a clean init, I'm getting:

Module xxxx (from "terraform-aws-modules/alb/aws") does not
support Terraform version 0.12.29

because of the updated version constraint

IMO, this should have been a major version change

@antonbabenko
Copy link
Member

@lev112 #195 (comment)

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants