AuthorizationPolicy class

AuthorizationPolicy is a resource that specifies how a server should authorize incoming connections. This resource in itself does not change the configuration unless it's attached to a target https proxy or endpoint config selector resource.

> Warning: This resource is in beta, and should be used with the terraform-provider-google-beta provider. See Provider Versions for more details on beta resources.

To get more information about AuthorizationPolicy, see:

Example Usage

Network Security Authorization Policy Basic

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

const _default = new gcp.networksecurity.AuthorizationPolicy("default", {
    name: "my-authorization-policy",
    labels: {
        foo: "bar",
    },
    description: "my description",
    action: "ALLOW",
    rules: [{
        sources: [{
            principals: ["namespace/*"],
            ipBlocks: ["1.2.3.0/24"],
        }],
    }],
});
import pulumi
import pulumi_gcp as gcp

default = gcp.networksecurity.AuthorizationPolicy("default",
    name="my-authorization-policy",
    labels={
        "foo": "bar",
    },
    description="my description",
    action="ALLOW",
    rules=[{
        "sources": [{
            "principals": ["namespace/*"],
            "ip_blocks": ["1.2.3.0/24"],
        }],
    }])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() =>
{
    var @default = new Gcp.NetworkSecurity.AuthorizationPolicy("default", new()
    {
        Name = "my-authorization-policy",
        Labels =
        {
            { "foo", "bar" },
        },
        Description = "my description",
        Action = "ALLOW",
        Rules = new[]
        {
            new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleArgs
            {
                Sources = new[]
                {
                    new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleSourceArgs
                    {
                        Principals = new[]
                        {
                            "namespace/*",
                        },
                        IpBlocks = new[]
                        {
                            "1.2.3.0/24",
                        },
                    },
                },
            },
        },
    });

});
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := networksecurity.NewAuthorizationPolicy(ctx, "default", &networksecurity.AuthorizationPolicyArgs{
			Name: pulumi.String("my-authorization-policy"),
			Labels: pulumi.StringMap{
				"foo": pulumi.String("bar"),
			},
			Description: pulumi.String("my description"),
			Action:      pulumi.String("ALLOW"),
			Rules: networksecurity.AuthorizationPolicyRuleArray{
				&networksecurity.AuthorizationPolicyRuleArgs{
					Sources: networksecurity.AuthorizationPolicyRuleSourceArray{
						&networksecurity.AuthorizationPolicyRuleSourceArgs{
							Principals: pulumi.StringArray{
								pulumi.String("namespace/*"),
							},
							IpBlocks: pulumi.StringArray{
								pulumi.String("1.2.3.0/24"),
							},
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

resource "gcp_networksecurity_authorizationpolicy" "default" {
  name = "my-authorization-policy"
  labels = {
    "foo" = "bar"
  }
  description = "my description"
  action      = "ALLOW"
  rules {
    sources {
      principals = ["namespace/*"]
      ip_blocks  = ["1.2.3.0/24"]
    }
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.networksecurity.AuthorizationPolicy;
import com.pulumi.gcp.networksecurity.AuthorizationPolicyArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleSourceArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 default_ = new AuthorizationPolicy("default", AuthorizationPolicyArgs.builder()
            .name("my-authorization-policy")
            .labels(Map.of("foo", "bar"))
            .description("my description")
            .action("ALLOW")
            .rules(AuthorizationPolicyRuleArgs.builder()
                .sources(AuthorizationPolicyRuleSourceArgs.builder()
                    .principals("namespace/*")
                    .ipBlocks("1.2.3.0/24")
                    .build())
                .build())
            .build());

    }
}
resources:
  default:
    type: gcp:networksecurity:AuthorizationPolicy
    properties:
      name: my-authorization-policy
      labels:
        foo: bar
      description: my description
      action: ALLOW
      rules:
        - sources:
            - principals:
                - namespace/*
              ipBlocks:
                - 1.2.3.0/24

Network Security Authorization Policy Destinations

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

const _default = new gcp.networksecurity.AuthorizationPolicy("default", {
    name: "my-authorization-policy",
    labels: {
        foo: "bar",
    },
    description: "my description",
    action: "ALLOW",
    rules: [{
        sources: [{
            principals: ["namespace/*"],
            ipBlocks: ["1.2.3.0/24"],
        }],
        destinations: [{
            hosts: ["mydomain.*"],
            ports: [8080],
            methods: ["GET"],
            httpHeaderMatch: {
                headerName: ":method",
                regexMatch: "GET",
            },
        }],
    }],
});
import pulumi
import pulumi_gcp as gcp

default = gcp.networksecurity.AuthorizationPolicy("default",
    name="my-authorization-policy",
    labels={
        "foo": "bar",
    },
    description="my description",
    action="ALLOW",
    rules=[{
        "sources": [{
            "principals": ["namespace/*"],
            "ip_blocks": ["1.2.3.0/24"],
        }],
        "destinations": [{
            "hosts": ["mydomain.*"],
            "ports": [8080],
            "methods": ["GET"],
            "http_header_match": {
                "header_name": ":method",
                "regex_match": "GET",
            },
        }],
    }])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() =>
{
    var @default = new Gcp.NetworkSecurity.AuthorizationPolicy("default", new()
    {
        Name = "my-authorization-policy",
        Labels =
        {
            { "foo", "bar" },
        },
        Description = "my description",
        Action = "ALLOW",
        Rules = new[]
        {
            new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleArgs
            {
                Sources = new[]
                {
                    new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleSourceArgs
                    {
                        Principals = new[]
                        {
                            "namespace/*",
                        },
                        IpBlocks = new[]
                        {
                            "1.2.3.0/24",
                        },
                    },
                },
                Destinations = new[]
                {
                    new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleDestinationArgs
                    {
                        Hosts = new[]
                        {
                            "mydomain.*",
                        },
                        Ports = new[]
                        {
                            8080,
                        },
                        Methods = new[]
                        {
                            "GET",
                        },
                        HttpHeaderMatch = new Gcp.NetworkSecurity.Inputs.AuthorizationPolicyRuleDestinationHttpHeaderMatchArgs
                        {
                            HeaderName = ":method",
                            RegexMatch = "GET",
                        },
                    },
                },
            },
        },
    });

});
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := networksecurity.NewAuthorizationPolicy(ctx, "default", &networksecurity.AuthorizationPolicyArgs{
			Name: pulumi.String("my-authorization-policy"),
			Labels: pulumi.StringMap{
				"foo": pulumi.String("bar"),
			},
			Description: pulumi.String("my description"),
			Action:      pulumi.String("ALLOW"),
			Rules: networksecurity.AuthorizationPolicyRuleArray{
				&networksecurity.AuthorizationPolicyRuleArgs{
					Sources: networksecurity.AuthorizationPolicyRuleSourceArray{
						&networksecurity.AuthorizationPolicyRuleSourceArgs{
							Principals: pulumi.StringArray{
								pulumi.String("namespace/*"),
							},
							IpBlocks: pulumi.StringArray{
								pulumi.String("1.2.3.0/24"),
							},
						},
					},
					Destinations: networksecurity.AuthorizationPolicyRuleDestinationArray{
						&networksecurity.AuthorizationPolicyRuleDestinationArgs{
							Hosts: pulumi.StringArray{
								pulumi.String("mydomain.*"),
							},
							Ports: pulumi.IntArray{
								pulumi.Int(8080),
							},
							Methods: pulumi.StringArray{
								pulumi.String("GET"),
							},
							HttpHeaderMatch: &networksecurity.AuthorizationPolicyRuleDestinationHttpHeaderMatchArgs{
								HeaderName: pulumi.String(":method"),
								RegexMatch: pulumi.String("GET"),
							},
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

resource "gcp_networksecurity_authorizationpolicy" "default" {
  name = "my-authorization-policy"
  labels = {
    "foo" = "bar"
  }
  description = "my description"
  action      = "ALLOW"
  rules {
    sources {
      principals = ["namespace/*"]
      ip_blocks  = ["1.2.3.0/24"]
    }
    destinations {
      hosts   = ["mydomain.*"]
      ports   = [8080]
      methods = ["GET"]
      http_header_match = {
        header_name = ":method"
        regex_match = "GET"
      }
    }
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.networksecurity.AuthorizationPolicy;
import com.pulumi.gcp.networksecurity.AuthorizationPolicyArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleSourceArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleDestinationArgs;
import com.pulumi.gcp.networksecurity.inputs.AuthorizationPolicyRuleDestinationHttpHeaderMatchArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 default_ = new AuthorizationPolicy("default", AuthorizationPolicyArgs.builder()
            .name("my-authorization-policy")
            .labels(Map.of("foo", "bar"))
            .description("my description")
            .action("ALLOW")
            .rules(AuthorizationPolicyRuleArgs.builder()
                .sources(AuthorizationPolicyRuleSourceArgs.builder()
                    .principals("namespace/*")
                    .ipBlocks("1.2.3.0/24")
                    .build())
                .destinations(AuthorizationPolicyRuleDestinationArgs.builder()
                    .hosts("mydomain.*")
                    .ports(8080)
                    .methods("GET")
                    .httpHeaderMatch(AuthorizationPolicyRuleDestinationHttpHeaderMatchArgs.builder()
                        .headerName(":method")
                        .regexMatch("GET")
                        .build())
                    .build())
                .build())
            .build());

    }
}
resources:
  default:
    type: gcp:networksecurity:AuthorizationPolicy
    properties:
      name: my-authorization-policy
      labels:
        foo: bar
      description: my description
      action: ALLOW
      rules:
        - sources:
            - principals:
                - namespace/*
              ipBlocks:
                - 1.2.3.0/24
          destinations:
            - hosts:
                - mydomain.*
              ports:
                - 8080
              methods:
                - GET
              httpHeaderMatch:
                headerName: :method
                regexMatch: GET

Import

AuthorizationPolicy can be imported using any of these accepted formats:

  • projects/{{project}}/locations/{{location}}/authorizationPolicies/{{name}}
  • {{project}}/{{location}}/{{name}}
  • {{location}}/{{name}}

When using the pulumi import command, AuthorizationPolicy can be imported using one of the formats above. For example:

$ pulumi import gcp:networksecurity/authorizationPolicy:AuthorizationPolicy default projects/{{project}}/locations/{{location}}/authorizationPolicies/{{name}}
$ pulumi import gcp:networksecurity/authorizationPolicy:AuthorizationPolicy default {{project}}/{{location}}/{{name}}
$ pulumi import gcp:networksecurity/authorizationPolicy:AuthorizationPolicy default {{location}}/{{name}}

Constructors

AuthorizationPolicy(String name, {AuthorizationPolicyArgs? args, CustomResourceOptions? options})
Creates a new AuthorizationPolicy. name The Pulumi resource name. args Arguments used to configure this AuthorizationPolicy. The set of arguments for AuthorizationPolicy. options Resource options controlling this resource's behavior.
AuthorizationPolicy.reference(String urn)
Creates a typed reference to an existing AuthorizationPolicy resource.

Properties

action ↔ Output<String>
The action to take when a rule match is found. Possible values are "ALLOW" or "DENY". Possible values are: ALLOW, DENY.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
createTime ↔ Output<String>
Time the AuthorizationPolicy was created in UTC.
latefinal
deletionPolicy ↔ Output<String>
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. When a 'terraform destroy' or 'pulumi up' would delete the resource, the command will fail if this field is set to "PREVENT" in Terraform state. When set to "ABANDON", the command will remove the resource from Terraform management without updating or deleting the resource in the API. When set to "DELETE", deleting the resource is allowed.
latefinal
description ↔ Output<String?>
A free-text description of the resource. Max length 1024 characters.
latefinal
effectiveLabels ↔ Output<Map<String, String>>
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Pulumi, other clients and services.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
labels ↔ Output<Map<String, String>?>
Set of label tags associated with the AuthorizationPolicy resource. Note: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field effectiveLabels for all of the labels present on the resource.
latefinal
location ↔ Output<String?>
The location of the authorization policy. The default value is global.
latefinal
name ↔ Output<String>
Name of the AuthorizationPolicy resource.
latefinal
project ↔ Output<String>
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
latefinal
pulumiLabels ↔ Output<Map<String, String>>
The combination of labels configured directly on the resource and default labels configured on the provider.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
rules ↔ Output<List<AuthorizationPolicyRule>?>
List of rules to match. Note that at least one of the rules must match in order for the action specified in the 'action' field to be taken. A rule is a match if there is a matching source and destination. If left blank, the action specified in the action field will be applied on every request. Structure is documented below.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
updateTime ↔ Output<String>
Time the AuthorizationPolicy was updated in UTC.
latefinal
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {AuthorizationPolicyState? state, CustomResourceOptions? options}) → AuthorizationPolicy
Gets an existing AuthorizationPolicy resource's state with the given name and id.