@@ -2,10 +2,14 @@ provider "aws" {
2
2
region = local. region
3
3
}
4
4
5
+ data "aws_caller_identity" "current" {}
6
+
5
7
locals {
6
- region = " us-east-1"
7
- replica_region = " eu-west-1"
8
- name = " kms-ex-${ replace (basename (path. cwd ), " _" , " -" )} "
8
+ region = " us-east-1"
9
+ replica_region = " eu-west-1"
10
+ name = " kms-ex-${ replace (basename (path. cwd ), " _" , " -" )} "
11
+
12
+ account_id = data. aws_caller_identity . current . account_id
9
13
current_identity = data. aws_caller_identity . current . arn
10
14
11
15
tags = {
@@ -15,12 +19,6 @@ locals {
15
19
}
16
20
}
17
21
18
- data "aws_caller_identity" "current" {}
19
- data "aws_region" "current" {}
20
- data "aws_region" "replica" {
21
- region = local. region
22
- }
23
-
24
22
# ###############################################################################
25
23
# KMS Module
26
24
# ###############################################################################
@@ -41,7 +39,7 @@ module "kms_complete" {
41
39
key_administrators = [local . current_identity ]
42
40
key_users = [local . current_identity ]
43
41
key_service_users = [local . current_identity ]
44
- key_service_roles_for_autoscaling = [" arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" ]
42
+ key_service_roles_for_autoscaling = [" arn:aws:iam::${ local . account_id } :role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" ]
45
43
key_symmetric_encryption_users = [local . current_identity ]
46
44
key_hmac_users = [local . current_identity ]
47
45
key_asymmetric_public_encryption_users = [local . current_identity ]
@@ -61,7 +59,7 @@ module "kms_complete" {
61
59
principals = [
62
60
{
63
61
type = " Service"
64
- identifiers = [" logs.${ data . aws_region . current . region } .amazonaws.com" ]
62
+ identifiers = [" logs.${ local . region } .amazonaws.com" ]
65
63
}
66
64
]
67
65
@@ -70,7 +68,7 @@ module "kms_complete" {
70
68
test = " ArnLike"
71
69
variable = " kms:EncryptionContext:aws:logs:arn"
72
70
values = [
73
- " arn:aws:logs:${ local . region } :${ data . aws_caller_identity . current . account_id } :log-group:*" ,
71
+ " arn:aws:logs:${ local . region } :${ local . account_id } :log-group:*" ,
74
72
]
75
73
}
76
74
]
@@ -124,7 +122,7 @@ module "kms_complete_other_region" {
124
122
key_administrators = [local . current_identity ]
125
123
key_users = [local . current_identity ]
126
124
key_service_users = [local . current_identity ]
127
- key_service_roles_for_autoscaling = [" arn:aws:iam::${ data . aws_caller_identity . current . account_id } :role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" ]
125
+ key_service_roles_for_autoscaling = [" arn:aws:iam::${ local . account_id } :role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" ]
128
126
key_symmetric_encryption_users = [local . current_identity ]
129
127
key_hmac_users = [local . current_identity ]
130
128
key_asymmetric_public_encryption_users = [local . current_identity ]
@@ -144,7 +142,7 @@ module "kms_complete_other_region" {
144
142
principals = [
145
143
{
146
144
type = " Service"
147
- identifiers = [" logs.${ data . aws_region . replica . region } .amazonaws.com" ]
145
+ identifiers = [" logs.${ local . replica_region } .amazonaws.com" ]
148
146
}
149
147
]
150
148
@@ -153,7 +151,7 @@ module "kms_complete_other_region" {
153
151
test = " ArnLike"
154
152
variable = " kms:EncryptionContext:aws:logs:arn"
155
153
values = [
156
- " arn:aws:logs:${ local . replica_region } :${ data . aws_caller_identity . current . account_id } :log-group:*" ,
154
+ " arn:aws:logs:${ local . replica_region } :${ local . account_id } :log-group:*" ,
157
155
]
158
156
}
159
157
]
@@ -231,8 +229,8 @@ module "kms_dnssec_signing" {
231
229
enable_key_rotation = false
232
230
route53_dnssec_sources = [
233
231
{
234
- accounts_ids = [data.aws_caller_identity.current. account_id] # can ommit if using current account ID which is default
235
- hosted_zone_arn = " arn:aws:route53:::hostedzone/*" # can ommit, this is default value
232
+ accounts_ids = [local. account_id] # can ommit if using current account ID which is default
233
+ hosted_zone_arn = " arn:aws:route53:::hostedzone/*" # can ommit, this is default value
236
234
}
237
235
]
238
236
@@ -253,8 +251,8 @@ module "kms_dnssec_signing_other_region" {
253
251
enable_key_rotation = false
254
252
route53_dnssec_sources = [
255
253
{
256
- accounts_ids = [data.aws_caller_identity.current. account_id] # can ommit if using current account ID which is default
257
- hosted_zone_arn = " arn:aws:route53:::hostedzone/*" # can ommit, this is default value
254
+ accounts_ids = [local. account_id] # can ommit if using current account ID which is default
255
+ hosted_zone_arn = " arn:aws:route53:::hostedzone/*" # can ommit, this is default value
258
256
}
259
257
]
260
258
region = local. replica_region
0 commit comments