@@ -27,7 +27,7 @@ resource "google_service_account" "onboarding_auth" {
2727}
2828
2929resource "google_service_account_iam_binding" "onboarding_auth_binding" {
30- service_account_id = google_service_account. push_auth . name
30+ service_account_id = google_service_account. onboarding_auth . name
3131 role = " roles/iam.workloadIdentityUser"
3232
3333 members = [
@@ -65,30 +65,14 @@ resource "google_iam_workload_identity_pool_provider" "onboarding_auth_pool_prov
6565 }
6666}
6767
68- # creating custom role with project-level permissions to access onboarding resources
69- resource "google_project_iam_custom_role" "custom_onboarding_auth_role" {
70- count = var. is_organizational ? 0 : 1
71-
72- project = var. project_id
73- role_id = var. role_name
74- title = " Sysdigcloud Onboarding Auth Role"
75- description = " A Role providing the required permissions for Sysdig Backend to read cloud resources created for onboarding"
76- permissions = [
77- " pubsub.topics.get" ,
78- " pubsub.topics.list" ,
79- " pubsub.subscriptions.get" ,
80- " pubsub.subscriptions.list" ,
81- " logging.sinks.get" ,
82- " logging.sinks.list" ,
83- ]
84- }
85-
86- # adding custom role with project-level permissions to the service account for auth
87- resource "google_project_iam_member" "custom" {
68+ # ---------------------------------
69+ # role permissions for onboarding
70+ # ---------------------------------
71+ resource "google_project_iam_member" "browser" {
8872 count = var. is_organizational ? 0 : 1
8973
9074 project = var. project_id
91- role = google_project_iam_custom_role . custom_onboarding_auth_role [ 0 ] . id
75+ role = " roles/browser "
9276 member = " serviceAccount:${ google_service_account . onboarding_auth . email } "
9377}
9478
@@ -97,4 +81,44 @@ resource "google_service_account_iam_member" "custom_auth" {
9781 service_account_id = google_service_account. onboarding_auth . name
9882 role = " roles/iam.workloadIdentityUser"
9983 member = " principalSet://iam.googleapis.com/projects/${ data . google_project . project . number } /locations/global/workloadIdentityPools/${ google_iam_workload_identity_pool . onboarding_auth_pool . workload_identity_pool_id } /attribute.aws_role/arn:aws:sts::${ data . sysdig_secure_trusted_cloud_identity . trusted_identity . aws_account_id } :assumed-role/${ data . sysdig_secure_trusted_cloud_identity . trusted_identity . aws_role_name } /${ var . external_id } "
84+ }
85+
86+ # ---------------------------------------------------------------------------------------------
87+ # Call Sysdig Backend to create account with foundational onboarding
88+ # (ensure it is called after all above cloud resources are created using explicit depends_on)
89+ # ---------------------------------------------------------------------------------------------
90+
91+ resource "sysdig_secure_cloud_auth_account" "google_account" {
92+ enabled = true
93+ provider_id = var. project_id
94+ provider_type = " PROVIDER_GCP"
95+ provider_alias = data. google_project . project . name
96+ provider_tenant_id = var. organization_domain
97+
98+ component {
99+ type = " COMPONENT_SERVICE_PRINCIPAL"
100+ instance = " secure-onboarding"
101+ version = " v0.1.0"
102+ service_principal_metadata = jsonencode ({
103+ gcp = {
104+ service_principal = {
105+ workload_identity_federation = {
106+ pool_id = google_iam_workload_identity_pool.onboarding_auth_pool.workload_identity_pool_id
107+ pool_provider_id = google_iam_workload_identity_pool_provider.onboarding_auth_pool_provider.workload_identity_pool_provider_id
108+ project_number = data.google_project.project.number
109+ }
110+ email = google_service_account.onboarding_auth.email
111+ }
112+ }
113+ })
114+ }
115+
116+ depends_on = [google_service_account_iam_member . custom_auth ]
117+
118+ lifecycle {
119+ ignore_changes = [
120+ component ,
121+ feature
122+ ]
123+ }
100124}
0 commit comments