1. Packages
  2. AWS
  3. API Docs
  4. organizations
  5. PolicyAttachment
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

aws.organizations.PolicyAttachment

Explore with Pulumi AI

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

    Provides a resource to attach an AWS Organizations policy to an organization account, root, or unit.

    Example Usage

    Organization Account

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const account = new aws.organizations.PolicyAttachment("account", {
        policyId: example.id,
        targetId: "123456789012",
    });
    
    import pulumi
    import pulumi_aws as aws
    
    account = aws.organizations.PolicyAttachment("account",
        policy_id=example["id"],
        target_id="123456789012")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := organizations.NewPolicyAttachment(ctx, "account", &organizations.PolicyAttachmentArgs{
    			PolicyId: pulumi.Any(example.Id),
    			TargetId: pulumi.String("123456789012"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var account = new Aws.Organizations.PolicyAttachment("account", new()
        {
            PolicyId = example.Id,
            TargetId = "123456789012",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.organizations.PolicyAttachment;
    import com.pulumi.aws.organizations.PolicyAttachmentArgs;
    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 account = new PolicyAttachment("account", PolicyAttachmentArgs.builder()
                .policyId(example.id())
                .targetId("123456789012")
                .build());
    
        }
    }
    
    resources:
      account:
        type: aws:organizations:PolicyAttachment
        properties:
          policyId: ${example.id}
          targetId: '123456789012'
    

    Organization Root

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const root = new aws.organizations.PolicyAttachment("root", {
        policyId: example.id,
        targetId: exampleAwsOrganizationsOrganization.roots[0].id,
    });
    
    import pulumi
    import pulumi_aws as aws
    
    root = aws.organizations.PolicyAttachment("root",
        policy_id=example["id"],
        target_id=example_aws_organizations_organization["roots"][0]["id"])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := organizations.NewPolicyAttachment(ctx, "root", &organizations.PolicyAttachmentArgs{
    			PolicyId: pulumi.Any(example.Id),
    			TargetId: pulumi.Any(exampleAwsOrganizationsOrganization.Roots[0].Id),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var root = new Aws.Organizations.PolicyAttachment("root", new()
        {
            PolicyId = example.Id,
            TargetId = exampleAwsOrganizationsOrganization.Roots[0].Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.organizations.PolicyAttachment;
    import com.pulumi.aws.organizations.PolicyAttachmentArgs;
    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 root = new PolicyAttachment("root", PolicyAttachmentArgs.builder()
                .policyId(example.id())
                .targetId(exampleAwsOrganizationsOrganization.roots()[0].id())
                .build());
    
        }
    }
    
    resources:
      root:
        type: aws:organizations:PolicyAttachment
        properties:
          policyId: ${example.id}
          targetId: ${exampleAwsOrganizationsOrganization.roots[0].id}
    

    Organization Unit

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const unit = new aws.organizations.PolicyAttachment("unit", {
        policyId: example.id,
        targetId: exampleAwsOrganizationsOrganizationalUnit.id,
    });
    
    import pulumi
    import pulumi_aws as aws
    
    unit = aws.organizations.PolicyAttachment("unit",
        policy_id=example["id"],
        target_id=example_aws_organizations_organizational_unit["id"])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/organizations"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := organizations.NewPolicyAttachment(ctx, "unit", &organizations.PolicyAttachmentArgs{
    			PolicyId: pulumi.Any(example.Id),
    			TargetId: pulumi.Any(exampleAwsOrganizationsOrganizationalUnit.Id),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var unit = new Aws.Organizations.PolicyAttachment("unit", new()
        {
            PolicyId = example.Id,
            TargetId = exampleAwsOrganizationsOrganizationalUnit.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.organizations.PolicyAttachment;
    import com.pulumi.aws.organizations.PolicyAttachmentArgs;
    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 unit = new PolicyAttachment("unit", PolicyAttachmentArgs.builder()
                .policyId(example.id())
                .targetId(exampleAwsOrganizationsOrganizationalUnit.id())
                .build());
    
        }
    }
    
    resources:
      unit:
        type: aws:organizations:PolicyAttachment
        properties:
          policyId: ${example.id}
          targetId: ${exampleAwsOrganizationsOrganizationalUnit.id}
    

    Create PolicyAttachment Resource

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

    Constructor syntax

    new PolicyAttachment(name: string, args: PolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def PolicyAttachment(resource_name: str,
                         args: PolicyAttachmentArgs,
                         opts: Optional[ResourceOptions] = None)
    
    @overload
    def PolicyAttachment(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         policy_id: Optional[str] = None,
                         target_id: Optional[str] = None,
                         skip_destroy: Optional[bool] = None)
    func NewPolicyAttachment(ctx *Context, name string, args PolicyAttachmentArgs, opts ...ResourceOption) (*PolicyAttachment, error)
    public PolicyAttachment(string name, PolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public PolicyAttachment(String name, PolicyAttachmentArgs args)
    public PolicyAttachment(String name, PolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: aws:organizations:PolicyAttachment
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args PolicyAttachmentArgs
    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 PolicyAttachmentArgs
    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 PolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args PolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args PolicyAttachmentArgs
    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 examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment = new Aws.Organizations.PolicyAttachment("examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment", new()
    {
        PolicyId = "string",
        TargetId = "string",
        SkipDestroy = false,
    });
    
    example, err := organizations.NewPolicyAttachment(ctx, "examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment", &organizations.PolicyAttachmentArgs{
    	PolicyId:    pulumi.String("string"),
    	TargetId:    pulumi.String("string"),
    	SkipDestroy: pulumi.Bool(false),
    })
    
    var examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment = new PolicyAttachment("examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment", PolicyAttachmentArgs.builder()
        .policyId("string")
        .targetId("string")
        .skipDestroy(false)
        .build());
    
    examplepolicy_attachment_resource_resource_from_organizationspolicy_attachment = aws.organizations.PolicyAttachment("examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment",
        policy_id="string",
        target_id="string",
        skip_destroy=False)
    
    const examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment = new aws.organizations.PolicyAttachment("examplepolicyAttachmentResourceResourceFromOrganizationspolicyAttachment", {
        policyId: "string",
        targetId: "string",
        skipDestroy: false,
    });
    
    type: aws:organizations:PolicyAttachment
    properties:
        policyId: string
        skipDestroy: false
        targetId: string
    

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

    PolicyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    TargetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    SkipDestroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    PolicyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    TargetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    SkipDestroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    policyId String
    The unique identifier (ID) of the policy that you want to attach to the target.
    targetId String
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    skipDestroy Boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    policyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    targetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    skipDestroy boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    policy_id str
    The unique identifier (ID) of the policy that you want to attach to the target.
    target_id str
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    skip_destroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    policyId String
    The unique identifier (ID) of the policy that you want to attach to the target.
    targetId String
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    skipDestroy Boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing PolicyAttachment Resource

    Get an existing PolicyAttachment 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?: PolicyAttachmentState, opts?: CustomResourceOptions): PolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy_id: Optional[str] = None,
            skip_destroy: Optional[bool] = None,
            target_id: Optional[str] = None) -> PolicyAttachment
    func GetPolicyAttachment(ctx *Context, name string, id IDInput, state *PolicyAttachmentState, opts ...ResourceOption) (*PolicyAttachment, error)
    public static PolicyAttachment Get(string name, Input<string> id, PolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static PolicyAttachment get(String name, Output<String> id, PolicyAttachmentState 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:
    PolicyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    SkipDestroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    TargetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    PolicyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    SkipDestroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    TargetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    policyId String
    The unique identifier (ID) of the policy that you want to attach to the target.
    skipDestroy Boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    targetId String
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    policyId string
    The unique identifier (ID) of the policy that you want to attach to the target.
    skipDestroy boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    targetId string
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    policy_id str
    The unique identifier (ID) of the policy that you want to attach to the target.
    skip_destroy bool
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    target_id str
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
    policyId String
    The unique identifier (ID) of the policy that you want to attach to the target.
    skipDestroy Boolean
    If set to true, destroy will not detach the policy and instead just remove the resource from state. This can be useful in situations where the attachment must be preserved to meet the AWS minimum requirement of 1 attached policy.
    targetId String
    The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.

    Import

    Using pulumi import, import aws_organizations_policy_attachment using the target ID and policy ID. For example:

    With an account target:

    $ pulumi import aws:organizations/policyAttachment:PolicyAttachment account 123456789012:p-12345678
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi