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

Add Support for List of Tag Maps #18

Merged
merged 20 commits into from
May 16, 2018
Merged

Conversation

Jamie-BitFlight
Copy link
Contributor

@Jamie-BitFlight Jamie-BitFlight commented May 9, 2018

what

  • Add support for list of tag maps

why

  • Certain kinds of resources (e.g. AWS AutoScaling groups) need them

@osterman
Copy link
Member

osterman commented May 9, 2018

Hah, yes, this is now entirely possible with locals. Question then becomes, what provider does it belong under?

https://www.terraform.io/docs/registry/modules/publish.html#requirements

We might want to create a new module under that provider, since terraform-null-label implies the primary provider is null. I guess it should be in a module called terraform-terraform-label

https://github.com/terraform-providers/terraform-provider-terraform

@osterman
Copy link
Member

osterman commented May 9, 2018

We were recently faced with this conundrum here: cloudposse/terraform-aws-key-pair#12 (see discussion for some context)

@Jamie-BitFlight
Copy link
Contributor Author

I see. So for it to be published publicly it needs to be named by the provider.

The locals is part of core terraform. I imagine that you could name it core or terraform for the middle name?

And retire the null provider repo? Since it requires extra downloading and initializing, unlike locals?

@osterman
Copy link
Member

osterman commented May 9, 2018

Yea, so the provider would be terraform. I would be more than happy to accomodate the repo, but terraform-null-provider will live to see another day.

image

We have nearly 80 repositories that need to be updated. All-in-all, it's a very low priority since the legacy method works fine.

@osterman
Copy link
Member

osterman commented May 9, 2018

Fwiw, here's a repo if you want to rebase your change ontop of it: https://github.com/cloudposse/terraform-terraform-label

@Jamie-BitFlight
Copy link
Contributor Author

Thank you. I have something even better to show you with my next commit.

Jamie Nelson added 2 commits May 10, 2018 16:19
Updated to allow for tagging of Autoscaling groups.
It was really damn hard guys, really hard to getthat stupid thing expanding as a dynamic list.
@Jamie-BitFlight
Copy link
Contributor Author

@osterman I've created a new technique for use in this module, and I have put the null provider back in to handle it.
Autoscaling groups and their servers can now be tagged dynamically.

@Jamie-BitFlight Jamie-BitFlight changed the title Updated to not used null_resource so that the null_resource provider … Updated so that the null_resource provider is used for autoscaling tags, and locals for standard tags May 10, 2018
@Jamie-BitFlight
Copy link
Contributor Author

@aknysh Is this being reviewed?

main.tf Outdated
}"

tags_asg_propagate_true = ["${null_resource.tags_asg_propagate_true.*.triggers}"]
tags_asg_propagate_false = ["${null_resource.tags_asg_propagate_false.*.triggers}"]
Copy link
Member

Choose a reason for hiding this comment

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

@Jamie-BitFlight
thanks again!
please remove everything related to other technologies and services from this module.
it's the lowest-level generic module which all other modules use.
it should not mention anything like EC2 or ASG.
(this could be in the advanced examples though)

README.md Outdated
@@ -148,6 +229,8 @@ resource "aws_instance" "eg_prod_bastion_xyz" {
| namespace | Normalized namespace |
| stage | Normalized stage |
| tags | Merge input tags with our tags. Note: `Name` has a special meaning in AWS and we need to disamgiuate it by using the computed `id` |
| tags_asg_propagate_true | a list of maps that contain the ASG format tags with propagation set to true |
| tags_asg_propagate_false | a list of maps that contain the ASG format tags with propagation set to false |
Copy link
Member

Choose a reason for hiding this comment

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

@Jamie-BitFlight
please remove everything related to other technologies and services from this module.
it's the lowest-level generic module which all other modules use.
it should not mention anything like EC2 or ASG in the inputs.
thanks

main.tf Outdated
}
}

resource "null_resource" "tags_asg_propagate_false" {
Copy link
Member

Choose a reason for hiding this comment

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

here too :)

