PolicyAttachment class

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")
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 main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/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
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_organizations_policyattachment" "account" {
  policy_id = example.id
  target_id = "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.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 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"])
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 main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/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
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_organizations_policyattachment" "root" {
  policy_id = example.id
  target_id = 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.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 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"])
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 main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/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
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_organizations_policyattachment" "unit" {
  policy_id = example.id
  target_id = 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.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 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}

Import

Identity Schema

Required

  • policyId (String) Organizations policy ID.
  • targetId (String) Organizations target ID (account, OU, or root).

Optional

  • accountId (String) AWS Account where this resource is managed.

Using pulumi import, import aws.organizations.PolicyAttachment using the target ID and policy ID. For example:

With an account target:

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

Constructors

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

Properties

childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
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
policyId ↔ Output<String>
The unique identifier (ID) of the policy that you want to attach to the target.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
skipDestroy ↔ Output<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.
latefinal
targetId ↔ Output<String>
The unique identifier (ID) of the root, organizational unit, or account number that you want to attach the policy to.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
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, {PolicyAttachmentState? state, CustomResourceOptions? options}) → PolicyAttachment
Gets an existing PolicyAttachment resource's state with the given name and id.