com.pulumi.alicloud.fc.kotlin.Function.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pulumi-alicloud-kotlin Show documentation
Show all versions of pulumi-alicloud-kotlin Show documentation
Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.
@file:Suppress("NAME_SHADOWING", "DEPRECATION")
package com.pulumi.alicloud.fc.kotlin
import com.pulumi.alicloud.fc.kotlin.outputs.FunctionCustomContainerConfig
import com.pulumi.alicloud.fc.kotlin.outputs.FunctionCustomContainerConfig.Companion.toKotlin
import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.Map
/**
* Builder for [Function].
*/
@PulumiTagMarker
public class FunctionResourceBuilder internal constructor() {
public var name: String? = null
public var args: FunctionArgs = FunctionArgs()
public var opts: CustomResourceOptions = CustomResourceOptions()
/**
* @param name The _unique_ name of the resulting resource.
*/
public fun name(`value`: String) {
this.name = value
}
/**
* @param block The arguments to use to populate this resource's properties.
*/
public suspend fun args(block: suspend FunctionArgsBuilder.() -> Unit) {
val builder = FunctionArgsBuilder()
block(builder)
this.args = builder.build()
}
/**
* @param block A bag of options that control this resource's behavior.
*/
public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
}
internal fun build(): Function {
val builtJavaResource = com.pulumi.alicloud.fc.Function(
this.name,
this.args.toJava(),
this.opts.toJava(),
)
return Function(builtJavaResource)
}
}
/**
* Provides a Alicloud Function Compute Function resource. Function allows you to trigger execution of code in response to events in Alibaba Cloud. The Function itself includes source code and runtime configuration.
* For information about Service and how to use it, see [What is Function Compute](https://www.alibabacloud.com/help/en/fc/developer-reference/api-createfunction).
* > **NOTE:** The resource requires a provider field 'account_id'. See account_id.
* > **NOTE:** Available since v1.10.0.
* ## Example Usage
* Basic Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as alicloud from "@pulumi/alicloud";
* import * as random from "@pulumi/random";
* const _default = new random.index.Integer("default", {
* max: 99999,
* min: 10000,
* });
* const defaultProject = new alicloud.log.Project("default", {projectName: `example-value-${_default.result}`});
* const defaultStore = new alicloud.log.Store("default", {
* projectName: defaultProject.projectName,
* logstoreName: "example-value",
* });
* const defaultRole = new alicloud.ram.Role("default", {
* name: `fcservicerole-${_default.result}`,
* document: ` {
* "Statement": [
* {
* "Action": "sts:AssumeRole",
* "Effect": "Allow",
* "Principal": {
* "Service": [
* "fc.aliyuncs.com"
* ]
* }
* }
* ],
* "Version": "1"
* }
* `,
* description: "this is a example",
* force: true,
* });
* const defaultRolePolicyAttachment = new alicloud.ram.RolePolicyAttachment("default", {
* roleName: defaultRole.name,
* policyName: "AliyunLogFullAccess",
* policyType: "System",
* });
* const defaultService = new alicloud.fc.Service("default", {
* name: `example-value-${_default.result}`,
* description: "example-value",
* role: defaultRole.arn,
* logConfig: {
* project: defaultProject.projectName,
* logstore: defaultStore.logstoreName,
* enableInstanceMetrics: true,
* enableRequestMetrics: true,
* },
* });
* const defaultBucket = new alicloud.oss.Bucket("default", {bucket: `terraform-example-${_default.result}`});
* // If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* const defaultBucketObject = new alicloud.oss.BucketObject("default", {
* bucket: defaultBucket.id,
* key: "index.py",
* content: `import logging
* def handler(event, context):
* logger = logging.getLogger()
* logger.info('hello world')
* return 'hello world'`,
* });
* const foo = new alicloud.fc.Function("foo", {
* service: defaultService.name,
* name: "terraform-example",
* description: "example",
* ossBucket: defaultBucket.id,
* ossKey: defaultBucketObject.key,
* memorySize: 512,
* runtime: "python3.10",
* handler: "hello.handler",
* environmentVariables: {
* prefix: "terraform",
* },
* });
* ```
* ```python
* import pulumi
* import pulumi_alicloud as alicloud
* import pulumi_random as random
* default = random.index.Integer("default",
* max=99999,
* min=10000)
* default_project = alicloud.log.Project("default", project_name=f"example-value-{default['result']}")
* default_store = alicloud.log.Store("default",
* project_name=default_project.project_name,
* logstore_name="example-value")
* default_role = alicloud.ram.Role("default",
* name=f"fcservicerole-{default['result']}",
* document=""" {
* "Statement": [
* {
* "Action": "sts:AssumeRole",
* "Effect": "Allow",
* "Principal": {
* "Service": [
* "fc.aliyuncs.com"
* ]
* }
* }
* ],
* "Version": "1"
* }
* """,
* description="this is a example",
* force=True)
* default_role_policy_attachment = alicloud.ram.RolePolicyAttachment("default",
* role_name=default_role.name,
* policy_name="AliyunLogFullAccess",
* policy_type="System")
* default_service = alicloud.fc.Service("default",
* name=f"example-value-{default['result']}",
* description="example-value",
* role=default_role.arn,
* log_config={
* "project": default_project.project_name,
* "logstore": default_store.logstore_name,
* "enable_instance_metrics": True,
* "enable_request_metrics": True,
* })
* default_bucket = alicloud.oss.Bucket("default", bucket=f"terraform-example-{default['result']}")
* # If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* default_bucket_object = alicloud.oss.BucketObject("default",
* bucket=default_bucket.id,
* key="index.py",
* content="""import logging
* def handler(event, context):
* logger = logging.getLogger()
* logger.info('hello world')
* return 'hello world'""")
* foo = alicloud.fc.Function("foo",
* service=default_service.name,
* name="terraform-example",
* description="example",
* oss_bucket=default_bucket.id,
* oss_key=default_bucket_object.key,
* memory_size=512,
* runtime="python3.10",
* handler="hello.handler",
* environment_variables={
* "prefix": "terraform",
* })
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using AliCloud = Pulumi.AliCloud;
* using Random = Pulumi.Random;
* return await Deployment.RunAsync(() =>
* {
* var @default = new Random.Index.Integer("default", new()
* {
* Max = 99999,
* Min = 10000,
* });
* var defaultProject = new AliCloud.Log.Project("default", new()
* {
* ProjectName = $"example-value-{@default.Result}",
* });
* var defaultStore = new AliCloud.Log.Store("default", new()
* {
* ProjectName = defaultProject.ProjectName,
* LogstoreName = "example-value",
* });
* var defaultRole = new AliCloud.Ram.Role("default", new()
* {
* Name = $"fcservicerole-{@default.Result}",
* Document = @" {
* ""Statement"": [
* {
* ""Action"": ""sts:AssumeRole"",
* ""Effect"": ""Allow"",
* ""Principal"": {
* ""Service"": [
* ""fc.aliyuncs.com""
* ]
* }
* }
* ],
* ""Version"": ""1""
* }
* ",
* Description = "this is a example",
* Force = true,
* });
* var defaultRolePolicyAttachment = new AliCloud.Ram.RolePolicyAttachment("default", new()
* {
* RoleName = defaultRole.Name,
* PolicyName = "AliyunLogFullAccess",
* PolicyType = "System",
* });
* var defaultService = new AliCloud.FC.Service("default", new()
* {
* Name = $"example-value-{@default.Result}",
* Description = "example-value",
* Role = defaultRole.Arn,
* LogConfig = new AliCloud.FC.Inputs.ServiceLogConfigArgs
* {
* Project = defaultProject.ProjectName,
* Logstore = defaultStore.LogstoreName,
* EnableInstanceMetrics = true,
* EnableRequestMetrics = true,
* },
* });
* var defaultBucket = new AliCloud.Oss.Bucket("default", new()
* {
* BucketName = $"terraform-example-{@default.Result}",
* });
* // If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* var defaultBucketObject = new AliCloud.Oss.BucketObject("default", new()
* {
* Bucket = defaultBucket.Id,
* Key = "index.py",
* Content = @"import logging
* def handler(event, context):
* logger = logging.getLogger()
* logger.info('hello world')
* return 'hello world'",
* });
* var foo = new AliCloud.FC.Function("foo", new()
* {
* Service = defaultService.Name,
* Name = "terraform-example",
* Description = "example",
* OssBucket = defaultBucket.Id,
* OssKey = defaultBucketObject.Key,
* MemorySize = 512,
* Runtime = "python3.10",
* Handler = "hello.handler",
* EnvironmentVariables =
* {
* { "prefix", "terraform" },
* },
* });
* });
* ```
* ```go
* package main
* import (
* "fmt"
* "github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/fc"
* "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/ram"
* "github.com/pulumi/pulumi-random/sdk/v4/go/random"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* _, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
* Max: 99999,
* Min: 10000,
* })
* if err != nil {
* return err
* }
* defaultProject, err := log.NewProject(ctx, "default", &log.ProjectArgs{
* ProjectName: pulumi.Sprintf("example-value-%v", _default.Result),
* })
* if err != nil {
* return err
* }
* defaultStore, err := log.NewStore(ctx, "default", &log.StoreArgs{
* ProjectName: defaultProject.ProjectName,
* LogstoreName: pulumi.String("example-value"),
* })
* if err != nil {
* return err
* }
* defaultRole, err := ram.NewRole(ctx, "default", &ram.RoleArgs{
* Name: pulumi.Sprintf("fcservicerole-%v", _default.Result),
* Document: pulumi.String(` {
* "Statement": [
* {
* "Action": "sts:AssumeRole",
* "Effect": "Allow",
* "Principal": {
* "Service": [
* "fc.aliyuncs.com"
* ]
* }
* }
* ],
* "Version": "1"
* }
* `),
* Description: pulumi.String("this is a example"),
* Force: pulumi.Bool(true),
* })
* if err != nil {
* return err
* }
* _, err = ram.NewRolePolicyAttachment(ctx, "default", &ram.RolePolicyAttachmentArgs{
* RoleName: defaultRole.Name,
* PolicyName: pulumi.String("AliyunLogFullAccess"),
* PolicyType: pulumi.String("System"),
* })
* if err != nil {
* return err
* }
* defaultService, err := fc.NewService(ctx, "default", &fc.ServiceArgs{
* Name: pulumi.Sprintf("example-value-%v", _default.Result),
* Description: pulumi.String("example-value"),
* Role: defaultRole.Arn,
* LogConfig: &fc.ServiceLogConfigArgs{
* Project: defaultProject.ProjectName,
* Logstore: defaultStore.LogstoreName,
* EnableInstanceMetrics: pulumi.Bool(true),
* EnableRequestMetrics: pulumi.Bool(true),
* },
* })
* if err != nil {
* return err
* }
* defaultBucket, err := oss.NewBucket(ctx, "default", &oss.BucketArgs{
* Bucket: pulumi.Sprintf("terraform-example-%v", _default.Result),
* })
* if err != nil {
* return err
* }
* // If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* defaultBucketObject, err := oss.NewBucketObject(ctx, "default", &oss.BucketObjectArgs{
* Bucket: defaultBucket.ID(),
* Key: pulumi.String("index.py"),
* Content: pulumi.String("import logging \ndef handler(event, context): \nlogger = logging.getLogger() \nlogger.info('hello world') \nreturn 'hello world'"),
* })
* if err != nil {
* return err
* }
* _, err = fc.NewFunction(ctx, "foo", &fc.FunctionArgs{
* Service: defaultService.Name,
* Name: pulumi.String("terraform-example"),
* Description: pulumi.String("example"),
* OssBucket: defaultBucket.ID(),
* OssKey: defaultBucketObject.Key,
* MemorySize: pulumi.Int(512),
* Runtime: pulumi.String("python3.10"),
* Handler: pulumi.String("hello.handler"),
* EnvironmentVariables: pulumi.StringMap{
* "prefix": pulumi.String("terraform"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* 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.alicloud.log.Store;
* import com.pulumi.alicloud.log.StoreArgs;
* import com.pulumi.alicloud.ram.Role;
* import com.pulumi.alicloud.ram.RoleArgs;
* import com.pulumi.alicloud.ram.RolePolicyAttachment;
* import com.pulumi.alicloud.ram.RolePolicyAttachmentArgs;
* import com.pulumi.alicloud.fc.Service;
* import com.pulumi.alicloud.fc.ServiceArgs;
* import com.pulumi.alicloud.fc.inputs.ServiceLogConfigArgs;
* import com.pulumi.alicloud.oss.Bucket;
* import com.pulumi.alicloud.oss.BucketArgs;
* import com.pulumi.alicloud.oss.BucketObject;
* import com.pulumi.alicloud.oss.BucketObjectArgs;
* import com.pulumi.alicloud.fc.Function;
* import com.pulumi.alicloud.fc.FunctionArgs;
* 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 default_ = new Integer("default", IntegerArgs.builder()
* .max(99999)
* .min(10000)
* .build());
* var defaultProject = new Project("defaultProject", ProjectArgs.builder()
* .projectName(String.format("example-value-%s", default_.result()))
* .build());
* var defaultStore = new Store("defaultStore", StoreArgs.builder()
* .projectName(defaultProject.projectName())
* .logstoreName("example-value")
* .build());
* var defaultRole = new Role("defaultRole", RoleArgs.builder()
* .name(String.format("fcservicerole-%s", default_.result()))
* .document("""
* {
* "Statement": [
* {
* "Action": "sts:AssumeRole",
* "Effect": "Allow",
* "Principal": {
* "Service": [
* "fc.aliyuncs.com"
* ]
* }
* }
* ],
* "Version": "1"
* }
* """)
* .description("this is a example")
* .force(true)
* .build());
* var defaultRolePolicyAttachment = new RolePolicyAttachment("defaultRolePolicyAttachment", RolePolicyAttachmentArgs.builder()
* .roleName(defaultRole.name())
* .policyName("AliyunLogFullAccess")
* .policyType("System")
* .build());
* var defaultService = new Service("defaultService", ServiceArgs.builder()
* .name(String.format("example-value-%s", default_.result()))
* .description("example-value")
* .role(defaultRole.arn())
* .logConfig(ServiceLogConfigArgs.builder()
* .project(defaultProject.projectName())
* .logstore(defaultStore.logstoreName())
* .enableInstanceMetrics(true)
* .enableRequestMetrics(true)
* .build())
* .build());
* var defaultBucket = new Bucket("defaultBucket", BucketArgs.builder()
* .bucket(String.format("terraform-example-%s", default_.result()))
* .build());
* // If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* var defaultBucketObject = new BucketObject("defaultBucketObject", BucketObjectArgs.builder()
* .bucket(defaultBucket.id())
* .key("index.py")
* .content("""
* import logging
* def handler(event, context):
* logger = logging.getLogger()
* logger.info('hello world')
* return 'hello world' """)
* .build());
* var foo = new Function("foo", FunctionArgs.builder()
* .service(defaultService.name())
* .name("terraform-example")
* .description("example")
* .ossBucket(defaultBucket.id())
* .ossKey(defaultBucketObject.key())
* .memorySize("512")
* .runtime("python3.10")
* .handler("hello.handler")
* .environmentVariables(Map.of("prefix", "terraform"))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* default:
* type: random:integer
* properties:
* max: 99999
* min: 10000
* defaultProject:
* type: alicloud:log:Project
* name: default
* properties:
* projectName: example-value-${default.result}
* defaultStore:
* type: alicloud:log:Store
* name: default
* properties:
* projectName: ${defaultProject.projectName}
* logstoreName: example-value
* defaultRole:
* type: alicloud:ram:Role
* name: default
* properties:
* name: fcservicerole-${default.result}
* document: |2
* {
* "Statement": [
* {
* "Action": "sts:AssumeRole",
* "Effect": "Allow",
* "Principal": {
* "Service": [
* "fc.aliyuncs.com"
* ]
* }
* }
* ],
* "Version": "1"
* }
* description: this is a example
* force: true
* defaultRolePolicyAttachment:
* type: alicloud:ram:RolePolicyAttachment
* name: default
* properties:
* roleName: ${defaultRole.name}
* policyName: AliyunLogFullAccess
* policyType: System
* defaultService:
* type: alicloud:fc:Service
* name: default
* properties:
* name: example-value-${default.result}
* description: example-value
* role: ${defaultRole.arn}
* logConfig:
* project: ${defaultProject.projectName}
* logstore: ${defaultStore.logstoreName}
* enableInstanceMetrics: true
* enableRequestMetrics: true
* defaultBucket:
* type: alicloud:oss:Bucket
* name: default
* properties:
* bucket: terraform-example-${default.result}
* # If you upload the function by OSS Bucket, you need to specify path can't upload by content.
* defaultBucketObject:
* type: alicloud:oss:BucketObject
* name: default
* properties:
* bucket: ${defaultBucket.id}
* key: index.py
* content: "import logging \ndef handler(event, context): \nlogger = logging.getLogger() \nlogger.info('hello world') \nreturn 'hello world'"
* foo:
* type: alicloud:fc:Function
* properties:
* service: ${defaultService.name}
* name: terraform-example
* description: example
* ossBucket: ${defaultBucket.id}
* ossKey: ${defaultBucketObject.key}
* memorySize: '512'
* runtime: python3.10
* handler: hello.handler
* environmentVariables:
* prefix: terraform
* ```
*
* ## Module Support
* You can use to the existing fc module
* to create a function quickly and set several triggers for it.
* ## Import
* Function Compute function can be imported using the id, e.g.
* ```sh
* $ pulumi import alicloud:fc/function:Function foo my-fc-service:hello-world
* ```
*/
public class Function internal constructor(
override val javaResource: com.pulumi.alicloud.fc.Function,
) : KotlinCustomResource(javaResource, FunctionMapper) {
/**
* The port that the function listen to, only valid for [custom runtime](https://www.alibabacloud.com/help/doc-detail/132044.htm) and [custom container runtime](https://www.alibabacloud.com/help/doc-detail/179368.htm).
*/
public val caPort: Output?
get() = javaResource.caPort().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
/**
* The checksum (crc64) of the function code.Used to trigger updates.The value can be generated by data source alicloud_file_crc64_checksum.
* > **NOTE:** For more information, see [Limits](https://www.alibabacloud.com/help/doc-detail/51907.htm).
*/
public val codeChecksum: Output
get() = javaResource.codeChecksum().applyValue({ args0 -> args0 })
/**
* The configuration for custom container runtime.See `custom_container_config` below.
*/
public val customContainerConfig: Output?
get() = javaResource.customContainerConfig().applyValue({ args0 ->
args0.map({ args0 ->
args0.let({ args0 -> toKotlin(args0) })
}).orElse(null)
})
/**
* The Function Compute function description.
*/
public val description: Output?
get() = javaResource.description().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* A map that defines environment variables for the function.
*/
public val environmentVariables: Output