Google Cloud (GCP) Classic

v6.39.0 published on Wednesday, Sep 28, 2022 by Pulumi

RepositoryIamPolicy

Three different resources help you manage your IAM policy for Cloud Pub/Sub Topic. Each of these resources serves a different use case:

  • gcp.pubsub.TopicIAMPolicy: Authoritative. Sets the IAM policy for the topic and replaces any existing policy already attached.
  • gcp.pubsub.TopicIAMBinding: 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 topic are preserved.
  • gcp.pubsub.TopicIAMMember: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the topic are preserved.

Note: gcp.pubsub.TopicIAMPolicy cannot be used in conjunction with gcp.pubsub.TopicIAMBinding and gcp.pubsub.TopicIAMMember or they will fight over what your policy should be.

Note: gcp.pubsub.TopicIAMBinding resources can be used in conjunction with gcp.pubsub.TopicIAMMember resources only if they do not grant privilege to the same role.

google_pubsub_topic_iam_policy

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

const admin = gcp.organizations.getIAMPolicy({
    bindings: [{
        role: "roles/viewer",
        members: ["user:jane@example.com"],
    }],
});
const policy = new gcp.pubsub.TopicIAMPolicy("policy", {
    project: google_pubsub_topic.example.project,
    topic: google_pubsub_topic.example.name,
    policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp

admin = gcp.organizations.get_iam_policy(bindings=[gcp.organizations.GetIAMPolicyBindingArgs(
    role="roles/viewer",
    members=["user:jane@example.com"],
)])
policy = gcp.pubsub.TopicIAMPolicy("policy",
    project=google_pubsub_topic["example"]["project"],
    topic=google_pubsub_topic["example"]["name"],
    policy_data=admin.policy_data)
using System.Collections.Generic;
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/viewer",
                Members = new[]
                {
                    "user:jane@example.com",
                },
            },
        },
    });

    var policy = new Gcp.PubSub.TopicIAMPolicy("policy", new()
    {
        Project = google_pubsub_topic.Example.Project,
        Topic = google_pubsub_topic.Example.Name,
        PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/organizations"
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/pubsub"
	"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{
				organizations.GetIAMPolicyBinding{
					Role: "roles/viewer",
					Members: []string{
						"user:jane@example.com",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = pubsub.NewTopicIAMPolicy(ctx, "policy", &pubsub.TopicIAMPolicyArgs{
			Project:    pulumi.Any(google_pubsub_topic.Example.Project),
			Topic:      pulumi.Any(google_pubsub_topic.Example.Name),
			PolicyData: pulumi.String(admin.PolicyData),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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.pubsub.TopicIAMPolicy;
import com.pulumi.gcp.pubsub.TopicIAMPolicyArgs;
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/viewer")
                .members("user:jane@example.com")
                .build())
            .build());

        var policy = new TopicIAMPolicy("policy", TopicIAMPolicyArgs.builder()        
            .project(google_pubsub_topic.example().project())
            .topic(google_pubsub_topic.example().name())
            .policyData(admin.applyValue(getIAMPolicyResult -> getIAMPolicyResult.policyData()))
            .build());

    }
}
resources:
  policy:
    type: gcp:pubsub:TopicIAMPolicy
    properties:
      project: ${google_pubsub_topic.example.project}
      topic: ${google_pubsub_topic.example.name}
      policyData: ${admin.policyData}
variables:
  admin:
    Fn::Invoke:
      Function: gcp:organizations:getIAMPolicy
      Arguments:
        bindings:
          - role: roles/viewer
            members:
              - user:jane@example.com

google_pubsub_topic_iam_binding

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

const binding = new gcp.pubsub.TopicIAMBinding("binding", {
    project: google_pubsub_topic.example.project,
    topic: google_pubsub_topic.example.name,
    role: "roles/viewer",
    members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp

binding = gcp.pubsub.TopicIAMBinding("binding",
    project=google_pubsub_topic["example"]["project"],
    topic=google_pubsub_topic["example"]["name"],
    role="roles/viewer",
    members=["user:jane@example.com"])
using System.Collections.Generic;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var binding = new Gcp.PubSub.TopicIAMBinding("binding", new()
    {
        Project = google_pubsub_topic.Example.Project,
        Topic = google_pubsub_topic.Example.Name,
        Role = "roles/viewer",
        Members = new[]
        {
            "user:jane@example.com",
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/pubsub"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := pubsub.NewTopicIAMBinding(ctx, "binding", &pubsub.TopicIAMBindingArgs{
			Project: pulumi.Any(google_pubsub_topic.Example.Project),
			Topic:   pulumi.Any(google_pubsub_topic.Example.Name),
			Role:    pulumi.String("roles/viewer"),
			Members: pulumi.StringArray{
				pulumi.String("user:jane@example.com"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.TopicIAMBinding;
import com.pulumi.gcp.pubsub.TopicIAMBindingArgs;
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 binding = new TopicIAMBinding("binding", TopicIAMBindingArgs.builder()        
            .project(google_pubsub_topic.example().project())
            .topic(google_pubsub_topic.example().name())
            .role("roles/viewer")
            .members("user:jane@example.com")
            .build());

    }
}
resources:
  binding:
    type: gcp:pubsub:TopicIAMBinding
    properties:
      project: ${google_pubsub_topic.example.project}
      topic: ${google_pubsub_topic.example.name}
      role: roles/viewer
      members:
        - user:jane@example.com

google_pubsub_topic_iam_member

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

const member = new gcp.pubsub.TopicIAMMember("member", {
    project: google_pubsub_topic.example.project,
    topic: google_pubsub_topic.example.name,
    role: "roles/viewer",
    member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp

member = gcp.pubsub.TopicIAMMember("member",
    project=google_pubsub_topic["example"]["project"],
    topic=google_pubsub_topic["example"]["name"],
    role="roles/viewer",
    member="user:jane@example.com")
using System.Collections.Generic;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var member = new Gcp.PubSub.TopicIAMMember("member", new()
    {
        Project = google_pubsub_topic.Example.Project,
        Topic = google_pubsub_topic.Example.Name,
        Role = "roles/viewer",
        Member = "user:jane@example.com",
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/pubsub"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := pubsub.NewTopicIAMMember(ctx, "member", &pubsub.TopicIAMMemberArgs{
			Project: pulumi.Any(google_pubsub_topic.Example.Project),
			Topic:   pulumi.Any(google_pubsub_topic.Example.Name),
			Role:    pulumi.String("roles/viewer"),
			Member:  pulumi.String("user:jane@example.com"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.TopicIAMMember;
import com.pulumi.gcp.pubsub.TopicIAMMemberArgs;
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 member = new TopicIAMMember("member", TopicIAMMemberArgs.builder()        
            .project(google_pubsub_topic.example().project())
            .topic(google_pubsub_topic.example().name())
            .role("roles/viewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:pubsub:TopicIAMMember
    properties:
      project: ${google_pubsub_topic.example.project}
      topic: ${google_pubsub_topic.example.name}
      role: roles/viewer
      member: user:jane@example.com

Create a RepositoryIamPolicy Resource

new RepositoryIamPolicy(name: string, args: RepositoryIamPolicyArgs, opts?: CustomResourceOptions);
@overload
def RepositoryIamPolicy(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        policy_data: Optional[str] = None,
                        project: Optional[str] = None,
                        repository: Optional[str] = None)
@overload
def RepositoryIamPolicy(resource_name: str,
                        args: RepositoryIamPolicyArgs,
                        opts: Optional[ResourceOptions] = None)
func NewRepositoryIamPolicy(ctx *Context, name string, args RepositoryIamPolicyArgs, opts ...ResourceOption) (*RepositoryIamPolicy, error)
public RepositoryIamPolicy(string name, RepositoryIamPolicyArgs args, CustomResourceOptions? opts = null)
public RepositoryIamPolicy(String name, RepositoryIamPolicyArgs args)
public RepositoryIamPolicy(String name, RepositoryIamPolicyArgs args, CustomResourceOptions options)
type: gcp:sourcerepo:RepositoryIamPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args RepositoryIamPolicyArgs
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 RepositoryIamPolicyArgs
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 RepositoryIamPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RepositoryIamPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args RepositoryIamPolicyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

RepositoryIamPolicy 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 RepositoryIamPolicy resource accepts the following input properties:

PolicyData string

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

Repository string
Project string

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.

PolicyData string

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

Repository string
Project string

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.

policyData String

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

repository String
project String

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.

policyData string

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

repository string
project string

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.

policy_data str

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

repository str
project str

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.

policyData String

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

repository String
project String

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.

Outputs

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

Etag string

(Computed) The etag of the IAM policy.

Id string

The provider-assigned unique ID for this managed resource.

Etag string

(Computed) The etag of the IAM policy.

Id string

The provider-assigned unique ID for this managed resource.

etag String

(Computed) The etag of the IAM policy.

id String

The provider-assigned unique ID for this managed resource.

etag string

(Computed) The etag of the IAM policy.

id string

The provider-assigned unique ID for this managed resource.

etag str

(Computed) The etag of the IAM policy.

id str

The provider-assigned unique ID for this managed resource.

etag String

(Computed) The etag of the IAM policy.

id String

The provider-assigned unique ID for this managed resource.

Look up an Existing RepositoryIamPolicy Resource

Get an existing RepositoryIamPolicy 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?: RepositoryIamPolicyState, opts?: CustomResourceOptions): RepositoryIamPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        etag: Optional[str] = None,
        policy_data: Optional[str] = None,
        project: Optional[str] = None,
        repository: Optional[str] = None) -> RepositoryIamPolicy
func GetRepositoryIamPolicy(ctx *Context, name string, id IDInput, state *RepositoryIamPolicyState, opts ...ResourceOption) (*RepositoryIamPolicy, error)
public static RepositoryIamPolicy Get(string name, Input<string> id, RepositoryIamPolicyState? state, CustomResourceOptions? opts = null)
public static RepositoryIamPolicy get(String name, Output<String> id, RepositoryIamPolicyState 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.
The following state arguments are supported:
Etag string

(Computed) The etag of the IAM policy.

PolicyData 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 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.

Repository string
Etag string

(Computed) The etag of the IAM policy.

PolicyData 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 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.

Repository string
etag String

(Computed) The etag of the IAM policy.

policyData 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 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.

repository String
etag string

(Computed) The etag of the IAM policy.

policyData 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 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.

repository string
etag str

(Computed) The etag of the IAM policy.

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 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.

repository str
etag String

(Computed) The etag of the IAM policy.

policyData 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 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.

repository String

Import

For all import syntaxes, the “resource in question” can take any of the following forms* projects/{{project}}/topics/{{name}} * {{project}}/{{name}} * {{name}} Any variables not passed in the import command will be taken from the provider configuration. Cloud Pub/Sub topic IAM resources can be imported using the resource identifiers, role, and member. IAM member imports use space-delimited identifiersthe resource in question, the role, and the member identity, e.g.

 $ pulumi import gcp:sourcerepo/repositoryIamPolicy:RepositoryIamPolicy editor "projects/{{project}}/topics/{{topic}} roles/viewer user:jane@example.com"

IAM binding imports use space-delimited identifiersthe resource in question and the role, e.g.

 $ pulumi import gcp:sourcerepo/repositoryIamPolicy:RepositoryIamPolicy editor "projects/{{project}}/topics/{{topic}} roles/viewer"

IAM policy imports use the identifier of the resource in question, e.g.

 $ pulumi import gcp:sourcerepo/repositoryIamPolicy:RepositoryIamPolicy editor projects/{{project}}/topics/{{topic}}

-> Custom RolesIf you’re importing a IAM resource with a custom role, make sure to use the

full name of the custom role, e.g. [projects/my-project|organizations/my-org]/roles/my-custom-role.

Package Details

Repository
https://github.com/pulumi/pulumi-gcp
License
Apache-2.0
Notes

This Pulumi package is based on the google-beta Terraform Provider.