1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. compute
  5. FirewallPolicyAssociation
Google Cloud v8.25.0 published on Thursday, Apr 3, 2025 by Pulumi

gcp.compute.FirewallPolicyAssociation

Explore with Pulumi AI

Allows associating hierarchical firewall policies with the target where they are applied. This allows creating policies and rules in a different location than they are applied. For more information on applying hierarchical firewall policies see the official documentation

To get more information about FirewallPolicyAssociation, see:

Example Usage

Firewall Policy Association

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

const folder = new gcp.organizations.Folder("folder", {
    displayName: "my-folder",
    parent: "organizations/123456789",
    deletionProtection: false,
});
const policy = new gcp.compute.FirewallPolicy("policy", {
    parent: "organizations/123456789",
    shortName: "my-policy",
    description: "Example Resource",
});
const _default = new gcp.compute.FirewallPolicyAssociation("default", {
    firewallPolicy: policy.id,
    attachmentTarget: folder.name,
    name: "my-association",
});
Copy
import pulumi
import pulumi_gcp as gcp

folder = gcp.organizations.Folder("folder",
    display_name="my-folder",
    parent="organizations/123456789",
    deletion_protection=False)
policy = gcp.compute.FirewallPolicy("policy",
    parent="organizations/123456789",
    short_name="my-policy",
    description="Example Resource")
default = gcp.compute.FirewallPolicyAssociation("default",
    firewall_policy=policy.id,
    attachment_target=folder.name,
    name="my-association")