outputs.tf Outdated

description = "Normalized Tag map"
}

output "tags_asg_propagate_true" {
Copy link
Member

Choose a reason for hiding this comment

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

and here

@osterman
Copy link
Member

I think tags_as_list_of_maps is very descriptive, so I am okay with leaving it as-is.

Just wonder though if we should rename both outputs for consistency:

tags_map - returns map of tags
tags_list - returns list of tag maps

@aknysh thoughts?

@Jamie-BitFlight
Copy link
Contributor Author

If you change tags to tags_map it wont be backwards compatible.

@osterman osterman changed the title Updated so that the null_resource provider is used for autoscaling tags, and locals for standard tags Add Support for List of Tag Maps May 15, 2018
@osterman osterman added the enhancement New feature or request label May 15, 2018
######################
# Autoscaling group #
######################
resource "aws_autoscaling_group" "this" {
Copy link
Member

Choose a reason for hiding this comment

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

We typically use default in place of this. Using this is also a good convention, but let's stick with default since that's what we have else where.

@osterman
Copy link
Member

@aknysh LGTM; one small nitpick on this vs default.

source = "../../"
namespace = "awesomeproject"
stage = "production"
name = "clusterpluck"
Copy link
Member

Choose a reason for hiding this comment

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

does not sound good.
please use our standard conventions:

namespace = "cp"
stage     = "prod"
name      = "app"

README.md Outdated
@@ -121,6 +121,93 @@ resource "aws_instance" "eg_prod_bastion_xyz" {
vpc_security_group_ids = ["${aws_security_group.eg_prod_bastion_xyz.id}"]
}
```
### Advanced Example 2

Here is a more complex example with an autoscaling group that has a different tagging schema than other resources and requres its tags to be in this format, which this module can generate:
Copy link
Member

Choose a reason for hiding this comment

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

typo in requres

README.md Outdated
source = "../../"
namespace = "awesomeproject"
stage = "production"
name = "clusterpluck"
Copy link
Member

Choose a reason for hiding this comment

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

does not sound good.
please use our standard conventions:

namespace = "cp"
stage     = "prod"
name      = "app"

README.md Outdated
]
```

Autoscaling group using proagating tagging below (full example: examples/autoscalinggroup/main.tf)
Copy link
Member

Choose a reason for hiding this comment

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

typo in proagating

README.md Outdated
#######################
# Launch template #
#######################
resource "aws_launch_template" "this" {
Copy link
Member

Choose a reason for hiding this comment

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

change this to default as it's used in all CloudPosse modules

README.md Outdated
######################
# Autoscaling group #
######################
resource "aws_autoscaling_group" "this" {
Copy link
Member

Choose a reason for hiding this comment

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

change this to default as it's used in all CloudPosse modules

outputs.tf Outdated

output "tags_as_list_of_maps" {
value = ["${local.tags_as_list_of_maps}"]
description = "Additional tags as a list of maps. Which can be used in several resources."
Copy link
Member

Choose a reason for hiding this comment

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

Additional tags as a list of maps, which can be used in several AWS resources

variables.tf Outdated
@@ -32,3 +32,9 @@ variable "tags" {
default = {}
description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)"
Copy link
Member

Choose a reason for hiding this comment

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

please also update the quotes
Additional tags (e.g. map('BusinessUnit','XYZ'))

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@Jamie-BitFlight
thanks
we are close, just a few comments

Jamie Nelson added 2 commits May 16, 2018 01:48
@Jamie-BitFlight
Copy link
Contributor Author

Those have been addressed @aknysh

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

+1

@aknysh aknysh merged commit 70a6ecf into cloudposse:master May 16, 2018
@aknysh
Copy link
Member

aknysh commented May 16, 2018

@Jamie-BitFlight
thanks a lot for your contribution.
merged to master

@Jamie-BitFlight
Copy link
Contributor Author

Thanks for working with me on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants