GoogleCloudPlatform / deploymentmanager-samples

Deployment Manager samples and templates.
Apache License 2.0
940 stars 717 forks source link

How to assign roles to service account using jinja & YAML file #679

Open ajeshsuseelan opened 2 years ago

ajeshsuseelan commented 2 years ago

Hi,

As per below document, I have created Jinja and Yaml file for assigning different roles to service account.

https://github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/google/resource-snippets/cloudresourcemanager-v1/virtualProjectMember.yaml

My code:

test1.yaml

imports:

resources:

policies.jinja

resources: {% set resource = properties.get("resource", env["project"]) %} {% set project = properties["projectName"] %} {% set type = resource.split("/", 1)[0] if "/" in resource else "projects" %} {% set apiVersion = "v2" if type == "folders" else "v1" %} {% for role in properties["roles"] %} {% for serviceAccount in properties["serviceAccounts"] %}

When I tired to execute the below template in deployment manager it's getting failed due to below error:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1642430647081-5d5c82f49988d-b159f25f-cbfa46a1]: errors:

Please suggest.

sandyydk commented 2 years ago

Facing issue doing the same with conditional access. Can anyone clarify on the same?

sandyydk commented 2 years ago

@ajeshsuseelan It might be that your service is not part of the given organization's conditions? I believe there is some policy blocking or allowing only those users with certain parameters to be allowed access. Maybe this user does not belong or clear those policies.