-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdisco.tf
40 lines (36 loc) · 1.7 KB
/
disco.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
---------------------------------------------------------|------------------------------------------------------------
Discovery
Some common discovery stuff for the module.
---------------------------------------------------------|------------------------------------------------------------
*/
# discover the calling user; the resulting account is the builder =
data "aws_caller_identity" "found" {}
/*
---------------------------------------------------------|------------------------------------------------------------
Partition
Automatically discover which partition we're in:
* Commercial: aws
* China: aws-cn
* GovCloud: aws-us-gov
AWS: https://docs.aws.amazon.com/whitepapers/latest/aws-fault-isolation-boundaries/partitions.html
HTF: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition
---------------------------------------------------------|------------------------------------------------------------
*/
data "aws_partition" "found" {}
/*
---------------------------------------------------------|------------------------------------------------------------
Locals
Make the assignment for variable distribution.
---------------------------------------------------------|------------------------------------------------------------
*/
locals {
part = data.aws_partition.found.partition
builder = regex("arn:${local.part}:iam::\\d+:user/(.*)", data.aws_caller_identity.found.arn)[0]
}
output "partition" {
value = local.part
}
output "iam_user" {
value = local.builder
}