Skip to content

Commit db40579

Browse files
casperdcl0x2b3bfa0
andauthored
docs: misc updates (#450)
Co-authored-by: Helio Machado <0x2b3bfa0+git@googlemail.com>
1 parent 6ce4154 commit db40579

File tree

6 files changed

+79
-26
lines changed

6 files changed

+79
-26
lines changed

.gitignore

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
.DS_Store
2-
examples/.terraform
3-
examples
41
bin
52

6-
# Local .terraform directories
7-
**/.terraform/*
8-
9-
# .tfstate files
10-
*.tfstate
11-
*.tfstate.*
12-
13-
# Crash log files
14-
crash.log
3+
# Local terraform testing
4+
/main.tf
5+
/main.json
6+
/.terraform*
7+
/*.tfstate*
8+
/crash.log
159

1610
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
1711
# .tfvars files are managed as part of configuration and so should be included in

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ terraform init
7676
### Run Task
7777

7878
```
79-
terraform apply
79+
TF_LOG_PROVIDER=INFO terraform apply
8080
```
8181

8282
This launches a `machine` in the `cloud`, uploads `workdir`, and runs the `script`. Upon completion (or error), the `machine` is terminated.
@@ -88,21 +88,21 @@ With spot/preemptible instances (`spot >= 0`), auto-recovery logic and persisten
8888
Results and logs are periodically synced to persistent cloud storage. To query this status and view logs:
8989

9090
```
91-
terraform refresh
92-
terraform show
91+
TF_LOG_PROVIDER=INFO terraform refresh
92+
TF_LOG_PROVIDER=INFO terraform show
9393
```
9494

9595
### Stop Tasks
9696

9797
```
98-
terraform destroy
98+
TF_LOG_PROVIDER=INFO terraform destroy
9999
```
100100

101101
This terminates the `machine` (if still running), downloads `output`, and removes the persistent `disk_size` storage.
102102

103103
## Help
104104

105-
The [getting started guide](https://registry.terraform.io/providers/iterative/iterative/latest/docs/guides/getting-started) has some more information.
105+
The [getting started guide](https://registry.terraform.io/providers/iterative/iterative/latest/docs/guides/getting-started) has some more information. In case of errors, extra debugging information is available using `TF_LOG_PROVIDER=DEBUG` instead of `INFO`.
106106

107107
Feature requests and bugs can be [reported via GitHub issues](https://github.com/iterative/terraform-provider-iterative/issues), while general questions and feedback are very welcome on our active [Discord server](https://discord.gg/bzA6uY7).
108108

docs/guides/authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Environment variables are the only supported authentication method, and should b
88

99
```bash
1010
export GOOGLE_APPLICATION_CREDENTIALS_DATA="$(cat service_account.json)"
11-
terraform apply
11+
TF_LOG_PROVIDER=INFO terraform apply
1212
```
1313

1414
## Amazon Web Services

docs/guides/getting-started.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ page_title: Getting Started
77
## Requirements
88

99
- [Install Terraform 1.0+](https://learn.hashicorp.com/tutorials/terraform/install-cli#install-terraform), e.g.:
10+
1011
- Brew (Homebrew/Mac OS): `brew tap hashicorp/tap && brew install hashicorp/tap/terraform`
1112
- Choco (Chocolatey/Windows): `choco install terraform`
1213
- Conda (Anaconda): `conda install -c conda-forge terraform`
1314
- Debian (Ubuntu/Linux):
14-
```
15+
16+
```console
1517
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
1618
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
1719
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
1820
sudo apt-get update && sudo apt-get install terraform
1921
```
22+
2023
- Create an account with any supported cloud vendor and expose its [authentication credentials via environment variables][authentication]
2124

2225
[authentication]: https://registry.terraform.io/providers/iterative/iterative/latest/docs/guides/authentication
@@ -74,7 +77,7 @@ This command will check `main.tf` and download the required TPI plugin.
7477
## Run Task
7578

7679
```console
77-
$ terraform apply
80+
$ TF_LOG_PROVIDER=INFO terraform apply
7881
```
7982

8083
This command will:
@@ -92,7 +95,8 @@ With spot/preemptible instances (`spot >= 0`), auto-recovery logic and persisten
9295
## Query Status
9396

9497
```console
95-
$ terraform refresh && terraform show
98+
$ TF_LOG_PROVIDER=INFO terraform refresh
99+
$ TF_LOG_PROVIDER=INFO terraform show
96100
```
97101

98102
These commands will:
@@ -103,7 +107,7 @@ These commands will:
103107
## Stop Task
104108

105109
```console
106-
$ terraform destroy
110+
$ TF_LOG_PROVIDER=INFO terraform destroy
107111
```
108112

109113
This command will:
@@ -114,3 +118,26 @@ This command will:
114118
In this example, after running `terraform destroy`, the `results` directory should contain a file named `greeting.txt` with the text `Hello, World!`
115119

116120
-> **Note:** A large `output` directory may take a long time to download.
121+
122+
## Debugging
123+
124+
Use `TF_LOG_PROVIDER=DEBUG` in lieu of `INFO` to increase verbosity for debugging. See the [logging docs](https://www.terraform.io/plugin/log/managing) for a full list of options.
125+
126+
In case of errors within the `script` itself, both `stdout` and `stderr` are available from the [status](#query-status).
127+
128+
Advanced users may also want to SSH to debug failed scripts. This means preventing TPI from terminating the instance on `script` errors. For example:
129+
130+
```hcl
131+
timeout = 60*60*24 # 24h
132+
environment = { GITHUB_ACTOR = "" } # optional: GitHub username
133+
script = <<-END
134+
#!/bin/bash
135+
trap 'echo script error: waiting 24h for debugging over SSH. Run \"terraform destroy\" to stop waiting; sleep 24h' ERR
136+
# optional: allow GitHub user's ssh keys.
137+
# alternatively, use `ssh_private_key` and `addresses` from
138+
# https://registry.terraform.io/providers/iterative/iterative/latest/docs/resources/task#attribute-reference
139+
curl "https://github.com/$GITHUB_ACTOR.keys" >> "$HOME/.ssh/authorized_keys"
140+
141+
# ... rest of script ...
142+
END
143+
```

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terraform Provider Iterative (TPI)
22

3-
![TPI](https://static.iterative.ai/img/cml/banner-terraform.png)
3+
![TPI](https://static.iterative.ai/img/cml/banner-tpi.svg)
44

55
[![tests](https://img.shields.io/github/workflow/status/iterative/terraform-provider-iterative/Test?label=tests&logo=GitHub)](https://github.com/iterative/terraform-provider-iterative/actions/workflows/test.yml)
66
[![Apache-2.0](https://img.shields.io/badge/licence-Apache%202.0-blue)](https://github.com/iterative/terraform-provider-iterative/blob/master/LICENSE)

docs/resources/task.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "iterative_task" "example" {
1818
disk_size = 30 # GB
1919
spot = 0 # auto-price. Or -1 to disable, or >0 to set a hourly USD limit
2020
parallelism = 1
21-
timeout = 3600 # max 1h idle
21+
timeout = 60*60 # max 1h before forced termination
2222
2323
environment = { GREETING = "Hello, world!" }
2424
storage {
@@ -51,8 +51,8 @@ resource "iterative_task" "example" {
5151
- `storage.workdir` - (Optional) Local working directory to upload and use as the `script` working directory.
5252
- `storage.output` - (Optional) Results directory (**relative to `workdir`**) to download (default: no download).
5353
- `environment` - (Optional) Map of environment variable names and values for the task script. Empty string values are replaced with local environment values. Empty values may also be combined with a [glob](<https://en.wikipedia.org/wiki/Glob_(programming)>) name to import all matching variables.
54-
- `timeout` - (Optional) Maximum number of seconds to run before termination.
55-
- `name` - (Optional) Discouraged and may be removed in future. Deterministic task name (e.g. `name="Hello, World!"` always produces `id="tpi-hello-world-5kz6ldls-57wo7rsp"`).
54+
- `timeout` - (Optional) Maximum number of seconds to run before instances are force-terminated. The countdown is reset each time TPI auto-respawns a spot instance.
55+
- `name` - (Optional) _Discouraged and may be removed in future - change the resource name instead, i.e. `resource "iterative_task" "some_other_example_name"`._ Deterministic task name (e.g. `name="Hello, World!"` always produces `id="tpi-hello-world-5kz6ldls-57wo7rsp"`).
5656

5757
-> **Note:** `output` is relative to `workdir`, so `storage { workdir = "foo", output = "bar" }` means "upload `./foo/`, change working directory to the uploaded folder, run `script`, and download `bar` (i.e. `./foo/bar`)".
5858

@@ -70,6 +70,38 @@ In addition to all arguments above, the following attributes are exported:
7070

7171
~> **Warning:** `events` have different formats across cloud providers and cannot be relied on for programmatic consumption/automation.
7272

73+
After `terraform apply`, these attributes may be obtained using `terraform console`. For example:
74+
75+
```console
76+
$ echo 'try(join("\n", iterative_task.example.logs), "")' | terraform console
77+
```
78+
79+
For convenience, this can placed in an `output` block in `main.tf`:
80+
81+
```hcl
82+
resource "iterative_task" "example" {
83+
...
84+
}
85+
output "logs" {
86+
value = try(join("\n", iterative_task.example.logs), "")
87+
}
88+
```
89+
90+
The above would allow:
91+
92+
```console
93+
$ terraform output --raw logs
94+
```
95+
96+
Finally, JSON output can be parsed using `terraform output --json` and `jq` like this:
97+
98+
```console
99+
$ terraform show --json | jq --raw-output '
100+
.values.root_module.resources[] |
101+
select(.address == "iterative_task.example") |
102+
.values.logs[]'
103+
```
104+
73105
## Machine Type
74106

75107
### Generic

0 commit comments

Comments
 (0)