aws.vpclattice.ResourcePolicy
Explore with Pulumi AI
Resource for managing an AWS VPC Lattice Resource Policy.
Example Usage
Basic Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const current = aws.getCallerIdentity({});
const currentGetPartition = aws.getPartition({});
const example = new aws.vpclattice.ServiceNetwork("example", {name: "example-vpclattice-service-network"});
const exampleResourcePolicy = new aws.vpclattice.ResourcePolicy("example", {
resourceArn: example.arn,
policy: pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [{
Sid: "test-pol-principals-6",
Effect: "Allow",
Principal: {
AWS: Promise.all([currentGetPartition, current]).then(([currentGetPartition, current]) => `arn:${currentGetPartition.partition}:iam::${current.accountId}:root`),
},
Action: [
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation",
"vpc-lattice:GetServiceNetwork",
],
Resource: example.arn,
}],
}),
});
import pulumi
import json
import pulumi_aws as aws
current = aws.get_caller_identity()
current_get_partition = aws.get_partition()
example = aws.vpclattice.ServiceNetwork("example", name="example-vpclattice-service-network")
example_resource_policy = aws.vpclattice.ResourcePolicy("example",
resource_arn=example.arn,
policy=pulumi.Output.json_dumps({
"Version": "2012-10-17",
"Statement": [{
"Sid": "test-pol-principals-6",
"Effect": "Allow",
"Principal": {
"AWS": f"arn:{current_get_partition.partition}:iam::{current.account_id}:root",
},
"Action": [
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation",
"vpc-lattice:GetServiceNetwork",
],
"Resource": example.arn,
}],
}))
package main
import (
"encoding/json"
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/vpclattice"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
current, err := aws.GetCallerIdentity(ctx, &aws.GetCallerIdentityArgs{}, nil)
if err != nil {
return err
}
currentGetPartition, err := aws.GetPartition(ctx, &aws.GetPartitionArgs{}, nil)
if err != nil {
return err
}
example, err := vpclattice.NewServiceNetwork(ctx, "example", &vpclattice.ServiceNetworkArgs{
Name: pulumi.String("example-vpclattice-service-network"),
})
if err != nil {
return err
}
_, err = vpclattice.NewResourcePolicy(ctx, "example", &vpclattice.ResourcePolicyArgs{
ResourceArn: example.Arn,
Policy: example.Arn.ApplyT(func(arn string) (pulumi.String, error) {
var _zero pulumi.String
tmpJSON0, err := json.Marshal(map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
map[string]interface{}{
"Sid": "test-pol-principals-6",
"Effect": "Allow",
"Principal": map[string]interface{}{
"AWS": fmt.Sprintf("arn:%v:iam::%v:root", currentGetPartition.Partition, current.AccountId),
},
"Action": []string{
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation",
"vpc-lattice:GetServiceNetwork",
},
"Resource": arn,
},
},
})
if err != nil {
return _zero, err
}
json0 := string(tmpJSON0)
return pulumi.String(json0), nil
}).(pulumi.StringOutput),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var current = Aws.GetCallerIdentity.Invoke();
var currentGetPartition = Aws.GetPartition.Invoke();
var example = new Aws.VpcLattice.ServiceNetwork("example", new()
{
Name = "example-vpclattice-service-network",
});
var exampleResourcePolicy = new Aws.VpcLattice.ResourcePolicy("example", new()
{
ResourceArn = example.Arn,
Policy = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
{
["Version"] = "2012-10-17",
["Statement"] = new[]
{
new Dictionary<string, object?>
{
["Sid"] = "test-pol-principals-6",
["Effect"] = "Allow",
["Principal"] = new Dictionary<string, object?>
{
["AWS"] = Output.Tuple(currentGetPartition, current).Apply(values =>
{
var currentGetPartition = values.Item1;
var current = values.Item2;
return $"arn:{currentGetPartition.Apply(getPartitionResult => getPartitionResult.Partition)}:iam::{current.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId)}:root";
}),
},
["Action"] = new[]
{
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation",
"vpc-lattice:GetServiceNetwork",
},
["Resource"] = example.Arn,
},
},
})),
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetCallerIdentityArgs;
import com.pulumi.aws.inputs.GetPartitionArgs;
import com.pulumi.aws.vpclattice.ServiceNetwork;
import com.pulumi.aws.vpclattice.ServiceNetworkArgs;
import com.pulumi.aws.vpclattice.ResourcePolicy;
import com.pulumi.aws.vpclattice.ResourcePolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;
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 current = AwsFunctions.getCallerIdentity();
final var currentGetPartition = AwsFunctions.getPartition();
var example = new ServiceNetwork("example", ServiceNetworkArgs.builder()
.name("example-vpclattice-service-network")
.build());
var exampleResourcePolicy = new ResourcePolicy("exampleResourcePolicy", ResourcePolicyArgs.builder()
.resourceArn(example.arn())
.policy(example.arn().applyValue(arn -> serializeJson(
jsonObject(
jsonProperty("Version", "2012-10-17"),
jsonProperty("Statement", jsonArray(jsonObject(
jsonProperty("Sid", "test-pol-principals-6"),
jsonProperty("Effect", "Allow"),
jsonProperty("Principal", jsonObject(
jsonProperty("AWS", String.format("arn:%s:iam::%s:root", currentGetPartition.applyValue(getPartitionResult -> getPartitionResult.partition()),current.applyValue(getCallerIdentityResult -> getCallerIdentityResult.accountId())))
)),
jsonProperty("Action", jsonArray(
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation",
"vpc-lattice:GetServiceNetwork"
)),
jsonProperty("Resource", arn)
)))
))))
.build());
}
}
resources:
example:
type: aws:vpclattice:ServiceNetwork
properties:
name: example-vpclattice-service-network
exampleResourcePolicy:
type: aws:vpclattice:ResourcePolicy
name: example
properties:
resourceArn: ${example.arn}
policy:
fn::toJSON:
Version: 2012-10-17
Statement:
- Sid: test-pol-principals-6
Effect: Allow
Principal:
AWS: arn:${currentGetPartition.partition}:iam::${current.accountId}:root
Action:
- vpc-lattice:CreateServiceNetworkVpcAssociation
- vpc-lattice:CreateServiceNetworkServiceAssociation
- vpc-lattice:GetServiceNetwork
Resource: ${example.arn}
variables:
current:
fn::invoke:
Function: aws:getCallerIdentity
Arguments: {}
currentGetPartition:
fn::invoke:
Function: aws:getPartition
Arguments: {}
Create ResourcePolicy Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new ResourcePolicy(name: string, args: ResourcePolicyArgs, opts?: CustomResourceOptions);
@overload
def ResourcePolicy(resource_name: str,
args: ResourcePolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def ResourcePolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
policy: Optional[str] = None,
resource_arn: Optional[str] = None)
func NewResourcePolicy(ctx *Context, name string, args ResourcePolicyArgs, opts ...ResourceOption) (*ResourcePolicy, error)
public ResourcePolicy(string name, ResourcePolicyArgs args, CustomResourceOptions? opts = null)
public ResourcePolicy(String name, ResourcePolicyArgs args)
public ResourcePolicy(String name, ResourcePolicyArgs args, CustomResourceOptions options)
type: aws:vpclattice:ResourcePolicy
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 ResourcePolicyArgs
- 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 ResourcePolicyArgs
- 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 ResourcePolicyArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args ResourcePolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args ResourcePolicyArgs
- 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 exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy = new Aws.VpcLattice.ResourcePolicy("exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy", new()
{
Policy = "string",
ResourceArn = "string",
});
example, err := vpclattice.NewResourcePolicy(ctx, "exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy", &vpclattice.ResourcePolicyArgs{
Policy: pulumi.String("string"),
ResourceArn: pulumi.String("string"),
})
var exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy = new ResourcePolicy("exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy", ResourcePolicyArgs.builder()
.policy("string")
.resourceArn("string")
.build());
exampleresource_policy_resource_resource_from_vpclatticeresource_policy = aws.vpclattice.ResourcePolicy("exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy",
policy="string",
resource_arn="string")
const exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy = new aws.vpclattice.ResourcePolicy("exampleresourcePolicyResourceResourceFromVpclatticeresourcePolicy", {
policy: "string",
resourceArn: "string",
});
type: aws:vpclattice:ResourcePolicy
properties:
policy: string
resourceArn: string
ResourcePolicy 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 ResourcePolicy resource accepts the following input properties:
- Policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- Resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- Policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- Resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy String
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn String - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy str
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource_
arn str - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy String
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn String - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
Outputs
All input properties are implicitly available as output properties. Additionally, the ResourcePolicy 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 ResourcePolicy Resource
Get an existing ResourcePolicy 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?: ResourcePolicyState, opts?: CustomResourceOptions): ResourcePolicy
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
policy: Optional[str] = None,
resource_arn: Optional[str] = None) -> ResourcePolicy
func GetResourcePolicy(ctx *Context, name string, id IDInput, state *ResourcePolicyState, opts ...ResourceOption) (*ResourcePolicy, error)
public static ResourcePolicy Get(string name, Input<string> id, ResourcePolicyState? state, CustomResourceOptions? opts = null)
public static ResourcePolicy get(String name, Output<String> id, ResourcePolicyState 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.
- Policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- Resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- Policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- Resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy String
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn String - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy string
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn string - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy str
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource_
arn str - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
- policy String
- An IAM policy. The policy string in JSON must not contain newlines or blank lines.
- resource
Arn String - The ID or Amazon Resource Name (ARN) of the service network or service for which the policy is created.
Import
Using pulumi import
, import VPC Lattice Resource Policy using the resource_arn
. For example:
$ pulumi import aws:vpclattice/resourcePolicy:ResourcePolicy example rft-8012925589
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.