Skip to content

Commit 02eb293

Browse files
committed
add reference topics
1 parent 6aa9717 commit 02eb293

File tree

5 files changed

+463
-3
lines changed

5 files changed

+463
-3
lines changed

content/terraform/v1.14.x (alpha)/data/cli-nav-data.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
{ "title": "Overview", "path": "import" },
6060
{ "title": "Import existing resources", "path": "import/usage" },
6161
{
62-
"title": "Reference",
62+
"title": "import command reference",
6363
"href": "/cli/commands/import"
64-
}
64+
},
65+
{ "title": "query command reference", "href": "/cli/commands/query" }
6566
]
6667
},
6768
{
@@ -370,6 +371,7 @@
370371
{ "title": "providers schema", "path": "commands/providers/schema" }
371372
]
372373
},
374+
{ "title": "query", "path": "commands/query" },
373375
{ "title": "refresh", "path": "commands/refresh" },
374376
{ "title": "show", "path": "commands/show" },
375377
{

content/terraform/v1.14.x (alpha)/data/language-nav-data.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
{ "title": "Overview", "path": "files" },
3131
{ "title": "Override files", "path": "files/override" },
3232
{ "title": "Dependency lock file", "path": "files/dependency-lock" },
33-
{ "title": "Test files", "path": "files/tests" }
33+
{ "title": "Test files", "path": "files/tests" },
34+
{ "title": "Query files", "path": "files/tfquery" }
3435
]
3536
},
3637
{
@@ -326,6 +327,27 @@
326327
}
327328
]
328329
},
330+
{
331+
"title": "tfquery blocks",
332+
"routes": [
333+
{
334+
"title": "list",
335+
"path": "block/tfquery/list"
336+
},
337+
{
338+
"title": "locals",
339+
"href": "/language/block/locals"
340+
},
341+
{
342+
"title": "provider",
343+
"href": "/language/block/provider"
344+
},
345+
{
346+
"title": "variable",
347+
"href": "/language/block/variable"
348+
}
349+
]
350+
},
329351
{
330352
"title": "Meta-arguments",
331353
"path": "meta-arguments"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
page_title: locals block reference for `.tfquery.hcl` files
3+
description: |-
4+
Add the `locals` block to your `.tfquery.hcl` files define values to reuse within the local Terraform module.
5+
---
6+
7+
# `terraform query` command
8+
9+
The `terraform query` command queries existing infrastructure for unmanaged resources according to the `tfquery.hcl` file so that you can import them into your Terraform workspace.
10+
11+
## Usage
12+
13+
```shell-session
14+
$ terraform query [flags] [options]
15+
```
16+
17+
## Description
18+
19+
When you run the `terraform query` command, Terraform searches the current configuration directory for `tfquery.hcl` files so that it can query remote infrastructure for resources that match the defined `list` blocks. Terraform prints the results to the terminal. You also add the `-generate-config-out` flag to generate configuration that you can use to import the resources. Refer to [Import resources in bulk](/terraform/language/import/bulk) for more information.
20+
21+
## Flags
22+
23+
- `-var '<INPUT-VARIABLE>=<VALUE>'`: Specifies a key-value pair that sets an input variable defined in the `tfquery.hcl` configuration. You can use this flag more than once to set additional input variables.
24+
- Data type: String.
25+
- Example: [Set input variables](#set-input-variabls)
26+
27+
- `-var-file=<FILENAME>`: Specifies a file containing input variable values, in addition to the default `terraform.tfvars` and `*.auto.tfvars` files.
28+
- Data type: Filename
29+
- Example: [Set input variables](#set-input-variabls)
30+
31+
## Options
32+
33+
- `-generate-config-out=<PATH/TO/OUTPUT>`: Instructs Terraform to generate `import` and `resource` blocks for results so that you can import them. Terraform writes the configuration to a new file. The file must not already exist. When used with the `-json` option, Terraform generates the configuration as part of the JSON output instead of writing it to a file.
34+
- Data type: Path
35+
- Example: [Generate import configuration](#generate-import-configuration)
36+
37+
- `-json`: Instructs Terraform to print results to the console in JSON format.
38+
- Data type: Boolean
39+
- Example: [Generate import configuration](#generate-import-configuration)
40+
41+
- `-no-color`: Terraform prints monochrome results.
42+
- Data type: Boolean
43+
## Examples
44+
45+
The following examples show how to use the command for common use cases.
46+
47+
### Set input variables
48+
49+
The following command passes sets the value of the `env` input variable to `prod`:
50+
51+
```shell-session
52+
$ terraform query -var 'env=prod'
53+
```
54+
55+
Corresponding `tfquery.hcl` configuration:
56+
57+
```hcl
58+
list "aws_instance" "instances" {
59+
provider = aws
60+
}
61+
62+
variable "env" {
63+
type = string
64+
default = "test"
65+
}
66+
```
67+
68+
The following command loads variable values defined in `my-vars.tfvars`:
69+
70+
```shell-session
71+
$ terraform query -var-file=my-vars.tfvars
72+
```
73+
74+
### Generate inport configuration
75+
76+
The following command generates `import` and `resource` blocks for the query results to a file in the `/to-import` directory:
77+
78+
```shell-session
79+
$ terraform query -generate-config=to-import
80+
```
81+
82+
The following command prints `import` and `resource` blocks for the query results as json:
83+
84+
```shell-session
85+
$ terraform query -generate-config=to-import -json
86+
```

0 commit comments

Comments
 (0)