PolicyAttachment class

Provides an IoT policy attachment.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";

const pubsub = aws.iam.getPolicyDocument({
    statements: [{
        effect: "Allow",
        actions: ["iot:*"],
        resources: ["*"],
    }],
});
const pubsubPolicy = new aws.iot.Policy("pubsub", {
    name: "PubSubToAnyTopic",
    policy: pubsub.then(pubsub => pubsub.json),
});
const cert = new aws.iot.Certificate("cert", {
    csr: std.file({
        input: "csr.pem",
    }).then(invoke => invoke.result),
    active: true,
});
const att = new aws.iot.PolicyAttachment("att", {
    policy: pubsubPolicy.name,
    target: cert.arn,
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std

pubsub = aws.iam.get_policy_document(statements=[{
    "effect": "Allow",
    "actions": ["iot:*"],
    "resources": ["*"],
}])
pubsub_policy = aws.iot.Policy("pubsub",
    name="PubSubToAnyTopic",
    policy=pubsub.json)
cert = aws.iot.Certificate("cert",
    csr=std.file(input="csr.pem").result,
    active=True)
att = aws.iot.PolicyAttachment("att",
    policy=pubsub_policy.name,
    target=cert.arn)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() =>
{
    var pubsub = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Effect = "Allow",
                Actions = new[]
                {
                    "iot:*",
                },
                Resources = new[]
                {
                    "*",
                },
            },
        },
    });

    var pubsubPolicy = new Aws.Iot.Policy("pubsub", new()
    {
        Name = "PubSubToAnyTopic",
        PolicyDocument = pubsub.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
    });

    var cert = new Aws.Iot.Certificate("cert", new()
    {
        Csr = Std.File.Invoke(new()
        {
            Input = "csr.pem",
        }).Apply(invoke => invoke.Result),
        Active = true,
    });

    var att = new Aws.Iot.PolicyAttachment("att", new()
    {
        Policy = pubsubPolicy.Name,
        Target = cert.Arn,
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iot"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		pubsub, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
			Statements: []iam.GetPolicyDocumentStatement{
				{
					Effect: pulumi.StringRef("Allow"),
					Actions: []string{
						"iot:*",
					},
					Resources: []string{
						"*",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		pubsubPolicy, err := iot.NewPolicy(ctx, "pubsub", &iot.PolicyArgs{
			Name:   pulumi.String("PubSubToAnyTopic"),
			Policy: pulumi.String(pubsub.Json),
		})
		if err != nil {
			return err
		}
		invokeFile, err := std.File(ctx, &std.FileArgs{
			Input: "csr.pem",
		}, nil)
		if err != nil {
			return err
		}
		cert, err := iot.NewCertificate(ctx, "cert", &iot.CertificateArgs{
			Csr:    pulumi.String(invokeFile.Result),
			Active: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		_, err = iot.NewPolicyAttachment(ctx, "att", &iot.PolicyAttachmentArgs{
			Policy: pubsubPolicy.Name,
			Target: cert.Arn,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
    std = {
      source = "pulumi/std"
    }
  }
}

data "aws_iam_getpolicydocument" "pubsub" {
  statements {
    effect    = "Allow"
    actions   = ["iot:*"]
    resources = ["*"]
  }
}

resource "aws_iot_policy" "pubsub" {
  name   = "PubSubToAnyTopic"
  policy = data.aws_iam_getpolicydocument.pubsub.json
}
resource "aws_iot_certificate" "cert" {
  csr    = file("csr.pem")
  active = true
}
resource "aws_iot_policyattachment" "att" {
  policy = aws_iot_policy.pubsub.name
  target = aws_iot_certificate.cert.arn
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iot.Policy;
import com.pulumi.aws.iot.PolicyArgs;
import com.pulumi.aws.iot.Certificate;
import com.pulumi.aws.iot.CertificateArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.FileArgs;
import com.pulumi.aws.iot.PolicyAttachment;
import com.pulumi.aws.iot.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) {
        final var pubsub = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .effect("Allow")
                .actions("iot:*")
                .resources("*")
                .build())
            .build());

        var pubsubPolicy = new Policy("pubsubPolicy", PolicyArgs.builder()
            .name("PubSubToAnyTopic")
            .policy(pubsub.json())
            .build());

        var cert = new Certificate("cert", CertificateArgs.builder()
            .csr(StdFunctions.file(FileArgs.builder()
                .input("csr.pem")
                .build()).result())
            .active(true)
            .build());

        var att = new PolicyAttachment("att", PolicyAttachmentArgs.builder()
            .policy(pubsubPolicy.name())
            .target(cert.arn())
            .build());

    }
}
resources:
  pubsubPolicy:
    type: aws:iot:Policy
    name: pubsub
    properties:
      name: PubSubToAnyTopic
      policy: ${pubsub.json}
  cert:
    type: aws:iot:Certificate
    properties:
      csr:
        fn::invoke:
          function: std:file
          arguments:
            input: csr.pem
          return: result
      active: true
  att:
    type: aws:iot:PolicyAttachment
    properties:
      policy: ${pubsubPolicy.name}
      target: ${cert.arn}
variables:
  pubsub:
    fn::invoke:
      function: aws:iam:getPolicyDocument
      arguments:
        statements:
          - effect: Allow
            actions:
              - iot:*
            resources:
              - '*'

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
policy ↔ Output<String>
The name of the policy to attach.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
target ↔ Output<String>
The identity to which the policy is attached.
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.