Resource Template
Resource templates are fundamental components of environment templates, containing Infrastructure as Code (IaC), such as HCL, to define resources. They encompass variables, lifecycle hooks (e.g., pre/post actions on completion or deployment), policies, and configurations that determine whether the resource is dedicated to a specific workload or shared across multiple workloads.
Key features of resource templates include:
- Representing a class of resources, which can be infrastructure, applications, or services
- Encapsulating IaC configurations and supporting config contexts
- Utilizing outputs from other resources as input variables through expressions
- Being version-controlled for better management
A resource template cannot be published independently; it must be associated with an environment template to be published. Additionally, resource templates can be shared across projects, allowing users with access to those projects to leverage them for building environment templates.
Setting | Description |
---|---|
apiVersion | Rafay’s API version eaas.envmgmt.io/v1 . |
Kind | ResourceTemplate . |
Metadata | - description: Description or purpose of the resource template. - name: Name of the resource template. - project: Project name where the resource template resides. |
spec -> agents | Set to the name of the agent designated to execute the code of the resource template. |
spec -> contexts | Refers to the Config Context defined outside the resource template. Note: Config Context is typically used to pass settings (variables, environment variables, or files) to multiple environment/resource templates. |
spec -> hooks | Refers to the lifecycle hooks for the resource template: - on_completion: Configure an on completion lifecycle hook. - on_failure: Configure an on failure lifecycle hook. - on_init: Configure an on initialize lifecycle hook. - on_success: Configure an on success lifecycle hook. - provider: Configure provider hooks. |
spec -> hooks -> on_completion | - name: Name of the hook. - type: Type of hook ( approval , container , http , driver ). - agents: Specify the resource ref agents. - on_failure: Action to take on failure. - options: Hook options (Max: 1). - timeout_seconds: Timeout in seconds. - driver: Driver responsible for execution. - execute_once: If the hook should execute only once. |
spec -> provider | Specify the resource template provider. Accepted values: terraform , hcpterraform , opentofu , custom . |
spec -> providerOptions | Provider-specific options: - driver: Driver name for execution (defaults to Rafay OpenTofu provider image if not provided). - backend_configs: List of key-value pairs or file paths. - lock: Skip holding a state lock during operation. - lock_timeout_seconds: Duration to retry state lock. - var_files: Load variable values from files. - backend_type: Supported types: custom , system , terraform_cloud . - volumes: Volumes for the Terraform driver. |
spec -> repositoryOptions | Options for the repository to pull code from: - branch: Specify the branch. - directory_path: Specify the directory path. - name: Specify the repository name. |
spec -> variables | A list of input variables with fields: - name: Variable name. - valueType: hcl , json , expression , or text . - overrideType: allowed , notallowed , or restricted . - required: true or false . - value: Single value. - sensitive: true (encrypted) or false . |
spec -> version | Version of the resource template. |
Sample Resource Template spec¶
apiVersion: eaas.envmgmt.io/v1
kind: ResourceTemplate
metadata:
name: rauto-workload-resource-template-65837
project: defaultproject
spec:
contexts:
- name: rauto-rafay-creds-config-context-65837
- name: rauto-workload-config-config-context-65837
hooks: {}
provider: terraform
providerOptions:
driver:
name: madhucustom
terraform:
backendConfigs:
- tmp/inputs/workload.tfvars
backendType: custom
lock: true
refresh: true
repositoryOptions:
branch: resourcetemplate-testing
directoryPath: workloads/eaas/terraform/rafay-workload
name: rauto-repo-65837
secret:
name: file://artifacts/rauto-workload-resource-template-65837/sealed-secret.yaml
variables:
- name: cluster_name
value: $(resource."rauto-eks-resource-template-65837".output.eks_cluster_name.value)$
valueType: expression
- name: postgres_host
value: $(resource."rauto-rds-resource-template-65837".output.rds_hostname.value)$
valueType: expression
- name: postgres_username
value: $(resource."rauto-rds-resource-template-65837".output.rds_username.value)$
valueType: expression
- name: postgres_password
options:
sensitive: true
value: sealed://variables.3
valueType: expression
- name: redis_config_endpoint
value: $(resource."rauto-ec-resource-template-65837".output.configuration_endpoint_address.value)$
valueType: expression
version: custom-noagent