Skip to content

Commit f5c4c6b

Browse files
StephenTan-TWnitrocodecloudpossebot
authored
Correct the ARN string, also fix the tag sets and allow tag filters as per the api (#9)
* Use the correct the lookup map object * Remove list of lists * Add lookups again * Fix ARN typo * Change ec2_tag_set and ec2_tag_filter stuctures * Fix missing bracket * Linting * Auto Format * The format of the ARNs is not consistent across platforms. Fixed. * Conform to the Cloud Posse syntax, add some comments and remove commented out crap * Tidy up variables documentation * Auto Format * Update main.tf Co-authored-by: nitrocode <[email protected]> * Update main.tf Co-authored-by: nitrocode <[email protected]> * Allow the correct AWS partition to be selected automagically * Auto Format * Adding enabled logic for the aws_partition data * Update main.tf Co-authored-by: nitrocode <[email protected]> Co-authored-by: cloudpossebot <[email protected]>
1 parent 0bc9955 commit f5c4c6b

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Available targets:
160160
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
161161
| [aws_iam_role_policy_attachment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
162162
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
163+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
163164

164165
## Inputs
165166

@@ -177,7 +178,8 @@ Available targets:
177178
| <a name="input_create_default_sns_topic"></a> [create\_default\_sns\_topic](#input\_create\_default\_sns\_topic) | Whether to create default SNS topic through which notifications are sent. | `bool` | `true` | no |
178179
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
179180
| <a name="input_deployment_style"></a> [deployment\_style](#input\_deployment\_style) | Configuration of the type of deployment, either in-place or blue/green, <br>you want to run and whether to route deployment traffic behind a load balancer.<br><br>deployment\_option:<br> Indicates whether to route deployment traffic behind a load balancer. <br> Possible values: `WITH_TRAFFIC_CONTROL`, `WITHOUT_TRAFFIC_CONTROL`.<br>deployment\_type:<br> Indicates whether to run an in-place deployment or a blue/green deployment.<br> Possible values: `IN_PLACE`, `BLUE_GREEN`. | <pre>object({<br> deployment_option = string<br> deployment_type = string<br> })</pre> | `null` | no |
180-
| <a name="input_ec2_tag_filter"></a> [ec2\_tag\_filter](#input\_ec2\_tag\_filter) | A list of sets of tag filters. If multiple tag groups are specified, <br>any instance that matches to at least one tag filter of every tag group is selected.<br><br>key:<br> The key of the tag filter.<br>type:<br> The type of the tag filter, either `KEY_ONLY`, `VALUE_ONLY`, or `KEY_AND_VALUE`.<br>value:<br> The value of the tag filter. | <pre>list(object({<br> key = string<br> type = string<br> value = string<br> }))</pre> | `null` | no |
181+
| <a name="input_ec2_tag_filter"></a> [ec2\_tag\_filter](#input\_ec2\_tag\_filter) | The Amazon EC2 tags on which to filter. The deployment group includes EC2 instances with any of the specified tags.<br>Cannot be used in the same call as ec2TagSet. | <pre>set(object({<br> key = string<br> type = string<br> value = string<br> }))</pre> | `[]` | no |
182+
| <a name="input_ec2_tag_set"></a> [ec2\_tag\_set](#input\_ec2\_tag\_set) | A list of sets of tag filters. If multiple tag groups are specified,<br>any instance that matches to at least one tag filter of every tag group is selected.<br><br>key:<br> The key of the tag filter.<br>type:<br> The type of the tag filter, either `KEY_ONLY`, `VALUE_ONLY`, or `KEY_AND_VALUE`.<br>value:<br> The value of the tag filter. | <pre>set(object(<br> {<br> ec2_tag_filter = set(object(<br> {<br> key = string<br> type = string<br> value = string<br> }<br> ))<br> }<br> ))</pre> | `[]` | no |
181183
| <a name="input_ecs_service"></a> [ecs\_service](#input\_ecs\_service) | Configuration block(s) of the ECS services for a deployment group.<br><br>cluster\_name:<br> The name of the ECS cluster. <br>service\_name:<br> The name of the ECS service. | <pre>list(object({<br> cluster_name = string<br> service_name = string<br> }))</pre> | `null` | no |
182184
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
183185
| <a name="input_environment"></a> [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |

docs/terraform.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
3131
| [aws_iam_role_policy_attachment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
3232
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
33+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
3334

3435
## Inputs
3536

@@ -47,7 +48,8 @@
4748
| <a name="input_create_default_sns_topic"></a> [create\_default\_sns\_topic](#input\_create\_default\_sns\_topic) | Whether to create default SNS topic through which notifications are sent. | `bool` | `true` | no |
4849
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
4950
| <a name="input_deployment_style"></a> [deployment\_style](#input\_deployment\_style) | Configuration of the type of deployment, either in-place or blue/green, <br>you want to run and whether to route deployment traffic behind a load balancer.<br><br>deployment\_option:<br> Indicates whether to route deployment traffic behind a load balancer. <br> Possible values: `WITH_TRAFFIC_CONTROL`, `WITHOUT_TRAFFIC_CONTROL`.<br>deployment\_type:<br> Indicates whether to run an in-place deployment or a blue/green deployment.<br> Possible values: `IN_PLACE`, `BLUE_GREEN`. | <pre>object({<br> deployment_option = string<br> deployment_type = string<br> })</pre> | `null` | no |
50-
| <a name="input_ec2_tag_filter"></a> [ec2\_tag\_filter](#input\_ec2\_tag\_filter) | A list of sets of tag filters. If multiple tag groups are specified, <br>any instance that matches to at least one tag filter of every tag group is selected.<br><br>key:<br> The key of the tag filter.<br>type:<br> The type of the tag filter, either `KEY_ONLY`, `VALUE_ONLY`, or `KEY_AND_VALUE`.<br>value:<br> The value of the tag filter. | <pre>list(object({<br> key = string<br> type = string<br> value = string<br> }))</pre> | `null` | no |
51+
| <a name="input_ec2_tag_filter"></a> [ec2\_tag\_filter](#input\_ec2\_tag\_filter) | The Amazon EC2 tags on which to filter. The deployment group includes EC2 instances with any of the specified tags.<br>Cannot be used in the same call as ec2TagSet. | <pre>set(object({<br> key = string<br> type = string<br> value = string<br> }))</pre> | `[]` | no |
52+
| <a name="input_ec2_tag_set"></a> [ec2\_tag\_set](#input\_ec2\_tag\_set) | A list of sets of tag filters. If multiple tag groups are specified,<br>any instance that matches to at least one tag filter of every tag group is selected.<br><br>key:<br> The key of the tag filter.<br>type:<br> The type of the tag filter, either `KEY_ONLY`, `VALUE_ONLY`, or `KEY_AND_VALUE`.<br>value:<br> The value of the tag filter. | <pre>set(object(<br> {<br> ec2_tag_filter = set(object(<br> {<br> key = string<br> type = string<br> value = string<br> }<br> ))<br> }<br> ))</pre> | `[]` | no |
5153
| <a name="input_ecs_service"></a> [ecs\_service](#input\_ecs\_service) | Configuration block(s) of the ECS services for a deployment group.<br><br>cluster\_name:<br> The name of the ECS cluster. <br>service\_name:<br> The name of the ECS service. | <pre>list(object({<br> cluster_name = string<br> service_name = string<br> }))</pre> | `null` | no |
5254
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
5355
| <a name="input_environment"></a> [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |

main.tf

+30-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ locals {
1414
default_service_role_enabled = local.enabled && var.create_default_service_role
1515
default_service_role_count = local.default_service_role_enabled ? 1 : 0
1616
service_role_arn = local.default_service_role_enabled ? join("", aws_iam_role.default.*.arn) : var.service_role_arn
17-
default_policy_name = {
18-
Server = "AWSCodeDeployRole"
19-
Lambda = "AWSCodeDeployRoleForLambda"
20-
ECS = "AWSCodeDeployRoleForECS"
17+
default_policy_arn = {
18+
Server = "arn:${join("", data.aws_partition.current.*.partition)}:iam::aws:policy/service-role/AWSCodeDeployRole"
19+
Lambda = "arn:${join("", data.aws_partition.current.*.partition)}:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda"
20+
ECS = "arn:${join("", data.aws_partition.current.*.partition)}:iam::aws:policy/AWSCodeDeployRoleForECS"
2121
}
2222
}
2323

@@ -35,6 +35,10 @@ data "aws_iam_policy_document" "assume_role" {
3535
}
3636
}
3737

38+
data "aws_partition" "current" {
39+
count = local.default_service_role_count
40+
}
41+
3842
resource "aws_iam_role" "default" {
3943
count = local.default_service_role_count
4044
name = module.this.id
@@ -44,7 +48,7 @@ resource "aws_iam_role" "default" {
4448

4549
resource "aws_iam_role_policy_attachment" "default" {
4650
count = local.default_service_role_count
47-
policy_arn = format("arn:aws:iam::aws:policy/%s", lookup(local.default_policy_name, var.compute_platform))
51+
policy_arn = format("%s", lookup(local.default_policy_arn, var.compute_platform))
4852
role = join("", aws_iam_role.default.*.name)
4953
}
5054

@@ -171,14 +175,30 @@ resource "aws_codedeploy_deployment_group" "default" {
171175
}
172176
}
173177

178+
# Note that you cannot have both ec_tag_filter and ec2_tag_set vars set!
179+
# See https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html for details
180+
dynamic "ec2_tag_filter" {
181+
for_each = length(var.ec2_tag_filter) > 0 ? [] : var.ec2_tag_filter
182+
content {
183+
key = ec2_tag_filter.value["key"]
184+
type = ec2_tag_filter.value["type"]
185+
value = ec2_tag_filter.value["value"]
186+
}
187+
}
188+
189+
# Note that you cannot have both ec_tag_filter and ec2_tag_set vars set!
190+
# See https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html for details
174191
dynamic "ec2_tag_set" {
175-
for_each = var.ec2_tag_filter == null ? [] : var.ec2_tag_filter
192+
for_each = length(var.ec2_tag_set) > 0 ? [] : var.ec2_tag_set
176193

177194
content {
178-
ec2_tag_filter {
179-
key = lookup(ec2_tag_set.value, "key", null)
180-
type = lookup(ec2_tag_set.value, "type", null)
181-
value = lookup(ec2_tag_set.value, "value", null)
195+
dynamic "ec2_tag_filter" {
196+
for_each = ec2_tag_set.value.ec2_tag_filter
197+
content {
198+
key = ec2_tag_filter.value["key"]
199+
type = ec2_tag_filter.value["type"]
200+
value = ec2_tag_filter.value["value"]
201+
}
182202
}
183203
}
184204
}

variables.tf

+22-3
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,33 @@ variable "deployment_style" {
118118
}
119119

120120
variable "ec2_tag_filter" {
121-
type = list(object({
121+
type = set(object({
122122
key = string
123123
type = string
124124
value = string
125125
}))
126-
default = null
126+
default = []
127+
description = <<-DOC
128+
The Amazon EC2 tags on which to filter. The deployment group includes EC2 instances with any of the specified tags.
129+
Cannot be used in the same call as ec2TagSet.
130+
DOC
131+
}
132+
133+
variable "ec2_tag_set" {
134+
type = set(object(
135+
{
136+
ec2_tag_filter = set(object(
137+
{
138+
key = string
139+
type = string
140+
value = string
141+
}
142+
))
143+
}
144+
))
145+
default = []
127146
description = <<-DOC
128-
A list of sets of tag filters. If multiple tag groups are specified,
147+
A list of sets of tag filters. If multiple tag groups are specified,
129148
any instance that matches to at least one tag filter of every tag group is selected.
130149
131150
key:

0 commit comments

Comments
 (0)