更新时间:2024-08-15 GMT+08:00

编写函数资源脚本

华为云在Terraform已经注册了provider,函数作为资源挂在huawei cloud的provider下。参考文档https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/fgs_function

提供如下样例:

在服务器创建一个main.tf文件,将如下脚本拷贝到main.tf上并保存。

terraform {
  required_providers {
    huaweicloud = {
      source  = "huaweicloud/huaweicloud"
      version = ">= 1.40.0"
    }
  }
}
 
provider "huaweicloud" {
  region     = "cn-east-3" #实际的区域
  access_key = "*******"  #前面获取的key
  secret_key = "*******" #前面获取的key
}
 
resource "huaweicloud_fgs_function" "fgs_function" {
  name        = "test_func_rf"
  app         = "default"
  agency      = "function-admin"
  description = "function test"
  handler     = "index.handler"
  memory_size = 128
  timeout     = 3
  runtime     = "Python3.6"
  code_type   = "inline"
  func_code   = "aW1wb3J0IGpzb24KZGVmIGhhbmRsZXIgKGV2ZW50LCBjb250ZXh0KToKICAgIG91dHB1dCA9ICdIZWxsbyBtZXNzYWdlOiAnICsganNvbi5kdW1wcyhldmVudCkKICAgIHJldHVybiBvdXRwdXQ="
}

access_key secret_key 需要替换为获取访问密钥生成的秘钥。