diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0e8df7d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## 1.0.0 (March 24, 2022) +- Project Initialization[GH-1](https://github.com/terraform-alicloud-modules/terraform-alicloud-serverless-workflow/pull/1) diff --git a/README.md b/README.md index 8522d58..5135d18 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,53 @@ # terraform-alicloud-serverless-workflow Terraform Module for creating Serverless Workflow resources on Alibaba Cloud. + +These types of resources are supported: + +* [alicloud_fnf_flow](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/fnf_flow) +* [alicloud_fnf_execution](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/fnf_execution) +* [alicloud_fnf_schedule](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/fnf_schedule) + +## Usage + +```hcl +module "example" { + source = "terraform-alicloud-modules/serverless-workflow/alicloud" + description = "your_description" + name = "your_name" + type = "DEFAULT" + + execution_name = "your_execution_name" + flow_name = "your_flow_name" + input = "your_input" + status = "your_status" + + cron_expression = "your_cron_expression" + schedule_name = "your_schedule_name" + payload = "your_payload" +} +``` + +## Examples + +* [complete example](https://github.com/terraform-alicloud-modules/serverless-workflow/tree/main/examples/complete) + +## Terraform versions + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [alicloud](#requirement\_alicloud) | >= 1.149.0 | + +Authors +------- +Created and maintained by Alibaba Cloud Terraform Team(terraform@alibabacloud.com) + +License +---- +Apache 2 Licensed. See LICENSE for full details. + +Reference +--------- +* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud) +* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/) +* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html) \ No newline at end of file diff --git a/examples/complete/main.tf b/examples/complete/main.tf new file mode 100644 index 0000000..270e0e4 --- /dev/null +++ b/examples/complete/main.tf @@ -0,0 +1,21 @@ +module "fnf" { + source = "../.." + # alicloud_fnf_flow + create_flow = true + flow_type = var.flow_type + flow_name = "flow_name" + flow_description = var.flow_description + definition = var.definition + + #alicloud_fnf_schedule + create_schedule = true + cron_expression = var.cron_expression + schedule_name = "module_schedule_name" + payload = var.payload + schedule_description = var.schedule_description + + # alicloud_fnf_execution + create_execution = true + execution_name = "module_execution_name" + input = jsonencode({ "wait" = 10 }) +} \ No newline at end of file diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf new file mode 100644 index 0000000..4ca7278 --- /dev/null +++ b/examples/complete/variables.tf @@ -0,0 +1,47 @@ +variable "flow_type" { + type = string + description = "The type of the flow. Valid values are FDL or DEFAULT." + default = "FDL" +} + +variable "flow_description" { + type = string + description = "The description of the flow." + default = "flow_description_test" +} + +variable "definition" { + type = string + description = "The definition of the flow. It must comply with the Flow Definition Language (FDL) syntax." + default = "version: v1beta1\ntype: flow\nsteps:\n - type: pass\n name: helloworld" +} + + + +variable "cron_expression" { + type = string + description = "The CRON expression of the time-based schedule to be created." + default = "30 9 * * * *" +} + + +variable "payload" { + type = string + description = "The trigger message of the time-based schedule to be created. It must be in JSON object format." + default = "{\"tf-testchange\": \"test success\"}" +} + + +variable "schedule_description" { + type = string + description = "The description of the time-based schedule to be created." + default = "module_schedule_description" +} + +variable "config_rule_ids" { + type = list(object({ + config_rule_id = string + })) + description = "" + default = [] +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..736126d --- /dev/null +++ b/main.tf @@ -0,0 +1,30 @@ +locals { + flow_name = var.flow_name != "" ? var.flow_name : concat(alicloud_fnf_flow.flow.*.name, [""])[0] +} + + +resource "alicloud_fnf_flow" "flow" { + count = var.create_flow ? 1 : 0 + definition = var.definition + description = var.flow_description + name = var.flow_name + type = var.flow_type +} + +resource "alicloud_fnf_execution" "execution" { + count = var.create_execution ? 1 : 0 + execution_name = var.execution_name + flow_name = local.flow_name + input = var.input + status = var.execution_status +} + +resource "alicloud_fnf_schedule" "schedule" { + count = var.create_schedule ? 1 : 0 + cron_expression = var.cron_expression + flow_name = local.flow_name + schedule_name = var.schedule_name + description = var.schedule_description + payload = var.payload + enable = var.schedule_enable +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..c3aca97 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,16 @@ +output "flow_id" { + description = "The Flow ID" + value = concat(alicloud_fnf_flow.flow.*.id, [""])[0] +} + +output "execution_id" { + description = "The Execution ID" + value = concat(alicloud_fnf_execution.execution.*.id, [""])[0] +} + +output "alicloud_fnf_schedule" { + description = "The Schedule ID" + value = concat(alicloud_fnf_schedule.schedule.*.id, [""])[0] +} + + diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..ba6a0d9 --- /dev/null +++ b/variables.tf @@ -0,0 +1,102 @@ +variable "create_flow" { + type = bool + description = "Whether to create the alicloud_fnf_flow" + default = false +} + +variable "create_execution" { + type = bool + description = "Whether to create the alicloud_fnf_execution" + default = false +} + +variable "create_schedule" { + type = bool + description = "Whether to create the alicloud_fnf_schedule" + default = false +} + +#alicloud_fnf_flow +variable "definition" { + type = string + description = "The definition of the flow. It must comply with the Flow Definition Language (FDL) syntax." + default = "" +} + +variable "flow_description" { + type = string + description = "The description of the flow." + default = "" +} + +variable "flow_name" { + type = string + description = "The name of the flow. The name must be unique in an Alibaba Cloud account." + default = "" +} + +variable "flow_type" { + type = string + description = "The type of the flow. Valid values are FDL or DEFAULT." + default = "DEFAULT" +} + +variable "role_arn" { + type = string + description = "The ARN of the specified RAM role that Serverless Workflow uses to assume the role when Serverless Workflow executes a flow." + default = "" +} + +#alicloud_fnf_execution + +variable "execution_name" { + type = string + description = "The name of the execution." + default = "" +} + +variable "input" { + type = string + description = "The Input information for this execution." + default = "" +} + +variable "execution_status" { + type = string + description = "TThe status of the resource. Valid values: `Stopped`" + default = null +} + + +#alicloud_fnf_schedule +variable "cron_expression" { + type = string + description = "The CRON expression of the time-based schedule to be created." + default = "" +} + +variable "schedule_name" { + type = string + description = "The name of the time-based schedule to be created." + default = "" +} + +variable "schedule_description" { + type = string + description = "The description of the time-based schedule to be created." + default = "" +} + +variable "schedule_enable" { + type = bool + description = "Specifies whether to enable the time-based schedule you want to create. Valid values: false, true." + default = null +} + +variable "payload" { + type = string + description = "The trigger message of the time-based schedule to be created. It must be in JSON object format." + default = "" +} + +