gcp.spanner.InstanceIAMPolicy
Explore with Pulumi AI
Three different resources help you manage your IAM policy for a Spanner instance. Each of these resources serves a different use case:
gcp.spanner.InstanceIAMPolicy
: Authoritative. Sets the IAM policy for the instance and replaces any existing policy already attached.
Warning: It’s entirely possibly to lock yourself out of your instance using
gcp.spanner.InstanceIAMPolicy
. Any permissions granted by default will be removed unless you include them in your config.
gcp.spanner.InstanceIAMBinding
: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the instance are preserved.gcp.spanner.InstanceIAMMember
: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the instance are preserved.
Note:
gcp.spanner.InstanceIAMPolicy
cannot be used in conjunction withgcp.spanner.InstanceIAMBinding
andgcp.spanner.InstanceIAMMember
or they will fight over what your policy should be.
Note:
gcp.spanner.InstanceIAMBinding
resources can be used in conjunction withgcp.spanner.InstanceIAMMember
resources only if they do not grant privilege to the same role.
gcp.spanner.InstanceIAMPolicy
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const admin = gcp.organizations.getIAMPolicy({
bindings: [{
role: "roles/editor",
members: ["user:jane@example.com"],
}],
});
const instance = new gcp.spanner.InstanceIAMPolicy("instance", {
instance: "your-instance-name",
policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp
admin = gcp.organizations.get_iam_policy(bindings=[{
"role": "roles/editor",
"members": ["user:jane@example.com"],
}])
instance = gcp.spanner.InstanceIAMPolicy("instance",
instance="your-instance-name",
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/organizations"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
admin, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{
{
Role: "roles/editor",
Members: []string{
"user:jane@example.com",
},
},
},
}, nil)
if err != nil {
return err
}
_, err = spanner.NewInstanceIAMPolicy(ctx, "instance", &spanner.InstanceIAMPolicyArgs{
Instance: pulumi.String("your-instance-name"),
PolicyData: pulumi.String(admin.PolicyData),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var admin = Gcp.Organizations.GetIAMPolicy.Invoke(new()
{
Bindings = new[]
{
new Gcp.Organizations.Inputs.GetIAMPolicyBindingInputArgs
{
Role = "roles/editor",
Members = new[]
{
"user:jane@example.com",
},
},
},
});
var instance = new Gcp.Spanner.InstanceIAMPolicy("instance", new()
{
Instance = "your-instance-name",
PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.OrganizationsFunctions;
import com.pulumi.gcp.organizations.inputs.GetIAMPolicyArgs;
import com.pulumi.gcp.spanner.InstanceIAMPolicy;
import com.pulumi.gcp.spanner.InstanceIAMPolicyArgs;
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) {
final var admin = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder()
.bindings(GetIAMPolicyBindingArgs.builder()
.role("roles/editor")
.members("user:jane@example.com")
.build())
.build());
var instance = new InstanceIAMPolicy("instance", InstanceIAMPolicyArgs.builder()
.instance("your-instance-name")
.policyData(admin.applyValue(getIAMPolicyResult -> getIAMPolicyResult.policyData()))
.build());
}
}
resources:
instance:
type: gcp:spanner:InstanceIAMPolicy
properties:
instance: your-instance-name
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
Function: gcp:organizations:getIAMPolicy
Arguments:
bindings:
- role: roles/editor
members:
- user:jane@example.com
gcp.spanner.InstanceIAMBinding
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const instance = new gcp.spanner.InstanceIAMBinding("instance", {
instance: "your-instance-name",
role: "roles/spanner.databaseAdmin",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
instance = gcp.spanner.InstanceIAMBinding("instance",
instance="your-instance-name",
role="roles/spanner.databaseAdmin",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := spanner.NewInstanceIAMBinding(ctx, "instance", &spanner.InstanceIAMBindingArgs{
Instance: pulumi.String("your-instance-name"),
Role: pulumi.String("roles/spanner.databaseAdmin"),
Members: pulumi.StringArray{
pulumi.String("user:jane@example.com"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var instance = new Gcp.Spanner.InstanceIAMBinding("instance", new()
{
Instance = "your-instance-name",
Role = "roles/spanner.databaseAdmin",
Members = new[]
{
"user:jane@example.com",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.spanner.InstanceIAMBinding;
import com.pulumi.gcp.spanner.InstanceIAMBindingArgs;
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 instance = new InstanceIAMBinding("instance", InstanceIAMBindingArgs.builder()
.instance("your-instance-name")
.role("roles/spanner.databaseAdmin")
.members("user:jane@example.com")
.build());
}
}
resources:
instance:
type: gcp:spanner:InstanceIAMBinding
properties:
instance: your-instance-name
role: roles/spanner.databaseAdmin
members:
- user:jane@example.com
gcp.spanner.InstanceIAMMember
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const instance = new gcp.spanner.InstanceIAMMember("instance", {
instance: "your-instance-name",
role: "roles/spanner.databaseAdmin",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
instance = gcp.spanner.InstanceIAMMember("instance",
instance="your-instance-name",
role="roles/spanner.databaseAdmin",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := spanner.NewInstanceIAMMember(ctx, "instance", &spanner.InstanceIAMMemberArgs{
Instance: pulumi.String("your-instance-name"),
Role: pulumi.String("roles/spanner.databaseAdmin"),
Member: pulumi.String("user:jane@example.com"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var instance = new Gcp.Spanner.InstanceIAMMember("instance", new()
{
Instance = "your-instance-name",
Role = "roles/spanner.databaseAdmin",
Member = "user:jane@example.com",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.spanner.InstanceIAMMember;
import com.pulumi.gcp.spanner.InstanceIAMMemberArgs;
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 instance = new InstanceIAMMember("instance", InstanceIAMMemberArgs.builder()
.instance("your-instance-name")
.role("roles/spanner.databaseAdmin")
.member("user:jane@example.com")
.build());
}
}
resources:
instance:
type: gcp:spanner:InstanceIAMMember
properties:
instance: your-instance-name
role: roles/spanner.databaseAdmin
member: user:jane@example.com
gcp.spanner.InstanceIAMBinding
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const instance = new gcp.spanner.InstanceIAMBinding("instance", {
instance: "your-instance-name",
role: "roles/spanner.databaseAdmin",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
instance = gcp.spanner.InstanceIAMBinding("instance",
instance="your-instance-name",
role="roles/spanner.databaseAdmin",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := spanner.NewInstanceIAMBinding(ctx, "instance", &spanner.InstanceIAMBindingArgs{
Instance: pulumi.String("your-instance-name"),
Role: pulumi.String("roles/spanner.databaseAdmin"),
Members: pulumi.StringArray{
pulumi.String("user:jane@example.com"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var instance = new Gcp.Spanner.InstanceIAMBinding("instance", new()
{
Instance = "your-instance-name",
Role = "roles/spanner.databaseAdmin",
Members = new[]
{
"user:jane@example.com",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.spanner.InstanceIAMBinding;
import com.pulumi.gcp.spanner.InstanceIAMBindingArgs;
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 instance = new InstanceIAMBinding("instance", InstanceIAMBindingArgs.builder()
.instance("your-instance-name")
.role("roles/spanner.databaseAdmin")
.members("user:jane@example.com")
.build());
}
}
resources:
instance:
type: gcp:spanner:InstanceIAMBinding
properties:
instance: your-instance-name
role: roles/spanner.databaseAdmin
members:
- user:jane@example.com
gcp.spanner.InstanceIAMMember
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const instance = new gcp.spanner.InstanceIAMMember("instance", {
instance: "your-instance-name",
role: "roles/spanner.databaseAdmin",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
instance = gcp.spanner.InstanceIAMMember("instance",
instance="your-instance-name",
role="roles/spanner.databaseAdmin",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := spanner.NewInstanceIAMMember(ctx, "instance", &spanner.InstanceIAMMemberArgs{
Instance: pulumi.String("your-instance-name"),
Role: pulumi.String("roles/spanner.databaseAdmin"),
Member: pulumi.String("user:jane@example.com"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var instance = new Gcp.Spanner.InstanceIAMMember("instance", new()
{
Instance = "your-instance-name",
Role = "roles/spanner.databaseAdmin",
Member = "user:jane@example.com",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.spanner.InstanceIAMMember;
import com.pulumi.gcp.spanner.InstanceIAMMemberArgs;
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 instance = new InstanceIAMMember("instance", InstanceIAMMemberArgs.builder()
.instance("your-instance-name")
.role("roles/spanner.databaseAdmin")
.member("user:jane@example.com")
.build());
}
}
resources:
instance:
type: gcp:spanner:InstanceIAMMember
properties:
instance: your-instance-name
role: roles/spanner.databaseAdmin
member: user:jane@example.com
Create InstanceIAMPolicy Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new InstanceIAMPolicy(name: string, args: InstanceIAMPolicyArgs, opts?: CustomResourceOptions);
@overload
def InstanceIAMPolicy(resource_name: str,
args: InstanceIAMPolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def InstanceIAMPolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
instance: Optional[str] = None,
policy_data: Optional[str] = None,
project: Optional[str] = None)
func NewInstanceIAMPolicy(ctx *Context, name string, args InstanceIAMPolicyArgs, opts ...ResourceOption) (*InstanceIAMPolicy, error)
public InstanceIAMPolicy(string name, InstanceIAMPolicyArgs args, CustomResourceOptions? opts = null)
public InstanceIAMPolicy(String name, InstanceIAMPolicyArgs args)
public InstanceIAMPolicy(String name, InstanceIAMPolicyArgs args, CustomResourceOptions options)
type: gcp:spanner:InstanceIAMPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args InstanceIAMPolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args InstanceIAMPolicyArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args InstanceIAMPolicyArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args InstanceIAMPolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args InstanceIAMPolicyArgs
- 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 gcpInstanceIAMPolicyResource = new Gcp.Spanner.InstanceIAMPolicy("gcpInstanceIAMPolicyResource", new()
{
Instance = "string",
PolicyData = "string",
Project = "string",
});
example, err := spanner.NewInstanceIAMPolicy(ctx, "gcpInstanceIAMPolicyResource", &spanner.InstanceIAMPolicyArgs{
Instance: pulumi.String("string"),
PolicyData: pulumi.String("string"),
Project: pulumi.String("string"),
})
var gcpInstanceIAMPolicyResource = new InstanceIAMPolicy("gcpInstanceIAMPolicyResource", InstanceIAMPolicyArgs.builder()
.instance("string")
.policyData("string")
.project("string")
.build());
gcp_instance_iam_policy_resource = gcp.spanner.InstanceIAMPolicy("gcpInstanceIAMPolicyResource",
instance="string",
policy_data="string",
project="string")
const gcpInstanceIAMPolicyResource = new gcp.spanner.InstanceIAMPolicy("gcpInstanceIAMPolicyResource", {
instance: "string",
policyData: "string",
project: "string",
});
type: gcp:spanner:InstanceIAMPolicy
properties:
instance: string
policyData: string
project: string
InstanceIAMPolicy Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The InstanceIAMPolicy resource accepts the following input properties:
- Instance string
- The name of the instance.
- Policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Instance string
- The name of the instance.
- Policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- instance String
- The name of the instance.
- policy
Data String - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- instance string
- The name of the instance.
- policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- instance str
- The name of the instance.
- policy_
data str - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project str
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- instance String
- The name of the instance.
- policy
Data String - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Outputs
All input properties are implicitly available as output properties. Additionally, the InstanceIAMPolicy resource produces the following output properties:
Look up Existing InstanceIAMPolicy Resource
Get an existing InstanceIAMPolicy 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?: InstanceIAMPolicyState, opts?: CustomResourceOptions): InstanceIAMPolicy
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
etag: Optional[str] = None,
instance: Optional[str] = None,
policy_data: Optional[str] = None,
project: Optional[str] = None) -> InstanceIAMPolicy
func GetInstanceIAMPolicy(ctx *Context, name string, id IDInput, state *InstanceIAMPolicyState, opts ...ResourceOption) (*InstanceIAMPolicy, error)
public static InstanceIAMPolicy Get(string name, Input<string> id, InstanceIAMPolicyState? state, CustomResourceOptions? opts = null)
public static InstanceIAMPolicy get(String name, Output<String> id, InstanceIAMPolicyState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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.
- Etag string
- (Computed) The etag of the instance's IAM policy.
- Instance string
- The name of the instance.
- Policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Etag string
- (Computed) The etag of the instance's IAM policy.
- Instance string
- The name of the instance.
- Policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- etag String
- (Computed) The etag of the instance's IAM policy.
- instance String
- The name of the instance.
- policy
Data String - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- etag string
- (Computed) The etag of the instance's IAM policy.
- instance string
- The name of the instance.
- policy
Data string - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- etag str
- (Computed) The etag of the instance's IAM policy.
- instance str
- The name of the instance.
- policy_
data str - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project str
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- etag String
- (Computed) The etag of the instance's IAM policy.
- instance String
- The name of the instance.
- policy
Data String - The policy data generated by
a
gcp.organizations.getIAMPolicy
data source. - project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Import
Importing IAM policies
IAM policy imports use the identifier of the Spanner Instances resource . For example:
{{project}}/{{instance}}
An import
block (Terraform v1.5.0 and later) can be used to import IAM policies:
tf
import {
id = {{project}}/{{instance}}
to = google_spanner_instance_iam_policy.default
}
The pulumi import
command can also be used:
$ pulumi import gcp:spanner/instanceIAMPolicy:InstanceIAMPolicy default {{project}}/{{instance}}
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.