Manage GCP API Gateway IAM Access

The gcp:apigateway/apiConfigIamMember:ApiConfigIamMember resource, part of the Pulumi GCP provider, manages IAM permissions for API Gateway API configurations. This guide focuses on two approaches: authoritative policy replacement and non-authoritative member addition.

IAM resources reference existing API Gateway APIs and ApiConfigs. The examples are intentionally small. Combine them with your own API Gateway infrastructure and organizational IAM policies.

Replace the entire IAM policy for an API config

When you need complete control over permissions, you can set the entire IAM policy at once.

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

const admin = gcp.organizations.getIAMPolicy({
    bindings: [{
        role: "roles/apigateway.viewer",
        members: ["user:jane@example.com"],
    }],
});
const policy = new gcp.apigateway.ApiConfigIamPolicy("policy", {
    api: apiCfg.api,
    apiConfig: apiCfg.apiConfigId,
    policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp

admin = gcp.organizations.get_iam_policy(bindings=[{
    "role": "roles/apigateway.viewer",
    "members": ["user:jane@example.com"],
}])
policy = gcp.apigateway.ApiConfigIamPolicy("policy",
    api=api_cfg["api"],
    api_config=api_cfg["apiConfigId"],
    policy_data=admin.policy_data)
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/apigateway"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
	"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/apigateway.viewer",
					Members: []string{
						"user:jane@example.com",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = apigateway.NewApiConfigIamPolicy(ctx, "policy", &apigateway.ApiConfigIamPolicyArgs{
			Api:        pulumi.Any(apiCfg.Api),
			ApiConfig:  pulumi.Any(apiCfg.ApiConfigId),
			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/apigateway.viewer",
                Members = new[]
                {
                    "user:jane@example.com",
                },
            },
        },
    });

    var policy = new Gcp.ApiGateway.ApiConfigIamPolicy("policy", new()
    {
        Api = apiCfg.Api,
        ApiConfig = apiCfg.ApiConfigId,
        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.apigateway.ApiConfigIamPolicy;
import com.pulumi.gcp.apigateway.ApiConfigIamPolicyArgs;
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/apigateway.viewer")
                .members("user:jane@example.com")
                .build())
            .build());

        var policy = new ApiConfigIamPolicy("policy", ApiConfigIamPolicyArgs.builder()
            .api(apiCfg.api())
            .apiConfig(apiCfg.apiConfigId())
            .policyData(admin.policyData())
            .build());

    }
}
resources:
  policy:
    type: gcp:apigateway:ApiConfigIamPolicy
    properties:
      api: ${apiCfg.api}
      apiConfig: ${apiCfg.apiConfigId}
      policyData: ${admin.policyData}
variables:
  admin:
    fn::invoke:
      function: gcp:organizations:getIAMPolicy
      arguments:
        bindings:
          - role: roles/apigateway.viewer
            members:
              - user:jane@example.com

The ApiConfigIamPolicy resource replaces all existing IAM bindings for the API config. The policyData comes from getIAMPolicy, which defines roles and members. This approach is authoritative: it removes any permissions not specified in the policy. ApiConfigIamPolicy cannot be used alongside ApiConfigIamBinding or ApiConfigIamMember for the same resource, as they will conflict over policy ownership.

Grant a role to a single member non-authoritatively

Most teams add permissions incrementally, granting roles to individual users without affecting existing access.

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

const member = new gcp.apigateway.ApiConfigIamMember("member", {
    api: apiCfg.api,
    apiConfig: apiCfg.apiConfigId,
    role: "roles/apigateway.viewer",
    member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp

member = gcp.apigateway.ApiConfigIamMember("member",
    api=api_cfg["api"],
    api_config=api_cfg["apiConfigId"],
    role="roles/apigateway.viewer",
    member="user:jane@example.com")
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/apigateway"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := apigateway.NewApiConfigIamMember(ctx, "member", &apigateway.ApiConfigIamMemberArgs{
			Api:       pulumi.Any(apiCfg.Api),
			ApiConfig: pulumi.Any(apiCfg.ApiConfigId),
			Role:      pulumi.String("roles/apigateway.viewer"),
			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 member = new Gcp.ApiGateway.ApiConfigIamMember("member", new()
    {
        Api = apiCfg.Api,
        ApiConfig = apiCfg.ApiConfigId,
        Role = "roles/apigateway.viewer",
        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.apigateway.ApiConfigIamMember;
import com.pulumi.gcp.apigateway.ApiConfigIamMemberArgs;
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 ApiConfigIamMember("member", ApiConfigIamMemberArgs.builder()
            .api(apiCfg.api())
            .apiConfig(apiCfg.apiConfigId())
            .role("roles/apigateway.viewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:apigateway:ApiConfigIamMember
    properties:
      api: ${apiCfg.api}
      apiConfig: ${apiCfg.apiConfigId}
      role: roles/apigateway.viewer
      member: user:jane@example.com

The ApiConfigIamMember resource adds one member to a role while preserving other members who already have that role. The member property accepts various identity formats: user emails, service accounts, groups, domains, or federated identities. This non-authoritative approach is safe to use alongside other IAM resources, as long as they don’t grant the same role to overlapping members.

Beyond these examples

These snippets focus on specific IAM management features: authoritative vs non-authoritative IAM management and policy-level and member-level access control. They’re intentionally minimal rather than full access control systems.

The examples reference pre-existing infrastructure such as API Gateway API and ApiConfig resources. They focus on managing permissions rather than provisioning the underlying API Gateway resources.

To keep things focused, common IAM patterns are omitted, including:

  • Conditional IAM bindings (condition property)
  • Custom role definitions
  • Binding-level management (ApiConfigIamBinding)
  • Project-level IAM inheritance

These omissions are intentional: the goal is to illustrate how each IAM resource type is wired, not provide drop-in access control modules. See the API Gateway ApiConfig IAM Member resource reference for all available configuration options.

Let's manage GCP API Gateway IAM Access

Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.

Try Pulumi Cloud for FREE

Frequently Asked Questions

Resource Selection & Compatibility
What's the difference between ApiConfigIamPolicy, ApiConfigIamBinding, and ApiConfigIamMember?
gcp.apigateway.ApiConfigIamPolicy is authoritative and replaces the entire IAM policy. gcp.apigateway.ApiConfigIamBinding is authoritative for a specific role, managing all members for that role while preserving other roles. gcp.apigateway.ApiConfigIamMember is non-authoritative, adding individual members to a role while preserving existing members.
Can I use ApiConfigIamPolicy with ApiConfigIamBinding or ApiConfigIamMember?
No, gcp.apigateway.ApiConfigIamPolicy cannot be used with gcp.apigateway.ApiConfigIamBinding or gcp.apigateway.ApiConfigIamMember because they will conflict over policy state.
Can I use ApiConfigIamBinding and ApiConfigIamMember together?
Yes, but only if they manage different roles. Using both resources for the same role will cause conflicts.
Configuration & Identity Formats
How do I specify custom IAM roles?
Custom roles must use the format [projects|organizations]/{parent-name}/roles/{role-name} in the role property.
What member identity formats are supported?
The member property supports: allUsers, allAuthenticatedUsers, user:{emailid}, serviceAccount:{emailid}, group:{emailid}, domain:{domain}, projectOwner:projectid, projectEditor:projectid, projectViewer:projectid, and federated identities (e.g., principal://iam.googleapis.com/...).
Stability & Provider Requirements
Is this resource production-ready?
This resource is in beta and requires the terraform-provider-google-beta provider.

Using a different cloud?

Explore security guides for other cloud providers: