-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
103 lines (81 loc) · 3.6 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
terraform {
# Requiring Providers
# https://www.terraform.io/language/providers/requirements#requiring-providers
required_providers {
# Datadog Provider
# https://registry.terraform.io/providers/DataDog/datadog/latest/docs
datadog = {
source = "datadog/datadog"
}
# Google Cloud Platform Provider
# https://registry.terraform.io/providers/hashicorp/google/latest/docs
google = {
source = "hashicorp/google"
}
}
}
provider "datadog" {
api_key = var.datadog_api_key
app_key = var.datadog_app_key
}
# Datadog Google Cloud Platform Integration Module (osinfra.io)
# https://github.com/osinfra-io/terraform-datadog-google-integration
module "datadog" {
source = "github.com/osinfra-io/terraform-datadog-google-integration?ref=v0.3.5"
count = var.datadog_enable ? 1 : 0
api_key = var.datadog_api_key
is_cspm_enabled = true
is_security_command_center_enabled = true
labels = module.helpers.labels
project = module.project.id
}
# Google Project Module (osinfra.io)
# https://github.com/osinfra-io/terraform-google-project
module "project" {
source = "github.com/osinfra-io/terraform-google-project?ref=v0.4.5"
billing_account = var.project_billing_account
cis_2_2_logging_sink_project_id = var.project_cis_2_2_logging_sink_project_id
description = "identity"
folder_id = var.project_folder_id
labels = module.helpers.labels
prefix = "plt-lz"
services = [
"cloudasset.googleapis.com",
"cloudbilling.googleapis.com",
"cloudresourcemanager.googleapis.com",
"compute.googleapis.com",
"iam.googleapis.com",
"iamcredentials.googleapis.com",
"monitoring.googleapis.com",
"sts.googleapis.com"
]
}
# To avoid subject collisions, we are using a single provider per workload identity pool.
# https://cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation#avoid-subject-collisions
# IAM Workload Identity Pool Resource
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool
resource "google_iam_workload_identity_pool" "this" {
for_each = local.workload_identity
description = "Workload Identity Pool for ${each.value.display_name}"
disabled = lookup(each.value, "disabled", false)
display_name = each.value.display_name
project = module.project.id
workload_identity_pool_id = each.key
}
# IAM Workload Identity Pool Provider Resource
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/iam_workload_identity_pool_provider
resource "google_iam_workload_identity_pool_provider" "this" {
for_each = local.workload_identity
attribute_condition = each.value.attribute_condition
attribute_mapping = each.value.attribute_mapping
description = "Workload Identity Pool Provider for ${each.value.display_name}"
disabled = lookup(each.value, "disabled", false)
display_name = "${each.value.display_name} OIDC"
project = module.project.id
workload_identity_pool_id = google_iam_workload_identity_pool.this[each.key].workload_identity_pool_id
workload_identity_pool_provider_id = "${each.key}-oidc"
oidc {
allowed_audiences = lookup(each.value, "allowed_audiences", [])
issuer_uri = each.value.issuer_uri
}
}