Copy
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/compute"
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/organizations"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		folder, err := organizations.NewFolder(ctx, "folder", &organizations.FolderArgs{
			DisplayName:        pulumi.String("my-folder"),
			Parent:             pulumi.String("organizations/123456789"),
			DeletionProtection: pulumi.Bool(false),
		})
		if err != nil {
			return err
		}
		policy, err := compute.NewFirewallPolicy(ctx, "policy", &compute.FirewallPolicyArgs{
			Parent:      pulumi.String("organizations/123456789"),
			ShortName:   pulumi.String("my-policy"),
			Description: pulumi.String("Example Resource"),
		})
		if err != nil {
			return err
		}
		_, err = compute.NewFirewallPolicyAssociation(ctx, "default", &compute.FirewallPolicyAssociationArgs{
			FirewallPolicy:   policy.ID(),
			AttachmentTarget: folder.Name,
			Name:             pulumi.String("my-association"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var folder = new Gcp.Organizations.Folder("folder", new()
    {
        DisplayName = "my-folder",
        Parent = "organizations/123456789",
        DeletionProtection = false,
    });

    var policy = new Gcp.Compute.FirewallPolicy("policy", new()
    {
        Parent = "organizations/123456789",
        ShortName = "my-policy",
        Description = "Example Resource",
    });

    var @default = new Gcp.Compute.FirewallPolicyAssociation("default", new()
    {
        FirewallPolicy = policy.Id,
        AttachmentTarget = folder.Name,
        Name = "my-association",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.Folder;
import com.pulumi.gcp.organizations.FolderArgs;
import com.pulumi.gcp.compute.FirewallPolicy;
import com.pulumi.gcp.compute.FirewallPolicyArgs;
import com.pulumi.gcp.compute.FirewallPolicyAssociation;
import com.pulumi.gcp.compute.FirewallPolicyAssociationArgs;
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 folder = new Folder("folder", FolderArgs.builder()
            .displayName("my-folder")
            .parent("organizations/123456789")
            .deletionProtection(false)
            .build());

        var policy = new FirewallPolicy("policy", FirewallPolicyArgs.builder()
            .parent("organizations/123456789")
            .shortName("my-policy")
            .description("Example Resource")
            .build());

        var default_ = new FirewallPolicyAssociation("default", FirewallPolicyAssociationArgs.builder()
            .firewallPolicy(policy.id())
            .attachmentTarget(folder.name())
            .name("my-association")
            .build());

    }
}
Copy
resources:
  folder:
    type: gcp:organizations:Folder
    properties:
      displayName: my-folder
      parent: organizations/123456789
      deletionProtection: false
  policy:
    type: gcp:compute:FirewallPolicy
    properties:
      parent: organizations/123456789
      shortName: my-policy
      description: Example Resource
  default:
    type: gcp:compute:FirewallPolicyAssociation
    properties:
      firewallPolicy: ${policy.id}
      attachmentTarget: ${folder.name}
      name: my-association
Copy

Import

FirewallPolicyAssociation can be imported using any of these accepted formats:

  • locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}

  • {{firewall_policy}}/{{name}}

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

$ pulumi import gcp:compute/firewallPolicyAssociation:FirewallPolicyAssociation default locations/global/firewallPolicies/{{firewall_policy}}/associations/{{name}}
Copy
$ pulumi import gcp:compute/firewallPolicyAssociation:FirewallPolicyAssociation default {{firewall_policy}}/{{name}}
Copy

Create FirewallPolicyAssociation Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new FirewallPolicyAssociation(name: string, args: FirewallPolicyAssociationArgs, opts?: CustomResourceOptions);
@overload
def FirewallPolicyAssociation(resource_name: str,
                              args: FirewallPolicyAssociationArgs,
                              opts: Optional[ResourceOptions] = None)

@overload
def FirewallPolicyAssociation(resource_name: str,
                              opts: Optional[ResourceOptions] = None,
                              attachment_target: Optional[str] = None,
                              firewall_policy: Optional[str] = None,
                              name: Optional[str] = None)
func NewFirewallPolicyAssociation(ctx *Context, name string, args FirewallPolicyAssociationArgs, opts ...ResourceOption) (*FirewallPolicyAssociation, error)
public FirewallPolicyAssociation(string name, FirewallPolicyAssociationArgs args, CustomResourceOptions? opts = null)
public FirewallPolicyAssociation(String name, FirewallPolicyAssociationArgs args)
public FirewallPolicyAssociation(String name, FirewallPolicyAssociationArgs args, CustomResourceOptions options)
type: gcp:compute:FirewallPolicyAssociation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. FirewallPolicyAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. FirewallPolicyAssociationArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. FirewallPolicyAssociationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. FirewallPolicyAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. FirewallPolicyAssociationArgs
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 firewallPolicyAssociationResource = new Gcp.Compute.FirewallPolicyAssociation("firewallPolicyAssociationResource", new()
{
    AttachmentTarget = "string",
    FirewallPolicy = "string",
    Name = "string",
});
Copy
example, err := compute.NewFirewallPolicyAssociation(ctx, "firewallPolicyAssociationResource", &compute.FirewallPolicyAssociationArgs{
	AttachmentTarget: pulumi.String("string"),
	FirewallPolicy:   pulumi.String("string"),
	Name:             pulumi.String("string"),
})
Copy
var firewallPolicyAssociationResource = new FirewallPolicyAssociation("firewallPolicyAssociationResource", FirewallPolicyAssociationArgs.builder()
    .attachmentTarget("string")
    .firewallPolicy("string")
    .name("string")
    .build());
Copy
firewall_policy_association_resource = gcp.compute.FirewallPolicyAssociation("firewallPolicyAssociationResource",
    attachment_target="string",
    firewall_policy="string",
    name="string")
Copy
const firewallPolicyAssociationResource = new gcp.compute.FirewallPolicyAssociation("firewallPolicyAssociationResource", {
    attachmentTarget: "string",
    firewallPolicy: "string",
    name: "string",
});
Copy
type: gcp:compute:FirewallPolicyAssociation
properties:
    attachmentTarget: string
    firewallPolicy: string
    name: string
Copy

FirewallPolicyAssociation Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The FirewallPolicyAssociation resource accepts the following input properties:

AttachmentTarget
This property is required.
Changes to this property will trigger replacement.
string
The target that the firewall policy is attached to.
FirewallPolicy This property is required. string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


Name Changes to this property will trigger replacement. string
The name for an association.
AttachmentTarget
This property is required.
Changes to this property will trigger replacement.
string
The target that the firewall policy is attached to.
FirewallPolicy This property is required. string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


Name Changes to this property will trigger replacement. string
The name for an association.
attachmentTarget
This property is required.
Changes to this property will trigger replacement.
String
The target that the firewall policy is attached to.
firewallPolicy This property is required. String
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. String
The name for an association.
attachmentTarget
This property is required.
Changes to this property will trigger replacement.
string
The target that the firewall policy is attached to.
firewallPolicy This property is required. string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. string
The name for an association.
attachment_target
This property is required.
Changes to this property will trigger replacement.
str
The target that the firewall policy is attached to.
firewall_policy This property is required. str
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. str
The name for an association.
attachmentTarget
This property is required.
Changes to this property will trigger replacement.
String
The target that the firewall policy is attached to.
firewallPolicy This property is required. String
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. String
The name for an association.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
ShortName string
The short name of the firewall policy of the association.
Id string
The provider-assigned unique ID for this managed resource.
ShortName string
The short name of the firewall policy of the association.
id String
The provider-assigned unique ID for this managed resource.
shortName String
The short name of the firewall policy of the association.
id string
The provider-assigned unique ID for this managed resource.
shortName string
The short name of the firewall policy of the association.
id str
The provider-assigned unique ID for this managed resource.
short_name str
The short name of the firewall policy of the association.
id String
The provider-assigned unique ID for this managed resource.
shortName String
The short name of the firewall policy of the association.

Look up Existing FirewallPolicyAssociation Resource

Get an existing FirewallPolicyAssociation 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?: FirewallPolicyAssociationState, opts?: CustomResourceOptions): FirewallPolicyAssociation
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        attachment_target: Optional[str] = None,
        firewall_policy: Optional[str] = None,
        name: Optional[str] = None,
        short_name: Optional[str] = None) -> FirewallPolicyAssociation
