@@ -2,10 +2,14 @@ provider "aws" {
22 region = local. region
33}
44
5+ data "aws_caller_identity" "current" {}
6+
57locals {
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
913 current_identity = data. aws_caller_identity . current . arn
1014
1115 tags = {
@@ -15,12 +19,6 @@ locals {
1519 }
1620}
1721
18- data "aws_caller_identity" "current" {}
19- data "aws_region" "current" {}
20- data "aws_region" "replica" {
21- region = local. region
22- }
23-
2422# ###############################################################################
2523# KMS Module
2624# ###############################################################################
@@ -41,7 +39,7 @@ module "kms_complete" {
4139 key_administrators = [local . current_identity ]
4240 key_users = [local . current_identity ]
4341 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" ]
4543 key_symmetric_encryption_users = [local . current_identity ]
4644 key_hmac_users = [local . current_identity ]
4745 key_asymmetric_public_encryption_users = [local . current_identity ]
@@ -61,7 +59,7 @@ module "kms_complete" {
6159 principals = [
6260 {
6361 type = " Service"
64- identifiers = [" logs.${ data . aws_region . current . region } .amazonaws.com" ]
62+ identifiers = [" logs.${ local . region } .amazonaws.com" ]
6563 }
6664 ]
6765
@@ -70,7 +68,7 @@ module "kms_complete" {
7068 test = " ArnLike"
7169 variable = " kms:EncryptionContext:aws:logs:arn"
7270 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:*" ,
7472 ]
7573 }
7674 ]
@@ -124,7 +122,7 @@ module "kms_complete_other_region" {
124122 key_administrators = [local . current_identity ]
125123 key_users = [local . current_identity ]
126124 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" ]
128126 key_symmetric_encryption_users = [local . current_identity ]
129127 key_hmac_users = [local . current_identity ]
130128 key_asymmetric_public_encryption_users = [local . current_identity ]
@@ -144,7 +142,7 @@ module "kms_complete_other_region" {
144142 principals = [
145143 {
146144 type = " Service"
147- identifiers = [" logs.${ data . aws_region . replica . region } .amazonaws.com" ]
145+ identifiers = [" logs.${ local . replica_region } .amazonaws.com" ]
148146 }
149147 ]
150148
@@ -153,7 +151,7 @@ module "kms_complete_other_region" {
153151 test = " ArnLike"
154152 variable = " kms:EncryptionContext:aws:logs:arn"
155153 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:*" ,
157155 ]
158156 }
159157 ]
@@ -231,8 +229,8 @@ module "kms_dnssec_signing" {
231229 enable_key_rotation = false
232230 route53_dnssec_sources = [
233231 {
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
236234 }
237235 ]
238236
@@ -253,8 +251,8 @@ module "kms_dnssec_signing_other_region" {
253251 enable_key_rotation = false
254252 route53_dnssec_sources = [
255253 {
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
258256 }
259257 ]
260258 region = local. replica_region
0 commit comments