Last Updated Oct 9, 2023
Before we can scan your infrastructure, our service account needs access to read limited metadata from your Google Cloud environment. You must grant us permissions via IAM and retain full control over what we can access and when.
The list of required permissions are:
$ export PROJECT_ID="<your-project-id>"
$ export PRINCIPAL="serviceAccount:<unique email generated for you by DeclutterGCP>"
$ export ROLE_NAME="DeclutterGCP_Images"
$ export PERMISSIONS="compute.images.list,compute.disks.list,compute.images.delete"
//
// create a role containing the permissions we need
$ gcloud iam roles create "$ROLE_NAME" --project=$PROJECT_ID --title="$ROLE_NAME" \
--permissions="$PERMISSIONS" --description="Used to analyse and recover custom VM image costs"
//
// grant the role to the DeclutterGCP service account
$ gcloud projects add-iam-policy-binding "$PROJECT_ID" \
--member="$PRINCIPAL" --role="projects/$PROJECT_ID/roles/$ROLE_NAME"
locals {
project = "<replace-with-project-id>"
declutter_member = "serviceAccount:<replace-with-email-supplied-by-us>"
}
resource "google_project_iam_custom_role" "decluttergcp_image_cleanup" {
role_id = "declutter.cleanup.images"
permissions = [
"compute.images.list",
"compute.disks.list",
"compute.images.delete",
]
title = "DeclutterGCP Custom Role"
description = "These permissions are required to scan & delete custom VM images from Compute Engine"
}
resource "google_project_iam_member" "assign_decluttergcp_role" {
role = "projects/${local.project}/roles/${google_project_iam_custom_role.decluttergcp_image_cleanup.role_id}"
member = local.declutter_member
project = local.project
}