func GetFirewallPolicyAssociation(ctx *Context, name string, id IDInput, state *FirewallPolicyAssociationState, opts ...ResourceOption) (*FirewallPolicyAssociation, error)
public static FirewallPolicyAssociation Get(string name, Input<string> id, FirewallPolicyAssociationState? state, CustomResourceOptions? opts = null)
public static FirewallPolicyAssociation get(String name, Output<String> id, FirewallPolicyAssociationState state, CustomResourceOptions options)
resources:  _:    type: gcp:compute:FirewallPolicyAssociation    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
AttachmentTarget Changes to this property will trigger replacement. string
The target that the firewall policy is attached to.
FirewallPolicy string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


Name Changes to this property will trigger replacement. string
The name for an association.
ShortName string
The short name of the firewall policy of the association.
AttachmentTarget Changes to this property will trigger replacement. string
The target that the firewall policy is attached to.
FirewallPolicy string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


Name Changes to this property will trigger replacement. string
The name for an association.
ShortName string
The short name of the firewall policy of the association.
attachmentTarget Changes to this property will trigger replacement. String
The target that the firewall policy is attached to.
firewallPolicy String
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. String
The name for an association.
shortName String
The short name of the firewall policy of the association.
attachmentTarget Changes to this property will trigger replacement. string
The target that the firewall policy is attached to.
firewallPolicy string
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. string
The name for an association.
shortName string
The short name of the firewall policy of the association.
attachment_target Changes to this property will trigger replacement. str
The target that the firewall policy is attached to.
firewall_policy str
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. str
The name for an association.
short_name str
The short name of the firewall policy of the association.
attachmentTarget Changes to this property will trigger replacement. String
The target that the firewall policy is attached to.
firewallPolicy String
The firewall policy of the resource. This field can be updated to refer to a different Firewall Policy, which will create a new association from that new firewall policy with the flag to override the existing attachmentTarget's policy association. Note Due to potential risks with this operation it is highly recommended to use the create_before_destroy life cycle option on your exisiting firewall policy so as to prevent a situation where your attachment target has no associated policy.


name Changes to this property will trigger replacement. String
The name for an association.
shortName String
The short name of the firewall policy of the association.

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.