IBM Cloud Functions: How to create secured web action using Terraform

184 Views Asked by At

I am able to create a new IBM Cloud Functions action using the Terraform provider.

resource "ibm_function_action" "sendEmail" {
  name      = "${ibm_function_package.cloudmailer.name}/sendEmail"
  namespace = ibm_function_namespace.namespace.name

  exec {
    kind = "nodejs:12"
    code = file("smtp_email.js")
  }
  publish = true
  user_defined_parameters = var.server_config
}

How can I turn the above action into a web action? How can I specify the configuration for its password protection?

1

There are 1 best solutions below

0
On BEST ANSWER

This can be achieved using the annotations argument. It holds key / value pairs of these documented action annotations.

resource "ibm_function_action" "sendEmail" {
  name      = "${ibm_function_package.cloudmailer.name}/sendEmail"
  namespace = ibm_function_namespace.namespace.name

  exec {
    kind = "nodejs:12"
    code = file("smtp_email.js")
  }
  publish = true
  user_defined_parameters = var.server_config
  user_defined_annotations =  <<EOF
    [
      {
        "key": "web-export",
        "value": true
      },
      {
        "key": "require-whisk-auth",
        "value": "your-web-secret"
      }
    ]
EOF

}

The above web-export turns the action into a web action, require-whisk-auth enables authentication for security and its value sets the password. I have turned it into a working sample.