1. Packages
  2. Ionoscloud Provider
  3. API Docs
  4. S3BucketPolicy
ionoscloud 6.7.6 published on Monday, Apr 14, 2025 by ionos-cloud

ionoscloud.S3BucketPolicy

Explore with Pulumi AI

ionoscloud logo
ionoscloud 6.7.6 published on Monday, Apr 14, 2025 by ionos-cloud

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as ionoscloud from "@pulumi/ionoscloud";
    
    const exampleS3Bucket = new ionoscloud.S3Bucket("exampleS3Bucket", {});
    const exampleS3BucketPolicy = new ionoscloud.S3BucketPolicy("exampleS3BucketPolicy", {
        bucket: exampleS3Bucket.name,
        policy: JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "Delegate certain actions to another user",
                Action: [
                    "s3:ListBucket",
                    "s3:PutObject",
                    "s3:GetObject",
                ],
                Effect: "Allow",
                Resource: [
                    "arn:aws:s3:::example",
                    "arn:aws:s3:::example/*",
                ],
                Condition: {
                    IpAddress: ["123.123.123.123/32"],
                },
                Principal: ["arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec"],
            }],
        }),
    });
    
    import pulumi
    import json
    import pulumi_ionoscloud as ionoscloud
    
    example_s3_bucket = ionoscloud.S3Bucket("exampleS3Bucket")
    example_s3_bucket_policy = ionoscloud.S3BucketPolicy("exampleS3BucketPolicy",
        bucket=example_s3_bucket.name,
        policy=json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "Delegate certain actions to another user",
                "Action": [
                    "s3:ListBucket",
                    "s3:PutObject",
                    "s3:GetObject",
                ],
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:s3:::example",
                    "arn:aws:s3:::example/*",
                ],
                "Condition": {
                    "IpAddress": ["123.123.123.123/32"],
                },
                "Principal": ["arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec"],
            }],
        }))
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ionoscloud/v6/ionoscloud"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleS3Bucket, err := ionoscloud.NewS3Bucket(ctx, "exampleS3Bucket", nil)
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Version": "2012-10-17",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Sid": "Delegate certain actions to another user",
    					"Action": []string{
    						"s3:ListBucket",
    						"s3:PutObject",
    						"s3:GetObject",
    					},
    					"Effect": "Allow",
    					"Resource": []string{
    						"arn:aws:s3:::example",
    						"arn:aws:s3:::example/*",
    					},
    					"Condition": map[string]interface{}{
    						"IpAddress": []string{
    							"123.123.123.123/32",
    						},
    					},
    					"Principal": []string{
    						"arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec",
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = ionoscloud.NewS3BucketPolicy(ctx, "exampleS3BucketPolicy", &ionoscloud.S3BucketPolicyArgs{
    			Bucket: exampleS3Bucket.Name,
    			Policy: pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Ionoscloud = Pulumi.Ionoscloud;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleS3Bucket = new Ionoscloud.S3Bucket("exampleS3Bucket");
    
        var exampleS3BucketPolicy = new Ionoscloud.S3BucketPolicy("exampleS3BucketPolicy", new()
        {
            Bucket = exampleS3Bucket.Name,
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Version"] = "2012-10-17",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Sid"] = "Delegate certain actions to another user",
                        ["Action"] = new[]
                        {
                            "s3:ListBucket",
                            "s3:PutObject",
                            "s3:GetObject",
                        },
                        ["Effect"] = "Allow",
                        ["Resource"] = new[]
                        {
                            "arn:aws:s3:::example",
                            "arn:aws:s3:::example/*",
                        },
                        ["Condition"] = new Dictionary<string, object?>
                        {
                            ["IpAddress"] = new[]
                            {
                                "123.123.123.123/32",
                            },
                        },
                        ["Principal"] = new[]
                        {
                            "arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec",
                        },
                    },
                },
            }),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.ionoscloud.S3Bucket;
    import com.pulumi.ionoscloud.S3BucketPolicy;
    import com.pulumi.ionoscloud.S3BucketPolicyArgs;
    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) {
            var exampleS3Bucket = new S3Bucket("exampleS3Bucket");
    
            var exampleS3BucketPolicy = new S3BucketPolicy("exampleS3BucketPolicy", S3BucketPolicyArgs.builder()
                .bucket(exampleS3Bucket.name())
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Sid", "Delegate certain actions to another user"),
                            jsonProperty("Action", jsonArray(
                                "s3:ListBucket", 
                                "s3:PutObject", 
                                "s3:GetObject"
                            )),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Resource", jsonArray(
                                "arn:aws:s3:::example", 
                                "arn:aws:s3:::example/*"
                            )),
                            jsonProperty("Condition", jsonObject(
                                jsonProperty("IpAddress", jsonArray("123.123.123.123/32"))
                            )),
                            jsonProperty("Principal", jsonArray("arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec"))
                        )))
                    )))
                .build());
    
        }
    }
    
    resources:
      exampleS3Bucket:
        type: ionoscloud:S3Bucket
      exampleS3BucketPolicy:
        type: ionoscloud:S3BucketPolicy
        properties:
          bucket: ${exampleS3Bucket.name}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: Delegate certain actions to another user
                  Action:
                    - s3:ListBucket
                    - s3:PutObject
                    - s3:GetObject
                  Effect: Allow
                  Resource:
                    - arn:aws:s3:::example
                    - arn:aws:s3:::example/*
                  Condition:
                    IpAddress:
                      - 123.123.123.123/32
                  Principal:
                    - arn:aws:iam:::user/31000000:9acd8251-2857-410e-b1fd-ca86462bdcec
    

    Create S3BucketPolicy Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new S3BucketPolicy(name: string, args: S3BucketPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def S3BucketPolicy(resource_name: str,
                       args: S3BucketPolicyArgs,
                       opts: Optional[ResourceOptions] = None)
    
    @overload
    def S3BucketPolicy(resource_name: str,
                       opts: Optional[ResourceOptions] = None,
                       bucket: Optional[str] = None,
                       policy: Optional[str] = None)
    func NewS3BucketPolicy(ctx *Context, name string, args S3BucketPolicyArgs, opts ...ResourceOption) (*S3BucketPolicy, error)
    public S3BucketPolicy(string name, S3BucketPolicyArgs args, CustomResourceOptions? opts = null)
    public S3BucketPolicy(String name, S3BucketPolicyArgs args)
    public S3BucketPolicy(String name, S3BucketPolicyArgs args, CustomResourceOptions options)
    
    type: ionoscloud:S3BucketPolicy
    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 S3BucketPolicyArgs
    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 S3BucketPolicyArgs
    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 S3BucketPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args S3BucketPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args S3BucketPolicyArgs
    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 s3bucketPolicyResource = new Ionoscloud.S3BucketPolicy("s3bucketPolicyResource", new()
    {
        Bucket = "string",
        Policy = "string",
    });
    
    example, err := ionoscloud.NewS3BucketPolicy(ctx, "s3bucketPolicyResource", &ionoscloud.S3BucketPolicyArgs{
    	Bucket: pulumi.String("string"),
    	Policy: pulumi.String("string"),
    })
    
    var s3bucketPolicyResource = new S3BucketPolicy("s3bucketPolicyResource", S3BucketPolicyArgs.builder()
        .bucket("string")
        .policy("string")
        .build());
    
    s3bucket_policy_resource = ionoscloud.S3BucketPolicy("s3bucketPolicyResource",
        bucket="string",
        policy="string")
    
    const s3bucketPolicyResource = new ionoscloud.S3BucketPolicy("s3bucketPolicyResource", {
        bucket: "string",
        policy: "string",
    });
    
    type: ionoscloud:S3BucketPolicy
    properties:
        bucket: string
        policy: string
    

    S3BucketPolicy 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 S3BucketPolicy resource accepts the following input properties:

    Bucket string
    [string] The name of the bucket where the object will be stored.
    Policy string
    [string] The policy document. This is a JSON formatted string.
    Bucket string
    [string] The name of the bucket where the object will be stored.
    Policy string
    [string] The policy document. This is a JSON formatted string.
    bucket String
    [string] The name of the bucket where the object will be stored.
    policy String
    [string] The policy document. This is a JSON formatted string.
    bucket string
    [string] The name of the bucket where the object will be stored.
    policy string
    [string] The policy document. This is a JSON formatted string.
    bucket str
    [string] The name of the bucket where the object will be stored.
    policy str
    [string] The policy document. This is a JSON formatted string.
    bucket String
    [string] The name of the bucket where the object will be stored.
    policy String
    [string] The policy document. This is a JSON formatted string.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the S3BucketPolicy 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 S3BucketPolicy Resource

    Get an existing S3BucketPolicy 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?: S3BucketPolicyState, opts?: CustomResourceOptions): S3BucketPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            bucket: Optional[str] = None,
            policy: Optional[str] = None) -> S3BucketPolicy
    func GetS3BucketPolicy(ctx *Context, name string, id IDInput, state *S3BucketPolicyState, opts ...ResourceOption) (*S3BucketPolicy, error)
    public static S3BucketPolicy Get(string name, Input<string> id, S3BucketPolicyState? state, CustomResourceOptions? opts = null)
    public static S3BucketPolicy get(String name, Output<String> id, S3BucketPolicyState state, CustomResourceOptions options)
    resources:  _:    type: ionoscloud:S3BucketPolicy    get:      id: ${id}
    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:
    Bucket string
    [string] The name of the bucket where the object will be stored.
    Policy string
    [string] The policy document. This is a JSON formatted string.
    Bucket string
    [string] The name of the bucket where the object will be stored.
    Policy string
    [string] The policy document. This is a JSON formatted string.
    bucket String
    [string] The name of the bucket where the object will be stored.
    policy String
    [string] The policy document. This is a JSON formatted string.
    bucket string
    [string] The name of the bucket where the object will be stored.
    policy string
    [string] The policy document. This is a JSON formatted string.
    bucket str
    [string] The name of the bucket where the object will be stored.
    policy str
    [string] The policy document. This is a JSON formatted string.
    bucket String
    [string] The name of the bucket where the object will be stored.
    policy String
    [string] The policy document. This is a JSON formatted string.

    Import

    Resource Policy can be imported using the bucket name

    $ pulumi import ionoscloud:index/s3BucketPolicy:S3BucketPolicy example example
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    ionoscloud ionos-cloud/terraform-provider-ionoscloud
    License
    Notes
    This Pulumi package is based on the ionoscloud Terraform Provider.
    ionoscloud logo
    ionoscloud 6.7.6 published on Monday, Apr 14, 2025 by ionos-cloud