1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. sls
  5. CollectionPolicy
Viewing docs for Alibaba Cloud v3.97.0
published on Saturday, Mar 14, 2026 by Pulumi
alicloud logo
Viewing docs for Alibaba Cloud v3.97.0
published on Saturday, Mar 14, 2026 by Pulumi

    Provides a Log Service (SLS) Collection Policy resource.

    Orchestration policies for cloud product log collection.

    For information about Log Service (SLS) Collection Policy and how to use it, see What is Collection Policy.

    NOTE: Available since v1.232.0.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    import * as random from "@pulumi/random";
    import * as std from "@pulumi/std";
    
    const config = new pulumi.Config();
    const name = config.get("name") || "terraform-example";
    const _default = new random.index.Integer("default", {
        min: 10000,
        max: 99999,
    });
    const projectCreate01 = new alicloud.log.Project("project_create_01", {
        description: name,
        projectName: std.format({
            input: "%s1%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const logstoreCreate01 = new alicloud.log.Store("logstore_create_01", {
        retentionPeriod: 30,
        shardCount: 2,
        projectName: projectCreate01.projectName,
        logstoreName: std.format({
            input: "%s1%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const update01 = new alicloud.log.Project("update_01", {
        description: name,
        projectName: std.format({
            input: "%s2%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const logstore002 = new alicloud.log.Store("logstore002", {
        retentionPeriod: 30,
        shardCount: 2,
        projectName: update01.projectName,
        logstoreName: std.format({
            input: "%s2%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const defaultCollectionPolicy = new alicloud.sls.CollectionPolicy("default", {
        policyConfig: {
            resourceMode: "all",
            regions: ["cn-hangzhou"],
        },
        dataCode: "metering_log",
        centralizeEnabled: true,
        productCode: "oss",
        policyName: "xc-example-oss-01",
        enabled: true,
        dataConfig: {
            dataRegion: "cn-hangzhou",
        },
        centralizeConfig: {
            destTtl: 3,
            destRegion: "cn-shanghai",
            destProject: projectCreate01.projectName,
            destLogstore: logstoreCreate01.logstoreName,
        },
        resourceDirectory: {
            accountGroupType: "custom",
            members: ["1936728897040477"],
        },
    });
    
    import pulumi
    import pulumi_alicloud as alicloud
    import pulumi_random as random
    import pulumi_std as std
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "terraform-example"
    default = random.index.Integer("default",
        min=10000,
        max=99999)
    project_create01 = alicloud.log.Project("project_create_01",
        description=name,
        project_name=std.format(input="%s1%s",
            args=[
                name,
                default["result"],
            ]).result)
    logstore_create01 = alicloud.log.Store("logstore_create_01",
        retention_period=30,
        shard_count=2,
        project_name=project_create01.project_name,
        logstore_name=std.format(input="%s1%s",
            args=[
                name,
                default["result"],
            ]).result)
    update01 = alicloud.log.Project("update_01",
        description=name,
        project_name=std.format(input="%s2%s",
            args=[
                name,
                default["result"],
            ]).result)
    logstore002 = alicloud.log.Store("logstore002",
        retention_period=30,
        shard_count=2,
        project_name=update01.project_name,
        logstore_name=std.format(input="%s2%s",
            args=[
                name,
                default["result"],
            ]).result)
    default_collection_policy = alicloud.sls.CollectionPolicy("default",
        policy_config={
            "resource_mode": "all",
            "regions": ["cn-hangzhou"],
        },
        data_code="metering_log",
        centralize_enabled=True,
        product_code="oss",
        policy_name="xc-example-oss-01",
        enabled=True,
        data_config={
            "data_region": "cn-hangzhou",
        },
        centralize_config={
            "dest_ttl": 3,
            "dest_region": "cn-shanghai",
            "dest_project": project_create01.project_name,
            "dest_logstore": logstore_create01.logstore_name,
        },
        resource_directory={
            "account_group_type": "custom",
            "members": ["1936728897040477"],
        })
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/log"
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/sls"
    	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
    	"github.com/pulumi/pulumi-std/sdk/go/std"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		name := "terraform-example"
    		if param := cfg.Get("name"); param != "" {
    			name = param
    		}
    		_default, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
    			Min: 10000,
    			Max: 99999,
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s1%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		projectCreate01, err := log.NewProject(ctx, "project_create_01", &log.ProjectArgs{
    			Description: pulumi.String(name),
    			ProjectName: pulumi.String(invokeFormat.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat1, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s1%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		logstoreCreate01, err := log.NewStore(ctx, "logstore_create_01", &log.StoreArgs{
    			RetentionPeriod: pulumi.Int(30),
    			ShardCount:      pulumi.Int(2),
    			ProjectName:     projectCreate01.ProjectName,
    			LogstoreName:    pulumi.String(invokeFormat1.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat2, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s2%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		update01, err := log.NewProject(ctx, "update_01", &log.ProjectArgs{
    			Description: pulumi.String(name),
    			ProjectName: pulumi.String(invokeFormat2.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat3, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s2%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = log.NewStore(ctx, "logstore002", &log.StoreArgs{
    			RetentionPeriod: pulumi.Int(30),
    			ShardCount:      pulumi.Int(2),
    			ProjectName:     update01.ProjectName,
    			LogstoreName:    pulumi.String(invokeFormat3.Result),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = sls.NewCollectionPolicy(ctx, "default", &sls.CollectionPolicyArgs{
    			PolicyConfig: &sls.CollectionPolicyPolicyConfigArgs{
    				ResourceMode: pulumi.String("all"),
    				Regions: pulumi.StringArray{
    					pulumi.String("cn-hangzhou"),
    				},
    			},
    			DataCode:          pulumi.String("metering_log"),
    			CentralizeEnabled: pulumi.Bool(true),
    			ProductCode:       pulumi.String("oss"),
    			PolicyName:        pulumi.String("xc-example-oss-01"),
    			Enabled:           pulumi.Bool(true),
    			DataConfig: &sls.CollectionPolicyDataConfigArgs{
    				DataRegion: pulumi.String("cn-hangzhou"),
    			},
    			CentralizeConfig: &sls.CollectionPolicyCentralizeConfigArgs{
    				DestTtl:      pulumi.Int(3),
    				DestRegion:   pulumi.String("cn-shanghai"),
    				DestProject:  projectCreate01.ProjectName,
    				DestLogstore: logstoreCreate01.LogstoreName,
    			},
    			ResourceDirectory: &sls.CollectionPolicyResourceDirectoryArgs{
    				AccountGroupType: pulumi.String("custom"),
    				Members: pulumi.StringArray{
    					pulumi.String("1936728897040477"),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    using Random = Pulumi.Random;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var name = config.Get("name") ?? "terraform-example";
        var @default = new Random.Index.Integer("default", new()
        {
            Min = 10000,
            Max = 99999,
        });
    
        var projectCreate01 = new AliCloud.Log.Project("project_create_01", new()
        {
            Description = name,
            ProjectName = Std.Format.Invoke(new()
            {
                Input = "%s1%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var logstoreCreate01 = new AliCloud.Log.Store("logstore_create_01", new()
        {
            RetentionPeriod = 30,
            ShardCount = 2,
            ProjectName = projectCreate01.ProjectName,
            LogstoreName = Std.Format.Invoke(new()
            {
                Input = "%s1%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var update01 = new AliCloud.Log.Project("update_01", new()
        {
            Description = name,
            ProjectName = Std.Format.Invoke(new()
            {
                Input = "%s2%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var logstore002 = new AliCloud.Log.Store("logstore002", new()
        {
            RetentionPeriod = 30,
            ShardCount = 2,
            ProjectName = update01.ProjectName,
            LogstoreName = Std.Format.Invoke(new()
            {
                Input = "%s2%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var defaultCollectionPolicy = new AliCloud.Sls.CollectionPolicy("default", new()
        {
            PolicyConfig = new AliCloud.Sls.Inputs.CollectionPolicyPolicyConfigArgs
            {
                ResourceMode = "all",
                Regions = new[]
                {
                    "cn-hangzhou",
                },
            },
            DataCode = "metering_log",
            CentralizeEnabled = true,
            ProductCode = "oss",
            PolicyName = "xc-example-oss-01",
            Enabled = true,
            DataConfig = new AliCloud.Sls.Inputs.CollectionPolicyDataConfigArgs
            {
                DataRegion = "cn-hangzhou",
            },
            CentralizeConfig = new AliCloud.Sls.Inputs.CollectionPolicyCentralizeConfigArgs
            {
                DestTtl = 3,
                DestRegion = "cn-shanghai",
                DestProject = projectCreate01.ProjectName,
                DestLogstore = logstoreCreate01.LogstoreName,
            },
            ResourceDirectory = new AliCloud.Sls.Inputs.CollectionPolicyResourceDirectoryArgs
            {
                AccountGroupType = "custom",
                Members = new[]
                {
                    "1936728897040477",
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.Integer;
    import com.pulumi.random.IntegerArgs;
    import com.pulumi.alicloud.log.Project;
    import com.pulumi.alicloud.log.ProjectArgs;
    import com.pulumi.std.StdFunctions;
    import com.pulumi.std.inputs.FormatArgs;
    import com.pulumi.alicloud.log.Store;
    import com.pulumi.alicloud.log.StoreArgs;
    import com.pulumi.alicloud.sls.CollectionPolicy;
    import com.pulumi.alicloud.sls.CollectionPolicyArgs;
    import com.pulumi.alicloud.sls.inputs.CollectionPolicyPolicyConfigArgs;
    import com.pulumi.alicloud.sls.inputs.CollectionPolicyDataConfigArgs;
    import com.pulumi.alicloud.sls.inputs.CollectionPolicyCentralizeConfigArgs;
    import com.pulumi.alicloud.sls.inputs.CollectionPolicyResourceDirectoryArgs;
    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 config = ctx.config();
            final var name = config.get("name").orElse("terraform-example");
            var default_ = new Integer("default", IntegerArgs.builder()
                .min(10000)
                .max(99999)
                .build());
    
            var projectCreate01 = new Project("projectCreate01", ProjectArgs.builder()
                .description(name)
                .projectName(StdFunctions.format(FormatArgs.builder()
                    .input("%s1%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var logstoreCreate01 = new Store("logstoreCreate01", StoreArgs.builder()
                .retentionPeriod(30)
                .shardCount(2)
                .projectName(projectCreate01.projectName())
                .logstoreName(StdFunctions.format(FormatArgs.builder()
                    .input("%s1%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var update01 = new Project("update01", ProjectArgs.builder()
                .description(name)
                .projectName(StdFunctions.format(FormatArgs.builder()
                    .input("%s2%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var logstore002 = new Store("logstore002", StoreArgs.builder()
                .retentionPeriod(30)
                .shardCount(2)
                .projectName(update01.projectName())
                .logstoreName(StdFunctions.format(FormatArgs.builder()
                    .input("%s2%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var defaultCollectionPolicy = new CollectionPolicy("defaultCollectionPolicy", CollectionPolicyArgs.builder()
                .policyConfig(CollectionPolicyPolicyConfigArgs.builder()
                    .resourceMode("all")
                    .regions("cn-hangzhou")
                    .build())
                .dataCode("metering_log")
                .centralizeEnabled(true)
                .productCode("oss")
                .policyName("xc-example-oss-01")
                .enabled(true)
                .dataConfig(CollectionPolicyDataConfigArgs.builder()
                    .dataRegion("cn-hangzhou")
                    .build())
                .centralizeConfig(CollectionPolicyCentralizeConfigArgs.builder()
                    .destTtl(3)
                    .destRegion("cn-shanghai")
                    .destProject(projectCreate01.projectName())
                    .destLogstore(logstoreCreate01.logstoreName())
                    .build())
                .resourceDirectory(CollectionPolicyResourceDirectoryArgs.builder()
                    .accountGroupType("custom")
                    .members("1936728897040477")
                    .build())
                .build());
    
        }
    }
    
    configuration:
      name:
        type: string
        default: terraform-example
    resources:
      default:
        type: random:Integer
        properties:
          min: 10000
          max: 99999
      projectCreate01:
        type: alicloud:log:Project
        name: project_create_01
        properties:
          description: ${name}
          projectName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s1%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      logstoreCreate01:
        type: alicloud:log:Store
        name: logstore_create_01
        properties:
          retentionPeriod: '30'
          shardCount: '2'
          projectName: ${projectCreate01.projectName}
          logstoreName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s1%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      update01:
        type: alicloud:log:Project
        name: update_01
        properties:
          description: ${name}
          projectName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s2%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      logstore002:
        type: alicloud:log:Store
        properties:
          retentionPeriod: '30'
          shardCount: '2'
          projectName: ${update01.projectName}
          logstoreName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s2%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      defaultCollectionPolicy:
        type: alicloud:sls:CollectionPolicy
        name: default
        properties:
          policyConfig:
            resourceMode: all
            regions:
              - cn-hangzhou
          dataCode: metering_log
          centralizeEnabled: true
          productCode: oss
          policyName: xc-example-oss-01
          enabled: true
          dataConfig:
            dataRegion: cn-hangzhou
          centralizeConfig:
            destTtl: '3'
            destRegion: cn-shanghai
            destProject: ${projectCreate01.projectName}
            destLogstore: ${logstoreCreate01.logstoreName}
          resourceDirectory:
            accountGroupType: custom
            members:
              - '1936728897040477'
    

    Enable real-time log query for one or more specific OSS buckets

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    import * as random from "@pulumi/random";
    import * as std from "@pulumi/std";
    
    const config = new pulumi.Config();
    const name = config.get("name") || "terraform-example-on-single-bucket";
    const _default = new random.index.Integer("default", {
        min: 10000,
        max: 99999,
    });
    const projectCreate01 = new alicloud.log.Project("project_create_01", {
        description: name,
        projectName: std.format({
            input: "%s1%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const logstoreCreate01 = new alicloud.log.Store("logstore_create_01", {
        retentionPeriod: 30,
        shardCount: 2,
        projectName: projectCreate01.projectName,
        logstoreName: std.format({
            input: "%s1%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const update01 = new alicloud.log.Project("update_01", {
        description: name,
        projectName: std.format({
            input: "%s2%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const logstore002 = new alicloud.log.Store("logstore002", {
        retentionPeriod: 30,
        shardCount: 2,
        projectName: update01.projectName,
        logstoreName: std.format({
            input: "%s2%s",
            args: [
                name,
                _default.result,
            ],
        }).then(invoke => invoke.result),
    });
    const bucket = new alicloud.oss.Bucket("bucket", {bucket: std.format({
        input: "%s1%s",
        args: [
            name,
            _default.result,
        ],
    }).then(invoke => invoke.result)});
    const defaultCollectionPolicy = new alicloud.sls.CollectionPolicy("default", {
        policyConfig: {
            resourceMode: "instanceMode",
            instanceIds: [bucket.id],
        },
        dataCode: "access_log",
        centralizeEnabled: false,
        productCode: "oss",
        policyName: "xc-example-oss-01",
        enabled: true,
    });
    
    import pulumi
    import pulumi_alicloud as alicloud
    import pulumi_random as random
    import pulumi_std as std
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "terraform-example-on-single-bucket"
    default = random.index.Integer("default",
        min=10000,
        max=99999)
    project_create01 = alicloud.log.Project("project_create_01",
        description=name,
        project_name=std.format(input="%s1%s",
            args=[
                name,
                default["result"],
            ]).result)
    logstore_create01 = alicloud.log.Store("logstore_create_01",
        retention_period=30,
        shard_count=2,
        project_name=project_create01.project_name,
        logstore_name=std.format(input="%s1%s",
            args=[
                name,
                default["result"],
            ]).result)
    update01 = alicloud.log.Project("update_01",
        description=name,
        project_name=std.format(input="%s2%s",
            args=[
                name,
                default["result"],
            ]).result)
    logstore002 = alicloud.log.Store("logstore002",
        retention_period=30,
        shard_count=2,
        project_name=update01.project_name,
        logstore_name=std.format(input="%s2%s",
            args=[
                name,
                default["result"],
            ]).result)
    bucket = alicloud.oss.Bucket("bucket", bucket=std.format(input="%s1%s",
        args=[
            name,
            default["result"],
        ]).result)
    default_collection_policy = alicloud.sls.CollectionPolicy("default",
        policy_config={
            "resource_mode": "instanceMode",
            "instance_ids": [bucket.id],
        },
        data_code="access_log",
        centralize_enabled=False,
        product_code="oss",
        policy_name="xc-example-oss-01",
        enabled=True)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/log"
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/oss"
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/sls"
    	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
    	"github.com/pulumi/pulumi-std/sdk/go/std"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		name := "terraform-example-on-single-bucket"
    		if param := cfg.Get("name"); param != "" {
    			name = param
    		}
    		_default, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
    			Min: 10000,
    			Max: 99999,
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s1%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		projectCreate01, err := log.NewProject(ctx, "project_create_01", &log.ProjectArgs{
    			Description: pulumi.String(name),
    			ProjectName: pulumi.String(invokeFormat.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat1, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s1%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = log.NewStore(ctx, "logstore_create_01", &log.StoreArgs{
    			RetentionPeriod: pulumi.Int(30),
    			ShardCount:      pulumi.Int(2),
    			ProjectName:     projectCreate01.ProjectName,
    			LogstoreName:    pulumi.String(invokeFormat1.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat2, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s2%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		update01, err := log.NewProject(ctx, "update_01", &log.ProjectArgs{
    			Description: pulumi.String(name),
    			ProjectName: pulumi.String(invokeFormat2.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat3, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s2%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = log.NewStore(ctx, "logstore002", &log.StoreArgs{
    			RetentionPeriod: pulumi.Int(30),
    			ShardCount:      pulumi.Int(2),
    			ProjectName:     update01.ProjectName,
    			LogstoreName:    pulumi.String(invokeFormat3.Result),
    		})
    		if err != nil {
    			return err
    		}
    		invokeFormat4, err := std.Format(ctx, &std.FormatArgs{
    			Input: "%s1%s",
    			Args: []interface{}{
    				name,
    				_default.Result,
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		bucket, err := oss.NewBucket(ctx, "bucket", &oss.BucketArgs{
    			Bucket: pulumi.String(invokeFormat4.Result),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = sls.NewCollectionPolicy(ctx, "default", &sls.CollectionPolicyArgs{
    			PolicyConfig: &sls.CollectionPolicyPolicyConfigArgs{
    				ResourceMode: pulumi.String("instanceMode"),
    				InstanceIds: pulumi.StringArray{
    					bucket.ID(),
    				},
    			},
    			DataCode:          pulumi.String("access_log"),
    			CentralizeEnabled: pulumi.Bool(false),
    			ProductCode:       pulumi.String("oss"),
    			PolicyName:        pulumi.String("xc-example-oss-01"),
    			Enabled:           pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    using Random = Pulumi.Random;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var name = config.Get("name") ?? "terraform-example-on-single-bucket";
        var @default = new Random.Index.Integer("default", new()
        {
            Min = 10000,
            Max = 99999,
        });
    
        var projectCreate01 = new AliCloud.Log.Project("project_create_01", new()
        {
            Description = name,
            ProjectName = Std.Format.Invoke(new()
            {
                Input = "%s1%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var logstoreCreate01 = new AliCloud.Log.Store("logstore_create_01", new()
        {
            RetentionPeriod = 30,
            ShardCount = 2,
            ProjectName = projectCreate01.ProjectName,
            LogstoreName = Std.Format.Invoke(new()
            {
                Input = "%s1%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var update01 = new AliCloud.Log.Project("update_01", new()
        {
            Description = name,
            ProjectName = Std.Format.Invoke(new()
            {
                Input = "%s2%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var logstore002 = new AliCloud.Log.Store("logstore002", new()
        {
            RetentionPeriod = 30,
            ShardCount = 2,
            ProjectName = update01.ProjectName,
            LogstoreName = Std.Format.Invoke(new()
            {
                Input = "%s2%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var bucket = new AliCloud.Oss.Bucket("bucket", new()
        {
            BucketName = Std.Format.Invoke(new()
            {
                Input = "%s1%s",
                Args = new[]
                {
                    name,
                    @default.Result,
                },
            }).Apply(invoke => invoke.Result),
        });
    
        var defaultCollectionPolicy = new AliCloud.Sls.CollectionPolicy("default", new()
        {
            PolicyConfig = new AliCloud.Sls.Inputs.CollectionPolicyPolicyConfigArgs
            {
                ResourceMode = "instanceMode",
                InstanceIds = new[]
                {
                    bucket.Id,
                },
            },
            DataCode = "access_log",
            CentralizeEnabled = false,
            ProductCode = "oss",
            PolicyName = "xc-example-oss-01",
            Enabled = true,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.Integer;
    import com.pulumi.random.IntegerArgs;
    import com.pulumi.alicloud.log.Project;
    import com.pulumi.alicloud.log.ProjectArgs;
    import com.pulumi.std.StdFunctions;
    import com.pulumi.std.inputs.FormatArgs;
    import com.pulumi.alicloud.log.Store;
    import com.pulumi.alicloud.log.StoreArgs;
    import com.pulumi.alicloud.oss.Bucket;
    import com.pulumi.alicloud.oss.BucketArgs;
    import com.pulumi.alicloud.sls.CollectionPolicy;
    import com.pulumi.alicloud.sls.CollectionPolicyArgs;
    import com.pulumi.alicloud.sls.inputs.CollectionPolicyPolicyConfigArgs;
    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 config = ctx.config();
            final var name = config.get("name").orElse("terraform-example-on-single-bucket");
            var default_ = new Integer("default", IntegerArgs.builder()
                .min(10000)
                .max(99999)
                .build());
    
            var projectCreate01 = new Project("projectCreate01", ProjectArgs.builder()
                .description(name)
                .projectName(StdFunctions.format(FormatArgs.builder()
                    .input("%s1%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var logstoreCreate01 = new Store("logstoreCreate01", StoreArgs.builder()
                .retentionPeriod(30)
                .shardCount(2)
                .projectName(projectCreate01.projectName())
                .logstoreName(StdFunctions.format(FormatArgs.builder()
                    .input("%s1%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var update01 = new Project("update01", ProjectArgs.builder()
                .description(name)
                .projectName(StdFunctions.format(FormatArgs.builder()
                    .input("%s2%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var logstore002 = new Store("logstore002", StoreArgs.builder()
                .retentionPeriod(30)
                .shardCount(2)
                .projectName(update01.projectName())
                .logstoreName(StdFunctions.format(FormatArgs.builder()
                    .input("%s2%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var bucket = new Bucket("bucket", BucketArgs.builder()
                .bucket(StdFunctions.format(FormatArgs.builder()
                    .input("%s1%s")
                    .args(                
                        name,
                        default_.result())
                    .build()).result())
                .build());
    
            var defaultCollectionPolicy = new CollectionPolicy("defaultCollectionPolicy", CollectionPolicyArgs.builder()
                .policyConfig(CollectionPolicyPolicyConfigArgs.builder()
                    .resourceMode("instanceMode")
                    .instanceIds(bucket.id())
                    .build())
                .dataCode("access_log")
                .centralizeEnabled(false)
                .productCode("oss")
                .policyName("xc-example-oss-01")
                .enabled(true)
                .build());
    
        }
    }
    
    configuration:
      name:
        type: string
        default: terraform-example-on-single-bucket
    resources:
      default:
        type: random:Integer
        properties:
          min: 10000
          max: 99999
      projectCreate01:
        type: alicloud:log:Project
        name: project_create_01
        properties:
          description: ${name}
          projectName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s1%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      logstoreCreate01:
        type: alicloud:log:Store
        name: logstore_create_01
        properties:
          retentionPeriod: '30'
          shardCount: '2'
          projectName: ${projectCreate01.projectName}
          logstoreName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s1%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      update01:
        type: alicloud:log:Project
        name: update_01
        properties:
          description: ${name}
          projectName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s2%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      logstore002:
        type: alicloud:log:Store
        properties:
          retentionPeriod: '30'
          shardCount: '2'
          projectName: ${update01.projectName}
          logstoreName:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s2%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      bucket:
        type: alicloud:oss:Bucket
        properties:
          bucket:
            fn::invoke:
              function: std:format
              arguments:
                input: '%s1%s'
                args:
                  - ${name}
                  - ${default.result}
              return: result
      defaultCollectionPolicy:
        type: alicloud:sls:CollectionPolicy
        name: default
        properties:
          policyConfig:
            resourceMode: instanceMode
            instanceIds:
              - ${bucket.id}
          dataCode: access_log
          centralizeEnabled: false
          productCode: oss
          policyName: xc-example-oss-01
          enabled: true
    

    📚 Need more examples? VIEW MORE EXAMPLES

    Create CollectionPolicy Resource

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

    Constructor syntax

    new CollectionPolicy(name: string, args: CollectionPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def CollectionPolicy(resource_name: str,
                         args: CollectionPolicyArgs,
                         opts: Optional[ResourceOptions] = None)
    
    @overload
    def CollectionPolicy(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         data_code: Optional[str] = None,
                         enabled: Optional[bool] = None,
                         policy_config: Optional[CollectionPolicyPolicyConfigArgs] = None,
                         policy_name: Optional[str] = None,
                         product_code: Optional[str] = None,
                         centralize_config: Optional[CollectionPolicyCentralizeConfigArgs] = None,
                         centralize_enabled: Optional[bool] = None,
                         data_config: Optional[CollectionPolicyDataConfigArgs] = None,
                         resource_directory: Optional[CollectionPolicyResourceDirectoryArgs] = None)
    func NewCollectionPolicy(ctx *Context, name string, args CollectionPolicyArgs, opts ...ResourceOption) (*CollectionPolicy, error)
    public CollectionPolicy(string name, CollectionPolicyArgs args, CustomResourceOptions? opts = null)
    public CollectionPolicy(String name, CollectionPolicyArgs args)
    public CollectionPolicy(String name, CollectionPolicyArgs args, CustomResourceOptions options)
    
    type: alicloud:sls:CollectionPolicy
    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 CollectionPolicyArgs
    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 CollectionPolicyArgs
    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 CollectionPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args CollectionPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args CollectionPolicyArgs
    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 collectionPolicyResource = new AliCloud.Sls.CollectionPolicy("collectionPolicyResource", new()
    {
        DataCode = "string",
        Enabled = false,
        PolicyConfig = new AliCloud.Sls.Inputs.CollectionPolicyPolicyConfigArgs
        {
            ResourceMode = "string",
            InstanceIds = new[]
            {
                "string",
            },
            Regions = new[]
            {
                "string",
            },
            ResourceTags = 
            {
                { "string", "string" },
            },
        },
        PolicyName = "string",
        ProductCode = "string",
        CentralizeConfig = new AliCloud.Sls.Inputs.CollectionPolicyCentralizeConfigArgs
        {
            DestLogstore = "string",
            DestProject = "string",
            DestRegion = "string",
            DestTtl = 0,
        },
        CentralizeEnabled = false,
        DataConfig = new AliCloud.Sls.Inputs.CollectionPolicyDataConfigArgs
        {
            DataProject = "string",
            DataRegion = "string",
        },
        ResourceDirectory = new AliCloud.Sls.Inputs.CollectionPolicyResourceDirectoryArgs
        {
            AccountGroupType = "string",
            Members = new[]
            {
                "string",
            },
        },
    });
    
    example, err := sls.NewCollectionPolicy(ctx, "collectionPolicyResource", &sls.CollectionPolicyArgs{
    	DataCode: pulumi.String("string"),
    	Enabled:  pulumi.Bool(false),
    	PolicyConfig: &sls.CollectionPolicyPolicyConfigArgs{
    		ResourceMode: pulumi.String("string"),
    		InstanceIds: pulumi.StringArray{
    			pulumi.String("string"),
    		},
    		Regions: pulumi.StringArray{
    			pulumi.String("string"),
    		},
    		ResourceTags: pulumi.StringMap{
    			"string": pulumi.String("string"),
    		},
    	},
    	PolicyName:  pulumi.String("string"),
    	ProductCode: pulumi.String("string"),
    	CentralizeConfig: &sls.CollectionPolicyCentralizeConfigArgs{
    		DestLogstore: pulumi.String("string"),
    		DestProject:  pulumi.String("string"),
    		DestRegion:   pulumi.String("string"),
    		DestTtl:      pulumi.Int(0),
    	},
    	CentralizeEnabled: pulumi.Bool(false),
    	DataConfig: &sls.CollectionPolicyDataConfigArgs{
    		DataProject: pulumi.String("string"),
    		DataRegion:  pulumi.String("string"),
    	},
    	ResourceDirectory: &sls.CollectionPolicyResourceDirectoryArgs{
    		AccountGroupType: pulumi.String("string"),
    		Members: pulumi.StringArray{
    			pulumi.String("string"),
    		},
    	},
    })
    
    var collectionPolicyResource = new CollectionPolicy("collectionPolicyResource", CollectionPolicyArgs.builder()
        .dataCode("string")
        .enabled(false)
        .policyConfig(CollectionPolicyPolicyConfigArgs.builder()
            .resourceMode("string")
            .instanceIds("string")
            .regions("string")
            .resourceTags(Map.of("string", "string"))
            .build())
        .policyName("string")
        .productCode("string")
        .centralizeConfig(CollectionPolicyCentralizeConfigArgs.builder()
            .destLogstore("string")
            .destProject("string")
            .destRegion("string")
            .destTtl(0)
            .build())
        .centralizeEnabled(false)
        .dataConfig(CollectionPolicyDataConfigArgs.builder()
            .dataProject("string")
            .dataRegion("string")
            .build())
        .resourceDirectory(CollectionPolicyResourceDirectoryArgs.builder()
            .accountGroupType("string")
            .members("string")
            .build())
        .build());
    
    collection_policy_resource = alicloud.sls.CollectionPolicy("collectionPolicyResource",
        data_code="string",
        enabled=False,
        policy_config={
            "resource_mode": "string",
            "instance_ids": ["string"],
            "regions": ["string"],
            "resource_tags": {
                "string": "string",
            },
        },
        policy_name="string",
        product_code="string",
        centralize_config={
            "dest_logstore": "string",
            "dest_project": "string",
            "dest_region": "string",
            "dest_ttl": 0,
        },
        centralize_enabled=False,
        data_config={
            "data_project": "string",
            "data_region": "string",
        },
        resource_directory={
            "account_group_type": "string",
            "members": ["string"],
        })
    
    const collectionPolicyResource = new alicloud.sls.CollectionPolicy("collectionPolicyResource", {
        dataCode: "string",
        enabled: false,
        policyConfig: {
            resourceMode: "string",
            instanceIds: ["string"],
            regions: ["string"],
            resourceTags: {
                string: "string",
            },
        },
        policyName: "string",
        productCode: "string",
        centralizeConfig: {
            destLogstore: "string",
            destProject: "string",
            destRegion: "string",
            destTtl: 0,
        },
        centralizeEnabled: false,
        dataConfig: {
            dataProject: "string",
            dataRegion: "string",
        },
        resourceDirectory: {
            accountGroupType: "string",
            members: ["string"],
        },
    });
    
    type: alicloud:sls:CollectionPolicy
    properties:
        centralizeConfig:
            destLogstore: string
            destProject: string
            destRegion: string
            destTtl: 0
        centralizeEnabled: false
        dataCode: string
        dataConfig:
            dataProject: string
            dataRegion: string
        enabled: false
        policyConfig:
            instanceIds:
                - string
            regions:
                - string
            resourceMode: string
            resourceTags:
                string: string
        policyName: string
        productCode: string
        resourceDirectory:
            accountGroupType: string
            members:
                - string
    

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

    DataCode string
    Log type code.
    Enabled bool
    Whether enabled.
    PolicyConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    PolicyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    ProductCode string
    Product code.
    CentralizeConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    CentralizeEnabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    DataConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    ResourceDirectory Pulumi.AliCloud.Sls.Inputs.CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    DataCode string
    Log type code.
    Enabled bool
    Whether enabled.
    PolicyConfig CollectionPolicyPolicyConfigArgs
    Collection rule configuration. See policy_config below.
    PolicyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    ProductCode string
    Product code.
    CentralizeConfig CollectionPolicyCentralizeConfigArgs
    Centralized forwarding configuration. See centralize_config below.
    CentralizeEnabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    DataConfig CollectionPolicyDataConfigArgs
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    ResourceDirectory CollectionPolicyResourceDirectoryArgs
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    dataCode String
    Log type code.
    enabled Boolean
    Whether enabled.
    policyConfig CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    policyName String
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode String
    Product code.
    centralizeConfig CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled Boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataConfig CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    resourceDirectory CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    dataCode string
    Log type code.
    enabled boolean
    Whether enabled.
    policyConfig CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    policyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode string
    Product code.
    centralizeConfig CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataConfig CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    resourceDirectory CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    data_code str
    Log type code.
    enabled bool
    Whether enabled.
    policy_config CollectionPolicyPolicyConfigArgs
    Collection rule configuration. See policy_config below.
    policy_name str
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    product_code str
    Product code.
    centralize_config CollectionPolicyCentralizeConfigArgs
    Centralized forwarding configuration. See centralize_config below.
    centralize_enabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    data_config CollectionPolicyDataConfigArgs
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    resource_directory CollectionPolicyResourceDirectoryArgs
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    dataCode String
    Log type code.
    enabled Boolean
    Whether enabled.
    policyConfig Property Map
    Collection rule configuration. See policy_config below.
    policyName String
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode String
    Product code.
    centralizeConfig Property Map
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled Boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataConfig Property Map
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    resourceDirectory Property Map
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.

    Outputs

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

    Get an existing CollectionPolicy 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?: CollectionPolicyState, opts?: CustomResourceOptions): CollectionPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            centralize_config: Optional[CollectionPolicyCentralizeConfigArgs] = None,
            centralize_enabled: Optional[bool] = None,
            data_code: Optional[str] = None,
            data_config: Optional[CollectionPolicyDataConfigArgs] = None,
            enabled: Optional[bool] = None,
            policy_config: Optional[CollectionPolicyPolicyConfigArgs] = None,
            policy_name: Optional[str] = None,
            product_code: Optional[str] = None,
            resource_directory: Optional[CollectionPolicyResourceDirectoryArgs] = None) -> CollectionPolicy
    func GetCollectionPolicy(ctx *Context, name string, id IDInput, state *CollectionPolicyState, opts ...ResourceOption) (*CollectionPolicy, error)
    public static CollectionPolicy Get(string name, Input<string> id, CollectionPolicyState? state, CustomResourceOptions? opts = null)
    public static CollectionPolicy get(String name, Output<String> id, CollectionPolicyState state, CustomResourceOptions options)
    resources:  _:    type: alicloud:sls:CollectionPolicy    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:
    CentralizeConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    CentralizeEnabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    DataCode string
    Log type code.
    DataConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    Enabled bool
    Whether enabled.
    PolicyConfig Pulumi.AliCloud.Sls.Inputs.CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    PolicyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    ProductCode string
    Product code.
    ResourceDirectory Pulumi.AliCloud.Sls.Inputs.CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    CentralizeConfig CollectionPolicyCentralizeConfigArgs
    Centralized forwarding configuration. See centralize_config below.
    CentralizeEnabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    DataCode string
    Log type code.
    DataConfig CollectionPolicyDataConfigArgs
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    Enabled bool
    Whether enabled.
    PolicyConfig CollectionPolicyPolicyConfigArgs
    Collection rule configuration. See policy_config below.
    PolicyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    ProductCode string
    Product code.
    ResourceDirectory CollectionPolicyResourceDirectoryArgs
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    centralizeConfig CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled Boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataCode String
    Log type code.
    dataConfig CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    enabled Boolean
    Whether enabled.
    policyConfig CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    policyName String
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode String
    Product code.
    resourceDirectory CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    centralizeConfig CollectionPolicyCentralizeConfig
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataCode string
    Log type code.
    dataConfig CollectionPolicyDataConfig
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    enabled boolean
    Whether enabled.
    policyConfig CollectionPolicyPolicyConfig
    Collection rule configuration. See policy_config below.
    policyName string
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode string
    Product code.
    resourceDirectory CollectionPolicyResourceDirectory
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    centralize_config CollectionPolicyCentralizeConfigArgs
    Centralized forwarding configuration. See centralize_config below.
    centralize_enabled bool
    Specifies whether to enable centralized forwarding. Default value: false.
    data_code str
    Log type code.
    data_config CollectionPolicyDataConfigArgs
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    enabled bool
    Whether enabled.
    policy_config CollectionPolicyPolicyConfigArgs
    Collection rule configuration. See policy_config below.
    policy_name str
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    product_code str
    Product code.
    resource_directory CollectionPolicyResourceDirectoryArgs
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.
    centralizeConfig Property Map
    Centralized forwarding configuration. See centralize_config below.
    centralizeEnabled Boolean
    Specifies whether to enable centralized forwarding. Default value: false.
    dataCode String
    Log type code.
    dataConfig Property Map
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration. See data_config below.
    enabled Boolean
    Whether enabled.
    policyConfig Property Map
    Collection rule configuration. See policy_config below.
    policyName String
    The naming rules are as follows:

    • It can contain only lowercase letters, digits, hyphens (-), and underscores (_).
    • It must start with a letter.
    • Its length must be between 3 and 63 characters.
    productCode String
    Product code.
    resourceDirectory Property Map
    Resource Directory configuration. The account must have Resource Directory enabled and be either a management account or a delegated administrator. See resource_directory below.

    Supporting Types

    CollectionPolicyCentralizeConfig, CollectionPolicyCentralizeConfigArgs

    DestLogstore string
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    DestProject string
    Destination project for centralized forwarding. Its region must match destRegion.
    DestRegion string
    Destination region for centralized forwarding.
    DestTtl int
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.
    DestLogstore string
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    DestProject string
    Destination project for centralized forwarding. Its region must match destRegion.
    DestRegion string
    Destination region for centralized forwarding.
    DestTtl int
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.
    destLogstore String
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    destProject String
    Destination project for centralized forwarding. Its region must match destRegion.
    destRegion String
    Destination region for centralized forwarding.
    destTtl Integer
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.
    destLogstore string
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    destProject string
    Destination project for centralized forwarding. Its region must match destRegion.
    destRegion string
    Destination region for centralized forwarding.
    destTtl number
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.
    dest_logstore str
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    dest_project str
    Destination project for centralized forwarding. Its region must match destRegion.
    dest_region str
    Destination region for centralized forwarding.
    dest_ttl int
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.
    destLogstore String
    Destination Logstore for centralized forwarding. Its region must match destRegion and it must belong to destProject.
    destProject String
    Destination project for centralized forwarding. Its region must match destRegion.
    destRegion String
    Destination region for centralized forwarding.
    destTtl Number
    Retention period (in days) for the destination Logstore in centralized forwarding. This setting takes effect only when the destination Logstore is created for the first time.

    CollectionPolicyDataConfig, CollectionPolicyDataConfigArgs

    DataProject string
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    DataRegion string
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.
    DataProject string
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    DataRegion string
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.
    dataProject String
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    dataRegion String
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.
    dataProject string
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    dataRegion string
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.
    data_project str
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    data_region str
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.
    dataProject String
    This setting is valid only when the log type is a global log type—for example, when productCode is sls.
    dataRegion String
    This parameter can be configured only when the log type is a global log type—for example, when productCode is sls. It indicates that global logs will be collected to the specified region upon initial configuration.

    CollectionPolicyPolicyConfig, CollectionPolicyPolicyConfigArgs

    ResourceMode string
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    InstanceIds List<string>
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    Regions List<string>
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    ResourceTags Dictionary<string, string>
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.
    ResourceMode string
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    InstanceIds []string
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    Regions []string
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    ResourceTags map[string]string
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.
    resourceMode String
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    instanceIds List<String>
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    regions List<String>
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    resourceTags Map<String,String>
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.
    resourceMode string
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    instanceIds string[]
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    regions string[]
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    resourceTags {[key: string]: string}
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.
    resource_mode str
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    instance_ids Sequence[str]
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    regions Sequence[str]
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    resource_tags Mapping[str, str]
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.
    resourceMode String
    Resource collection mode. If set to all, all instances under the account are collected into the default Logstore. If set to attributeMode, instances are filtered based on their region attributes and resource tags. If set to instanceMode, instances are filtered by their instance IDs.
    instanceIds List<String>
    The set of instance IDs. This parameter is valid only when resourceMode is set to instanceMode. Only instances whose IDs are included in this set are collected.
    regions List<String>
    The set of regions to which instances belong. This parameter is valid only when resourceMode is set to attributeMode and supports wildcards. If the region set filter is an empty array, no region-based filtering is applied, and all instances satisfy the region condition. Otherwise, only instances whose region attribute is included in this region set are collected. The region set and resource tags work together. An instance is collected only if it satisfies both conditions.
    resourceTags Map<String>
    Resource tags. This parameter is valid only when resourceMode is set to attributeMode.
    If the resource tag filter is empty, no filtering by resource tags is applied, and all instances satisfy the resource tag condition. Otherwise, only instances whose resource tag attributes fully match the specified resource tag configuration are collected. Resource tags and the region set of the instance work together. An instance is collected only if it satisfies both conditions.

    CollectionPolicyResourceDirectory, CollectionPolicyResourceDirectoryArgs

    AccountGroupType string
    Supports the all (select all) mode and custom mode under this Resource Directory.
    Members List<string>
    The list of member accounts when the Resource Directory is configured in custom mode.
    AccountGroupType string
    Supports the all (select all) mode and custom mode under this Resource Directory.
    Members []string
    The list of member accounts when the Resource Directory is configured in custom mode.
    accountGroupType String
    Supports the all (select all) mode and custom mode under this Resource Directory.
    members List<String>
    The list of member accounts when the Resource Directory is configured in custom mode.
    accountGroupType string
    Supports the all (select all) mode and custom mode under this Resource Directory.
    members string[]
    The list of member accounts when the Resource Directory is configured in custom mode.
    account_group_type str
    Supports the all (select all) mode and custom mode under this Resource Directory.
    members Sequence[str]
    The list of member accounts when the Resource Directory is configured in custom mode.
    accountGroupType String
    Supports the all (select all) mode and custom mode under this Resource Directory.
    members List<String>
    The list of member accounts when the Resource Directory is configured in custom mode.

    Import

    Log Service (SLS) Collection Policy can be imported using the id, e.g.

    $ pulumi import alicloud:sls/collectionPolicy:CollectionPolicy example <policy_name>
    

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

    Package Details

    Repository
    Alibaba Cloud pulumi/pulumi-alicloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the alicloud Terraform Provider.
    alicloud logo
    Viewing docs for Alibaba Cloud v3.97.0
    published on Saturday, Mar 14, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.