On this page
Terraform Lock
| source | condition | target |
|---|---|---|
✗ | ✔ | ✔ |
Description
The terraform/lock resource maintains a .terraform.lock.hcl dependency lock file: for a given provider it updates the version, the version constraint, and the package checksums - without running terraform init. The checksums are fetched from the registry for the platforms you list.
- condition
Tests that the lock file already records that version and its hashes for the provider.
- target
Rewrites the provider’s
version,constraintsandhashesentries.- source
Not supported - a source fails with
Source not supported for the plugin terraform/lock. Pair this resource withterraform/registry, which supplies the version.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| file | string | “file” defines the terraform lock file path to interact with. compatible: * condition * target remark: * “file” and “files” are mutually exclusive * protocols “https://”, “http://”, and “file://” are supported in path for condition | |
| files | array | “files” defines the list of terraform lock files path to interact with. compatible: * condition * target remark: * file and files are mutually exclusive * when using as a condition only one file is supported * protocols “https://”, “http://”, and “file://” are supported in file path for condition | |
| platforms | array | “platforms” is the target platforms to request package checksums for. compatible: * condition * target | |
| provider | string | “provider” is the terraform provider you wish to update, supports with or without registry url. compatible: * condition * target | |
| skipconstraints | boolean | “skipconstraints” will control whether the constraint in lock file is updated compatible: * condition * target NOTE: That turning this off can break the lockfile if version value source does not follow the constraints | |
| value | string | “value” is the value associated with a terraform provider. compatible: * condition * target default: When used from a condition or a target, the default value is set to linked source output. |
file or files, provider and platforms are all mandatory - missing any of them aborts the run with wrong spec content, preceded by terraform/lock file undefined, terraform/lock provider undefined or terraform/lock platforms undefined. file and files are mutually exclusive, and a condition accepts only one file.
providerAccepts the short form or the fully qualified one (
hashicorp/kubernetesandregistry.terraform.io/hashicorp/kubernetesboth work).platformsThe platforms to request checksums for, such as
linux_amd64ordarwin_arm64. Only the platforms listed here end up in the lock file, exactly as withterraform providers lock -platform=…. Omitting the platform your CI runs on will maketerraform initfail there.
Warning |
|
Remote files
For a condition, file accepts https://, http:// and file://. A target must write locally and refuses a URL.
Example
The example uses an additional resource plugin: terraform/registry.
# updatecli.yaml
name: Terraform Lock
sources:
kubernetes:
name: Get version from registry
kind: terraform/registry
spec:
type: provider
namespace: hashicorp
name: kubernetes
conditions:
using-value:
name: Condition using value
kind: terraform/lock
disablesourceinput: true
spec:
file: .terraform.lock.hcl
provider: hashicorp/kubernetes
platforms:
- linux_amd64
value: 2.22.0
https:
name: Condition using HTTP
kind: terraform/lock
disablesourceinput: true
spec:
file: https://raw.githubusercontent.com/updatecli-test/jenkins-infra-aws/main/.terraform.lock.hcl
provider: hashicorp/kubernetes
platforms:
- linux_amd64
value: 2.22.0
targets:
update-file-from-source:
name: Update files content from value
kind: terraform/lock
sourceid: kubernetes
spec:
file: .terraform.lock.hcl
provider: hashicorp/kubernetes
platforms:
- linux_amd64
Links
The
terraform/providerresource - for therequired_providersblock