# jf terraform Run Terraform commands with Artifactory provider integration and optional build-info collection. This topic covers the following tasks: * [Configure Terraform for Artifactory (`jf terraform-config`)](#configuration-jf-terraform-config) * [Publish Terraform modules (`jf terraform`)](#build-jf-terraform) ## When to Use Use `jf terraform` to publish Terraform providers and modules to Artifactory. This command packages and deploys Terraform artifacts — it does not wrap `terraform init` or `terraform plan`. ## Prerequisites * Terraform must be installed. * Run `jf terraform-config` in the project directory before the first operation. * Configure a server with `jf config add` or `jf c add`. * Authentication to Artifactory is required. *** ## Configuration: `jf terraform-config` Generate Terraform configuration for deployment to Artifactory. **Run this once per project before your first Terraform operation.** **To configure Terraform for Artifactory:** ### Synopsis ``` jf terraform-config [options] ``` **Aliases:** `tfc` ### Configuration Options | Flag | Default | Description | | -------------------- | ------- | ------------------------------------------------------------------------------------ | | `--global` | `false` | Set to true for global configuration (all projects). Specific projects can override. | | `--repo-deploy` | — | Repository for artifacts deployment | | `--server-id-deploy` | — | Artifactory server ID for deployment. Configure with `jf config add`. | ### Configuration Examples #### View Help ```bash jf terraform-config --help ``` #### Non-Interactive Configuration with Flags ```bash jf terraform-config --server-id-deploy= --repo-deploy= ``` Where: * \: The server ID configured using `jf config add` * \: The name of the Terraform repository in Artifactory For example: ```bash jf terraform-config --server-id-deploy=my-server --repo-deploy=terraform-local ``` ### Why Run Config First? You must run `jf terraform-config` **before** using `jf terraform` for deployment. The config creates `.jfrog/projects/terraform.yaml` specifying the Artifactory repository for Terraform provider/module uploads. Without it, `jf terraform` does not know where to deploy artifacts. > **Shortcut**: In CI/CD, pass all flags non-interactively so the config step is fully automated and reproducible. ### Configuration Notes * **Deployment only**: Terraform config supports artifact deployment but not resolution. Terraform providers are resolved via Terraform's own registry mechanism. * **Run once per project**: Re-run when changing the deployment repository. ### Expected Output ``` $ jf terraform-config --server-id-deploy=my-server --repo-deploy=terraform-local Terraform build configuration saved successfully. ``` ### How to Verify After running, confirm the configuration exists: ```bash cat .jfrog/projects/terraform.yaml ``` *** ## Build: `jf terraform` Run Terraform commands with Artifactory provider integration and optional build-info collection. **To publish Terraform modules to Artifactory:** ### Synopsis ``` jf terraform [options] ``` **Aliases:** `tf` ### Arguments | Argument | Required | Description | | ----------------------- | -------- | -------------------------------------------------------------------------- | | `` | Yes | Terraform subcommand and options. Only `publish` (alias `p`) is supported. | ### Build Options | Flag | Default | Description | | ---------------- | ------- | ---------------------------------------------------------------------------------- | | `--build-name` | — | Build name for build-info. Requires `--build-number`. | | `--build-number` | — | Build number for build-info. Requires `--build-name`. | | `--exclusions` | — | Semicolon-separated exclusions. Wildcards `*` and `?` are supported. | | `--module` | — | Optional module name for build-info. Requires `--build-name` and `--build-number`. | | `--namespace` | — | Terraform namespace (mandatory for provider config) | | `--project` | — | JFrog Artifactory project key | | `--provider` | — | Terraform provider (mandatory for provider config) | | `--tag` | — | Terraform package tag (mandatory for provider config) | ### Build Examples #### Publish a Terraform Module The command creates a package for the Terraform module in the current directory and publishes it to the configured Terraform repository: ```bash jf tf p --namespace= --provider= --tag= ``` Where: * `` is the Terraform namespace (e.g., `example`, `myorg`) * `` is the Terraform provider name (e.g., `aws`, `azure`, `gcp`) * `` is the version tag (e.g., `v0.0.1`) For example: ```bash jf tf p --namespace=example --provider=aws --tag=v0.0.1 ``` #### Publish with Exclusions The published package will not include module paths matching `test` or `ignore`: ```bash jf tf p --namespace=example --provider=aws --tag=v0.0.1 --exclusions="*test*;*ignore*" ``` #### Publish with Build-Info The published module will be recorded as an artifact of build `my-build` with build number `1`: ```bash jf tf p --namespace=example --provider=aws --tag=v0.0.1 --build-name=my-build --build-number=1 jf rt build-publish my-build 1 ``` *** ## Important Notes * **Mandatory flags**: `--namespace`, `--provider`, and `--tag` are required for provider configuration commands. * **Terraform providers**: This command is used to publish and manage Terraform providers and modules in Artifactory, not for general Terraform workflows. * **Build-info**: Use `--build-name` and `--build-number` to track provider/module deployments. ## CI/CD Example (GitHub Actions) ```yaml # .github/workflows/build.yml steps: - uses: actions/checkout@v4 - name: Setup JFrog CLI uses: jfrog/setup-jfrog-cli@v4 env: JF_URL: ${{ vars.JF_URL }} JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }} - name: Configure Terraform run: jf terraform-config --server-id-deploy=setup-jfrog-cli-server --repo-deploy=terraform-local - name: Publish Terraform module run: jf tf p --namespace=example --provider=aws --tag=v0.0.1 --build-name=my-terraform --build-number=${{ github.run_number }} - name: Publish build info run: jf rt build-publish my-terraform ${{ github.run_number }} ``` ## Troubleshooting | Symptom | Cause | Fix | | ---------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------- | | `no config file was found` | `jf terraform-config` was not run | Run `jf terraform-config` in the project directory | | 401 / 403 on publish | Invalid credentials or insufficient permissions | Re-run `jf config add` with a valid access token | | "namespace, provider, or tag is missing" | Required flags not provided | Pass `--namespace`, `--provider`, and `--tag` on every publish | | No `.tf` files found | Command run in wrong directory | Ensure you are in a directory containing Terraform module files | | Unwanted files included in package | Test or doc files not excluded | Use `--exclusions="*test*;*.md"` to filter them out | **Enable debug logging:** `export JFROG_CLI_LOG_LEVEL=DEBUG`
## Related Topics * [Build Tools Overview](/artifactory/docs/build-tool-commands) — Capabilities matrix and tool reference * [Native Mode](/artifactory/docs/native-mode) — Supported packages with Native Mode