1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. projects
  5. DefaultServiceAccounts
Google Cloud v8.26.0 published on Thursday, Apr 10, 2025 by Pulumi

gcp.projects.DefaultServiceAccounts

Explore with Pulumi AI

Allows management of Google Cloud Platform project default service accounts.

When certain service APIs are enabled, Google Cloud Platform automatically creates service accounts to help get started, but this is not recommended for production environments as per Google’s documentation. See the Organization documentation for more details.

WARNING Some Google Cloud products do not work if the default service accounts are deleted so it is better to DEPRIVILEGE as Google CAN NOT recover service accounts that have been deleted for more than 30 days. Also Google recommends using the constraints/iam.automaticIamGrantsForDefaultServiceAccounts constraint to disable automatic IAM Grants to default service accounts.

This resource works on a best-effort basis, as no API formally describes the default service accounts and it is for users who are unable to use constraints. If the default service accounts change their name or additional service accounts are added, this resource will need to be updated.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const myProject = new gcp.projects.DefaultServiceAccounts("my_project", {
    project: "my-project-id",
    action: "DELETE",
});
Copy
import pulumi
import pulumi_gcp as gcp

my_project = gcp.projects.DefaultServiceAccounts("my_project",
    project="my-project-id",
    action="DELETE")
Copy
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/projects"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := projects.NewDefaultServiceAccounts(ctx, "my_project", &projects.DefaultServiceAccountsArgs{
			Project: pulumi.String("my-project-id"),
			Action:  pulumi.String("DELETE"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var myProject = new Gcp.Projects.DefaultServiceAccounts("my_project", new()
    {
        Project = "my-project-id",
        Action = "DELETE",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.projects.DefaultServiceAccounts;
import com.pulumi.gcp.projects.DefaultServiceAccountsArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var myProject = new DefaultServiceAccounts("myProject", DefaultServiceAccountsArgs.builder()
            .project("my-project-id")
            .action("DELETE")
            .build());

    }
}
Copy
resources:
  myProject:
    type: gcp:projects:DefaultServiceAccounts
    name: my_project
    properties:
      project: my-project-id
      action: DELETE
Copy

To enable the default service accounts on the resource destroy:

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const myProject = new gcp.projects.DefaultServiceAccounts("my_project", {
    project: "my-project-id",
    action: "DISABLE",
    restorePolicy: "REVERT",
});
Copy
import pulumi
import pulumi_gcp as gcp

my_project = gcp.projects.DefaultServiceAccounts("my_project",
    project="my-project-id",
    action="DISABLE",
    restore_policy="REVERT")
Copy
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/projects"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := projects.NewDefaultServiceAccounts(ctx, "my_project", &projects.DefaultServiceAccountsArgs{
			Project:       pulumi.String("my-project-id"),
			Action:        pulumi.String("DISABLE"),
			RestorePolicy: pulumi.String("REVERT"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var myProject = new Gcp.Projects.DefaultServiceAccounts("my_project", new()
    {
        Project = "my-project-id",
        Action = "DISABLE",
        RestorePolicy = "REVERT",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.projects.DefaultServiceAccounts;
import com.pulumi.gcp.projects.DefaultServiceAccountsArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var myProject = new DefaultServiceAccounts("myProject", DefaultServiceAccountsArgs.builder()
            .project("my-project-id")
            .action("DISABLE")
            .restorePolicy("REVERT")
            .build());

    }
}
Copy
resources:
  myProject:
    type: gcp:projects:DefaultServiceAccounts
    name: my_project
    properties:
      project: my-project-id
      action: DISABLE
      restorePolicy: REVERT
Copy

Create DefaultServiceAccounts Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new DefaultServiceAccounts(name: string, args: DefaultServiceAccountsArgs, opts?: CustomResourceOptions);
@overload
def DefaultServiceAccounts(resource_name: str,
                           args: DefaultServiceAccountsArgs,
                           opts: Optional[ResourceOptions] = None)

@overload
def DefaultServiceAccounts(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           action: Optional[str] = None,
                           project: Optional[str] = None,
                           restore_policy: Optional[str] = None)
func NewDefaultServiceAccounts(ctx *Context, name string, args DefaultServiceAccountsArgs, opts ...ResourceOption) (*DefaultServiceAccounts, error)
public DefaultServiceAccounts(string name, DefaultServiceAccountsArgs args, CustomResourceOptions? opts = null)
public DefaultServiceAccounts(String name, DefaultServiceAccountsArgs args)
public DefaultServiceAccounts(String name, DefaultServiceAccountsArgs args, CustomResourceOptions options)
type: gcp:projects:DefaultServiceAccounts
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. DefaultServiceAccountsArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. DefaultServiceAccountsArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. DefaultServiceAccountsArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. DefaultServiceAccountsArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. DefaultServiceAccountsArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var defaultServiceAccountsResource = new Gcp.Projects.DefaultServiceAccounts("defaultServiceAccountsResource", new()
{
    Action = "string",
    Project = "string",
    RestorePolicy = "string",
});
Copy
example, err := projects.NewDefaultServiceAccounts(ctx, "defaultServiceAccountsResource", &projects.DefaultServiceAccountsArgs{
	Action:        pulumi.String("string"),
	Project:       pulumi.String("string"),
	RestorePolicy: pulumi.String("string"),
})
Copy
var defaultServiceAccountsResource = new DefaultServiceAccounts("defaultServiceAccountsResource", DefaultServiceAccountsArgs.builder()
    .action("string")
    .project("string")
    .restorePolicy("string")
    .build());
Copy
default_service_accounts_resource = gcp.projects.DefaultServiceAccounts("defaultServiceAccountsResource",
    action="string",
    project="string",
    restore_policy="string")
Copy
const defaultServiceAccountsResource = new gcp.projects.DefaultServiceAccounts("defaultServiceAccountsResource", {
    action: "string",
    project: "string",
    restorePolicy: "string",
});
Copy
type: gcp:projects:DefaultServiceAccounts
properties:
    action: string
    project: string
    restorePolicy: string
Copy

DefaultServiceAccounts Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The DefaultServiceAccounts resource accepts the following input properties:

Action
This property is required.
Changes to this property will trigger replacement.
string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
Project
This property is required.
Changes to this property will trigger replacement.
string
The project ID where service accounts are created.
RestorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
Action
This property is required.
Changes to this property will trigger replacement.
string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
Project
This property is required.
Changes to this property will trigger replacement.
string
The project ID where service accounts are created.
RestorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
action
This property is required.
Changes to this property will trigger replacement.
String
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project
This property is required.
Changes to this property will trigger replacement.
String
The project ID where service accounts are created.
restorePolicy String
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
action
This property is required.
Changes to this property will trigger replacement.
string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project
This property is required.
Changes to this property will trigger replacement.
string
The project ID where service accounts are created.
restorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
action
This property is required.
Changes to this property will trigger replacement.
str
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project
This property is required.
Changes to this property will trigger replacement.
str
The project ID where service accounts are created.
restore_policy str
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
action
This property is required.
Changes to this property will trigger replacement.
String
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project
This property is required.
Changes to this property will trigger replacement.
String
The project ID where service accounts are created.
restorePolicy String
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.

Outputs

All input properties are implicitly available as output properties. Additionally, the DefaultServiceAccounts resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
ServiceAccounts Dictionary<string, string>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
Id string
The provider-assigned unique ID for this managed resource.
ServiceAccounts map[string]string
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
id String
The provider-assigned unique ID for this managed resource.
serviceAccounts Map<String,String>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
id string
The provider-assigned unique ID for this managed resource.
serviceAccounts {[key: string]: string}
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
id str
The provider-assigned unique ID for this managed resource.
service_accounts Mapping[str, str]
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
id String
The provider-assigned unique ID for this managed resource.
serviceAccounts Map<String>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.

Look up Existing DefaultServiceAccounts Resource

Get an existing DefaultServiceAccounts resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: DefaultServiceAccountsState, opts?: CustomResourceOptions): DefaultServiceAccounts
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        action: Optional[str] = None,
        project: Optional[str] = None,
        restore_policy: Optional[str] = None,
        service_accounts: Optional[Mapping[str, str]] = None) -> DefaultServiceAccounts
