Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change service account IAM management to be additive #17

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,13 @@ resource "google_project_iam_member" "gsuite_group_role" {
/******************************************
Granting serviceAccountUser to group
*****************************************/
resource "google_service_account_iam_binding" "service_account_grant_to_group" {
resource "google_service_account_iam_member" "service_account_grant_to_group" {
count = "${local.gsuite_group ? 1 : 0}"

service_account_id = "projects/${local.project_id}/serviceAccounts/${google_service_account.default_service_account.email}"
role = "roles/iam.serviceAccountUser"

members = [
"${data.null_data_source.data_group_email_format.outputs["group_fmt"]}",
]
member = "${data.null_data_source.data_group_email_format.outputs["group_fmt"]}"
}

/*************************************************************************************
Expand Down
26 changes: 26 additions & 0 deletions test/integration/gcloud/integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@
gcloud --quiet iam service-accounts delete "$SA_EMAIL" --project "$PROJECT_ID"
}

@test "Confirm Terraform service account IAM membership is additive" {
if [ "$GROUP_NAME" == "" -o "$CREATE_GROUP" != "true" ]; then
skip "GROUP_NAME is unset and CREATE_GROUP is false, skipping service account IAM management test"
fi

MANAGED_SA_EMAIL="$(terraform output service_account_email)"

PROJECT_ID="$(terraform output project_info_example)"
SA_ID="sa-${RANDOM}"
SA_EMAIL="${SA_ID}@${PROJECT_ID}.iam.gserviceaccount.com"

gcloud iam service-accounts create "$SA_ID" \
--project "$PROJECT_ID"

gcloud iam service-accounts add-iam-policy-binding \
$MANAGED_SA_EMAIL \
--member "serviceAccount:${SA_EMAIL}" \
--role "roles/iam.serviceAccountUser"

run terraform plan
[[ "$output" =~ No\ changes ]]

# tear down test iam account
gcloud --quiet iam service-accounts delete "$SA_EMAIL" --project "$PROJECT_ID"
}

@test "Test App Engine app created with the correct settings" {

PROJECT_ID="$(terraform output project_info_example)"
Expand Down
4 changes: 4 additions & 0 deletions test/integration/gcloud/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ output "domain_example" {
output "group_email_example" {
value = "${module.project-factory.group_email}"
}

output "service_account_email" {
value = "${module.project-factory.service_account_email}"
}
EOF
}

Expand Down