The portainer_kubernetes_service_account resource allows you to deploy one-off Kubernetes Service account workloads into a specified namespace on a Kubernetes environment (endpoint) managed via Portainer.
resource "portainer_kubernetes_service_account" "example" {
endpoint_id = 4
namespace = "default"
manifest = file("${path.module}/serviceaccount.yaml")
}The Service account is created via the Portainer Kubernetes API.
Any change results in a delete + create.
To update the Service account (e.g. name, image), simply modify the manifest and re-apply:
terraform applyTo remove the service account:
terraform destroy| Name | Type | Required | Description |
|---|---|---|---|
| endpoint_id | int | β yes | ID of the Portainer environment (Kubernetes cluster). |
| namespace | string | β yes | Kubernetes namespace where the Service account should be created. |
| manifest | string | β yes | Kubernetes Service account manifest (JSON or YAML as a string). |
| Name | Description |
|---|---|
id |
ID in the format endpoint_id:namespace:serviceaccount:name |
Kubernetes ServiceAccount resources can be imported using the composite ID endpointID:namespace:name:
terraform import portainer_kubernetes_serviceaccounts.example 1:default:my-serviceaccountAfter import, set the manifest field in config to match the live object β Read only confirms the resource exists and restores identity fields, it does not reconstruct the manifest. If manifest is left blank after import, the next terraform apply will treat it as a change and may recreate the resource.