diff --git a/src/stack/rfsStack/function.ts b/src/stack/rfsStack/function.ts new file mode 100644 index 00000000..90d272fa --- /dev/null +++ b/src/stack/rfsStack/function.ts @@ -0,0 +1,41 @@ +import { ActionContext, FunctionDomain } from '../../types'; + +const fgsApplication = (context: ActionContext, service: string) => ` +resource "huaweicloud_fgs_application" "${service}_app" { + name = "${service}-app" + description = "${service} application" + package_type = "event" +} +`; + +const fgsFunction = (fn: FunctionDomain, context: ActionContext, service: string) => ` +resource "huaweicloud_fgs_function" "${fn.key}" { + function_name = "${fn.name}" + handler = "${fn.handler}" + runtime = "${fn.runtime}" + memory_size = ${fn.memory} + timeout = ${fn.timeout} + environment = ${JSON.stringify(fn.environment)} + code = { + package_type = "inline" + code = < | undefined, + context: ActionContext, + service: string, +) => { + if (!functions) { + return undefined; + } + const app = fgsApplication(context, service); + + return app + '\n' + functions.map((fn) => fgsFunction(fn, context, service)).join('\n'); +}; diff --git a/src/stack/rfsStack/index.ts b/src/stack/rfsStack/index.ts index 15cf28d8..3434829d 100644 --- a/src/stack/rfsStack/index.ts +++ b/src/stack/rfsStack/index.ts @@ -1,8 +1,16 @@ import { ActionContext, ServerlessIac } from '../../types'; const provider = (context: ActionContext) => ` +terraform { + required_providers { + huaweicloud = { + source = "huaweicloud/huaweicloud" + version = ">= 1.71.2" + } + } +} + provider "huaweicloud" { - version = ">= 1.36.0" region = "${context.region}" access_key = "${context.accessKeyId}" secret_key = "${context.accessKeySecret}"