Show / Hide Table of Contents

Class InstanceIAMPolicy

Three different resources help you manage your IAM policy for Compute Engine Instance. Each of these resources serves a different use case:

  • gcp.compute.InstanceIAMPolicy: Authoritative. Sets the IAM policy for the instance and replaces any existing policy already attached.
  • gcp.compute.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.compute.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.compute.InstanceIAMPolicy cannot be used in conjunction with gcp.compute.InstanceIAMBinding and gcp.compute.InstanceIAMMember or they will fight over what your policy should be.

Note: gcp.compute.InstanceIAMBinding resources can be used in conjunction with gcp.compute.InstanceIAMMember resources only if they do not grant privilege to the same role.

google_compute_instance_iam_policy

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var admin = Output.Create(Gcp.Organizations.GetIAMPolicy.InvokeAsync(new Gcp.Organizations.GetIAMPolicyArgs
    {
        Binding = 
        {

            {
                { "role", "roles/compute.osLogin" },
                { "members", 
                {
                    "user:jane@example.com",
                } },
            },
        },
    }));
    var policy = new Gcp.Compute.InstanceIAMPolicy("policy", new Gcp.Compute.InstanceIAMPolicyArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        PolicyData = admin.Apply(admin => admin.PolicyData),
    });
}

}

With IAM Conditions:

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var admin = Output.Create(Gcp.Organizations.GetIAMPolicy.InvokeAsync(new Gcp.Organizations.GetIAMPolicyArgs
    {
        Binding = 
        {

            {
                { "role", "roles/compute.osLogin" },
                { "members", 
                {
                    "user:jane@example.com",
                } },
                { "condition", 
                {
                    { "title", "expires_after_2019_12_31" },
                    { "description", "Expiring at midnight of 2019-12-31" },
                    { "expression", "request.time < timestamp(\"2020-01-01T00:00:00Z\")" },
                } },
            },
        },
    }));
    var policy = new Gcp.Compute.InstanceIAMPolicy("policy", new Gcp.Compute.InstanceIAMPolicyArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        PolicyData = admin.Apply(admin => admin.PolicyData),
    });
}

}

google_compute_instance_iam_binding

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var binding = new Gcp.Compute.InstanceIAMBinding("binding", new Gcp.Compute.InstanceIAMBindingArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        Role = "roles/compute.osLogin",
        Members = 
        {
            "user:jane@example.com",
        },
    });
}

}

With IAM Conditions:

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var binding = new Gcp.Compute.InstanceIAMBinding("binding", new Gcp.Compute.InstanceIAMBindingArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        Role = "roles/compute.osLogin",
        Members = 
        {
            "user:jane@example.com",
        },
        Condition = new Gcp.Compute.Inputs.InstanceIAMBindingConditionArgs
        {
            Title = "expires_after_2019_12_31",
            Description = "Expiring at midnight of 2019-12-31",
            Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
        },
    });
}

}

google_compute_instance_iam_member

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var member = new Gcp.Compute.InstanceIAMMember("member", new Gcp.Compute.InstanceIAMMemberArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        Role = "roles/compute.osLogin",
        Member = "user:jane@example.com",
    });
}

}

With IAM Conditions:

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
public MyStack()
{
    var member = new Gcp.Compute.InstanceIAMMember("member", new Gcp.Compute.InstanceIAMMemberArgs
    {
        Project = google_compute_instance.Default.Project,
        Zone = google_compute_instance.Default.Zone,
        InstanceName = google_compute_instance.Default.Name,
        Role = "roles/compute.osLogin",
        Member = "user:jane@example.com",
        Condition = new Gcp.Compute.Inputs.InstanceIAMMemberConditionArgs
        {
            Title = "expires_after_2019_12_31",
            Description = "Expiring at midnight of 2019-12-31",
            Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
        },
    });
}

}
Inheritance
System.Object
Resource
CustomResource
InstanceIAMPolicy
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Gcp.Compute
Assembly: Pulumi.Gcp.dll
Syntax
public class InstanceIAMPolicy : CustomResource

Constructors

View Source

InstanceIAMPolicy(String, InstanceIAMPolicyArgs, CustomResourceOptions)

Create a InstanceIAMPolicy resource with the given unique name, arguments, and options.

Declaration
public InstanceIAMPolicy(string name, InstanceIAMPolicyArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

InstanceIAMPolicyArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

Etag

(Computed) The etag of the IAM policy.

Declaration
public Output<string> Etag { get; }
Property Value
Type Description
Output<System.String>
View Source

InstanceName

Used to find the parent resource to bind the IAM policy to

Declaration
public Output<string> InstanceName { get; }
Property Value
Type Description
Output<System.String>
View Source

PolicyData

The policy data generated by a gcp.organizations.getIAMPolicy data source.

Declaration
public Output<string> PolicyData { get; }
Property Value
Type Description
Output<System.String>
View Source

Project

The ID of the project in which the resource belongs. If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used.

Declaration
public Output<string> Project { get; }
Property Value
Type Description
Output<System.String>
View Source

Zone

A reference to the zone where the machine resides. Used to find the parent resource to bind the IAM policy to. If not specified, the value will be parsed from the identifier of the parent resource. If no zone is provided in the parent identifier and no zone is specified, it is taken from the provider configuration.

Declaration
public Output<string> Zone { get; }
Property Value
Type Description
Output<System.String>

Methods

View Source

Get(String, Input<String>, InstanceIAMPolicyState, CustomResourceOptions)

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

Declaration
public static InstanceIAMPolicy Get(string name, Input<string> id, InstanceIAMPolicyState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

InstanceIAMPolicyState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
InstanceIAMPolicy
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.