Try AWS Native preview for resources not in the classic version.
aws.iot.PolicyAttachment
Explore with Pulumi AI
Try AWS Native preview for resources not in the classic version.
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)
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v6/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: 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
})
}
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 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.iot.Policy;
import com.pulumi.aws.iot.PolicyArgs;
import com.pulumi.aws.iot.Certificate;
import com.pulumi.aws.iot.CertificateArgs;
import com.pulumi.aws.iot.PolicyAttachment;
import com.pulumi.aws.iot.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) {
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.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.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:
- '*'
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: Optional[str] = None,
target: Optional[str] = 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.
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 awsPolicyAttachmentResource = new Aws.Iot.PolicyAttachment("awsPolicyAttachmentResource", new()
{
Policy = "string",
Target = "string",
});
example, err := iot.NewPolicyAttachment(ctx, "awsPolicyAttachmentResource", &iot.PolicyAttachmentArgs{
Policy: pulumi.Any("string"),
Target: pulumi.String("string"),
})
var awsPolicyAttachmentResource = new PolicyAttachment("awsPolicyAttachmentResource", PolicyAttachmentArgs.builder()
.policy("string")
.target("string")
.build());
aws_policy_attachment_resource = aws.iot.PolicyAttachment("awsPolicyAttachmentResource",
policy="string",
target="string")
const awsPolicyAttachmentResource = new aws.iot.PolicyAttachment("awsPolicyAttachmentResource", {
policy: "string",
target: "string",
});
type: aws:iot:PolicyAttachment
properties:
policy: string
target: 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
The PolicyAttachment resource accepts the following input properties:
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: 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.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.
Try AWS Native preview for resources not in the classic version.