# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/apply-terraform-config.cue
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  annotations:
    custom.definition.oam.dev/category: Terraform
    definition.oam.dev/alias: ""
    definition.oam.dev/description: Apply terraform configuration in the step
  name: apply-terraform-config
  namespace: {{ include "systemDefinitionNamespace" . }}
spec:
  schematic:
    cue:
      template: |
        import (
        	"vela/op"
        )

        apply: op.#Apply & {
        	value: {
        		apiVersion: "terraform.core.oam.dev/v1beta2"
        		kind:       "Configuration"
        		metadata: {
        			name:      "\(context.name)-\(context.stepName)"
        			namespace: context.namespace
        		}
        		spec: {
        			deleteResource: parameter.deleteResource
        			variable:       parameter.variable
        			forceDelete:    parameter.forceDelete
        			if parameter.source.path != _|_ {
        				path: parameter.source.path
        			}
        			if parameter.source.remote != _|_ {
        				remote: parameter.source.remote
        			}
        			if parameter.source.hcl != _|_ {
        				hcl: parameter.source.hcl
        			}
        			if parameter.providerRef != _|_ {
        				providerRef: parameter.providerRef
        			}
        			if parameter.jobEnv != _|_ {
        				jobEnv: parameter.jobEnv
        			}
        			if parameter.writeConnectionSecretToRef != _|_ {
        				writeConnectionSecretToRef: parameter.writeConnectionSecretToRef
        			}
        			if parameter.region != _|_ {
        				region: parameter.region
        			}
        		}
        	}
        }
        check: op.#ConditionalWait & {
        	continue: apply.value.status != _|_ && apply.value.status.apply != _|_ && apply.value.status.apply.state == "Available"
        }
        parameter: {
        	// +usage=specify the source of the terraform configuration
        	source: close({
        		// +usage=directly specify the hcl of the terraform configuration
        		hcl: string
        	}) | close({
        		// +usage=specify the remote url of the terraform configuration
        		remote: *"https://github.com/kubevela-contrib/terraform-modules.git" | string
        		// +usage=specify the path of the terraform configuration
        		path?: string
        	})
        	// +usage=whether to delete resource
        	deleteResource: *true | bool
        	// +usage=the variable in the configuration
        	variable: {...}
        	// +usage=this specifies the namespace and name of a secret to which any connection details for this managed resource should be written.
        	writeConnectionSecretToRef?: {
        		name:      string
        		namespace: *context.namespace | string
        	}
        	// +usage=providerRef specifies the reference to Provider
        	providerRef?: {
        		name:      string
        		namespace: *context.namespace | string
        	}
        	// +usage=region is cloud provider's region. It will override the region in the region field of providerRef
        	region?: string
        	// +usage=the envs for job
        	jobEnv?: {...}
        	// +usage=forceDelete will force delete Configuration no matter which state it is or whether it has provisioned some resources
        	forceDelete: *false | bool
        }

