AWS Classic

Pulumi Official
Package maintained by Pulumi
v5.10.0 published on Monday, Jul 11, 2022 by Pulumi

PolicyAttachment

Provides an IoT policy attachment.

Example Usage

using System.IO;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var pubsub = new Aws.Iot.Policy("pubsub", new Aws.Iot.PolicyArgs
        {
            Policy = @"{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
    {
      ""Action"": [
        ""iot:*""
      ],
      ""Effect"": ""Allow"",
      ""Resource"": ""*""
    }
  ]
}
",
        });
        var cert = new Aws.Iot.Certificate("cert", new Aws.Iot.CertificateArgs
        {
            Csr = File.ReadAllText("csr.pem"),
            Active = true,
        });
        var att = new Aws.Iot.PolicyAttachment("att", new Aws.Iot.PolicyAttachmentArgs
        {
            Policy = pubsub.Name,
            Target = cert.Arn,
        });
    }

}
package main

import (
	"fmt"
	"io/ioutil"

	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/iot"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func readFileOrPanic(path string) pulumi.StringPtrInput {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err.Error())
	}
	return pulumi.String(string(data))
}

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		pubsub, err := iot.NewPolicy(ctx, "pubsub", &iot.PolicyArgs{
			Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "    {\n", "      \"Action\": [\n", "        \"iot:*\"\n", "      ],\n", "      \"Effect\": \"Allow\",\n", "      \"Resource\": \"*\"\n", "    }\n", "  ]\n", "}\n")),
		})
		if err != nil {
			return err
		}
		cert, err := iot.NewCertificate(ctx, "cert", &iot.CertificateArgs{
			Csr:    readFileOrPanic("csr.pem"),
			Active: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		_, err = iot.NewPolicyAttachment(ctx, "att", &iot.PolicyAttachmentArgs{
			Policy: pubsub.Name,
			Target: cert.Arn,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var pubsub = new Policy("pubsub", PolicyArgs.builder()        
            .policy("""
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "iot:*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
            """)
            .build());

        var cert = new Certificate("cert", CertificateArgs.builder()        
            .csr(Files.readString("csr.pem"))
            .active(true)
            .build());

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

    }
}
import pulumi
import pulumi_aws as aws

pubsub = aws.iot.Policy("pubsub", policy="""{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "iot:*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
""")
cert = aws.iot.Certificate("cert",
    csr=(lambda path: open(path).read())("csr.pem"),
    active=True)
att = aws.iot.PolicyAttachment("att",
    policy=pubsub.name,
    target=cert.arn)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * from "fs";

const pubsub = new aws.iot.Policy("pubsub", {policy: `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "iot:*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
`});
const cert = new aws.iot.Certificate("cert", {
    csr: fs.readFileSync("csr.pem"),
    active: true,
});
const att = new aws.iot.PolicyAttachment("att", {
    policy: pubsub.name,
    target: cert.arn,
});

Coming soon!

Create a PolicyAttachment Resource

new PolicyAttachment(name: string, args: PolicyAttachmentArgs, opts?: CustomResourceOptions);
@overload
def PolicyAttachment(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     policy: Optional[str] = None,
                     target: Optional[str] = None)
@overload
def PolicyAttachment(resource_name: str,
                     args: PolicyAttachmentArgs,
                     opts: Optional[ResourceOptions] = 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:iot:PolicyAttachment
properties: # The arguments to resource properties.
options: # 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.
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.

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

The PolicyAttachment resource accepts the following input properties:

Policy string | string

The name of the policy to attach.

Target string

The identity to which the policy is attached.

Policy string | string

The name of the policy to attach.

Target string

The identity to which the policy is attached.

policy String | String

The name of the policy to attach.

target String

The identity to which the policy is attached.

policy string | Policy

The name of the policy to attach.

target ARN

The identity to which the policy is attached.

policy str | str

The name of the policy to attach.

target str

The identity to which the policy is attached.

policy String |

The name of the policy to attach.

target

The identity to which the policy is attached.

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 an 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: Optional[str] = None,
        target: 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:
Policy string | string

The name of the policy to attach.

Target string

The identity to which the policy is attached.

Policy string | string

The name of the policy to attach.

Target string

The identity to which the policy is attached.

policy String | String

The name of the policy to attach.

target String

The identity to which the policy is attached.

policy string | Policy

The name of the policy to attach.

target ARN

The identity to which the policy is attached.

policy str | str

The name of the policy to attach.

target str

The identity to which the policy is attached.

policy String |

The name of the policy to attach.

target

The identity to which the policy is attached.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.