func GetDefaultServiceAccounts(ctx *Context, name string, id IDInput, state *DefaultServiceAccountsState, opts ...ResourceOption) (*DefaultServiceAccounts, error)
public static DefaultServiceAccounts Get(string name, Input<string> id, DefaultServiceAccountsState? state, CustomResourceOptions? opts = null)
public static DefaultServiceAccounts get(String name, Output<String> id, DefaultServiceAccountsState state, CustomResourceOptions options)
resources:  _:    type: gcp:projects:DefaultServiceAccounts    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Action Changes to this property will trigger replacement. string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
Project Changes to this property will trigger replacement. string
The project ID where service accounts are created.
RestorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
ServiceAccounts Dictionary<string, string>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
Action Changes to this property will trigger replacement. string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
Project Changes to this property will trigger replacement. string
The project ID where service accounts are created.
RestorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
ServiceAccounts map[string]string
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
action Changes to this property will trigger replacement. String
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project Changes to this property will trigger replacement. String
The project ID where service accounts are created.
restorePolicy String
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
serviceAccounts Map<String,String>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
action Changes to this property will trigger replacement. string
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project Changes to this property will trigger replacement. string
The project ID where service accounts are created.
restorePolicy string
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
serviceAccounts {[key: string]: string}
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
action Changes to this property will trigger replacement. str
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project Changes to this property will trigger replacement. str
The project ID where service accounts are created.
restore_policy str
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
service_accounts Mapping[str, str]
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.
action Changes to this property will trigger replacement. String
The action to be performed in the default service accounts. Valid values are: DEPRIVILEGE, DELETE, DISABLE. Note that DEPRIVILEGE action will ignore the REVERT configuration in the restore_policy
project Changes to this property will trigger replacement. String
The project ID where service accounts are created.
restorePolicy String
The action to be performed in the default service accounts on the resource destroy. Valid values are NONE, REVERT and REVERT_AND_IGNORE_FAILURE. It is applied for any action but in the DEPRIVILEGE. If set to REVERT it attempts to restore all default SAs but the DEPRIVILEGE action. If set to REVERT_AND_IGNORE_FAILURE it is the same behavior as REVERT but ignores errors returned by the API.
serviceAccounts Map<String>
The Service Accounts changed by this resource. It is used for REVERT the action on the destroy.

Import

This resource does not support import

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Google Cloud (GCP) Classic pulumi/pulumi-gcp
License
Apache-2.0
Notes
This Pulumi package is based on the google-beta Terraform Provider.