Skip to content

Commit 6b48a4c

Browse files
0x2b3bfa0restyled-commitscasperdclDavidGOrtegajorgeorpinel
authored
Integrate task resource (#237)
* Integrate task resource Integrate main.go Migrate testing repositories Format code * Restyled by prettier-markdown * Apply suggestions from code review Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Apply suggestions from code review Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Apply suggestions from code review Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Restyled by prettier-markdown * Simplify `switch` statement. * Replace `switch` by `if` Co-Authored-By: DavidGOrtega <g.ortega.david@gmail.com> * Fix bad character in variable * Restyled by gofmt * Add az/k8s aliases on the machine resource * Adjust timeouts * Add machine resource compatibility for instance+accelerator notation * Simplify verbose conditional Co-Authored-By: DavidGOrtega <g.ortega.david@gmail.com> * Simplify conditional * Finish k8s user–friendly storage support Works like the other providers except for two “insignificant” details: 1. Users need to specify an existing StorageClass and storage capacity to allocate with a slightly different syntax: `directory = "sc:1:/path"` would create a PersistentVolumeClaim from the StorageClass `sc` with `1` GB of capacity, and synchronize `/path` from the user's computer back and forth. The used StorageClass should support the ReadWriteOnce access mode for `parallelism = 1` or ReadWriteMany for `parallelism > 1` in order to be accessed by different pods at the same time. In the first case, rancher/local-path-provisioner can be used for testing purposes. 2. There is a “feature” (read: bug) pulling files that creates nested directories. Solving it is trivial, but we need to implement on our own some of the `kubectl cp` logic. * Rename cloud providers to use abbreviations * Reverse AWS image arch/owner fields * Clarify environment behavior * Replace results with shared * Simplify task resource description Worse yet * Restyled by prettier-markdown * Improve Kubernetes destroy handling * Improve environment variable behavior description Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Update generic instance documentation to “at least” * Remove `default` on switch * Remove else * Remove redundant d.SetId("") * Remove redundant nil return * Remove redundant nil return * Remove stray parenthesis Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Replace “declaring” with “defining” Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add colon and period to callout Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Remove irrelevant “just” Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Reword callout Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add more colons to callouts Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add even mor colons to callouts Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Link environment variables on index.md Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add colon and period to callout Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add link to the #cloud-regions section Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add link to the #machine-images section Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add link to the #machine-types section Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Remove top–level argument reference Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Restyled by prettier-markdown * Improve result description Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Add callout with link to Getting Started * Restyled by prettier-markdown * Add note on different ways of specifying script * Specify Terracorm CLI version constraint Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com> * Move machine–specific code to a separate package * Restyled by gofmt * Add glob support for environment variables * fixup! Link environment variables on index.md * Rename log path to prefix @dmpetrov cosmetic recommendation * Replace sizes by types Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Add ASCII tree of project layout Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> * Restyled by prettier-markdown * Introduce idempotent identifiers Now normalized names can be used to import resources. N(N(S)) == N(S) where N is the normalization function and S the name string. * Rename universal to common Less pretentious, despite being sorted between az and gcp * Rename NewTask to New * Iron out some bugs and add automated tests * Improve tests and add Kubernetes * Add optional StorageClass and requires for k8s * Simplify task schema code * Add sweep for smoke tests Named after the sweep code on official Terraform providers, but also because... well, it sweeps the soot left by smoke. See also Britten's The Little Sweep. * Fix typo 🙈 * Remove Push(unsafe) API wart * Improve start/stop support * Allow infinity timeout on machines * Remove extra log messages and fix `gcp` tests * Prepare tests for parallel matrix * Restyled by gofmt * Fix smoke.yml workflow after testing * Rename test to enabled * Relocate hardcoded environment variable on smoke.yml * minor wording update Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Casper da Costa-Luis <casper.dcl@physics.org> Co-authored-by: DavidGOrtega <g.ortega.david@gmail.com> Co-authored-by: Jorge Orpinel <jorgeorpinel@users.noreply.github.com>
1 parent 8121c66 commit 6b48a4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+7718
-225
lines changed

.github/workflows/smoke.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Smoke Test
2+
on:
3+
pull_request_target:
4+
paths: 'task/**'
5+
schedule:
6+
- cron: '0 9 * * 1'
7+
jobs:
8+
authorize:
9+
environment: ${{ github.event_name == 'schedule' && 'automatic' || 'manual' }}
10+
runs-on: ubuntu-latest
11+
steps:
12+
- run: echo ✓
13+
start:
14+
needs: authorize
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 30
17+
outputs:
18+
kubeconfig: ${{ steps.cluster.outputs.kubeconfig }}
19+
steps:
20+
- id: cluster
21+
run: |
22+
az login \
23+
--service-principal \
24+
--user="$AZURE_CLIENT_ID" \
25+
--password="$AZURE_CLIENT_SECRET" \
26+
--tenant="$AZURE_TENANT_ID"
27+
az account set \
28+
--subscription="$AZURE_SUBSCRIPTION_ID"
29+
az extension add \
30+
--name=aks-preview
31+
az provider register \
32+
--namespace=Microsoft.ContainerService
33+
az feature register \
34+
--namespace=Microsoft.ContainerService \
35+
--name=GPUDedicatedVHDPreview
36+
az group create \
37+
--name="tpiSmokeTestCluster$GITHUB_RUN_ID" \
38+
--location=eastus
39+
az aks create \
40+
--resource-group="tpiSmokeTestCluster$GITHUB_RUN_ID" \
41+
--name="tpiSmokeTestCluster$GITHUB_RUN_ID" \
42+
--node-vm-size=Standard_NC6 \
43+
--node-count=1 \
44+
--aks-custom-headers=UseGPUDedicatedVHD=true \
45+
--generate-ssh-keys
46+
az aks get-credentials \
47+
--resource-group="tpiSmokeTestCluster$GITHUB_RUN_ID" \
48+
--name="tpiSmokeTestCluster$GITHUB_RUN_ID" \
49+
--file - |
50+
perl -p -e 's/%/%25/g;' -e 's/\n/%0A/g;' -e 's/\r/%0D/g;' |
51+
xargs -0 printf "::set-output name=kubeconfig::%s\n"
52+
env:
53+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
54+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
55+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
56+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
57+
test:
58+
needs: start
59+
runs-on: ubuntu-latest
60+
timeout-minutes: 60
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
provider: [AWS, AZ, GCP, K8S]
65+
env:
66+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
69+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
70+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
71+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
72+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
73+
GOOGLE_APPLICATION_CREDENTIALS_DATA: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_DATA }}
74+
KUBECONFIG_DATA: ${{ needs.start.outputs.kubeconfig }}
75+
SMOKE_TEST_IDENTIFIER: smoke test ${{ github.run_id }}
76+
SMOKE_TEST_ENABLE_${{ matrix.provider }}: true
77+
steps:
78+
- uses: actions/checkout@v2
79+
- uses: actions/setup-go@v2
80+
with:
81+
go-version: ^1.17
82+
- run: go test ./task -v -timeout=30m -count=1
83+
- if: always()
84+
uses: actions/checkout@v2
85+
with:
86+
ref: master
87+
- if: always()
88+
run: go test ./task -v -timeout=30m -count=1
89+
env:
90+
SMOKE_TEST_SWEEP: true
91+
stop:
92+
if: always()
93+
needs: test
94+
runs-on: ubuntu-latest
95+
timeout-minutes: 30
96+
steps:
97+
- run: |
98+
az login \
99+
--service-principal \
100+
--user="$AZURE_CLIENT_ID" \
101+
--password="$AZURE_CLIENT_SECRET" \
102+
--tenant="$AZURE_TENANT_ID"
103+
az account set \
104+
--subscription="$AZURE_SUBSCRIPTION_ID"
105+
az group delete \
106+
--name="tpiSmokeTestCluster$GITHUB_RUN_ID" \
107+
--yes
108+
env:
109+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
110+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
111+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
112+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

.goreleaser.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
before:
2-
hooks:
3-
- go mod vendor
41
builds:
52
- env:
63
- CGO_ENABLED=0
@@ -24,11 +21,17 @@ builds:
2421
goarch: '386'
2522
binary: '{{ .ProjectName }}_v{{ .Version }}'
2623
archives:
27-
- format: zip
24+
- id: default
25+
format: zip
2826
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
27+
- id: agent
28+
format: binary
29+
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
2930
checksum:
3031
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
3132
algorithm: sha256
33+
ids:
34+
- default
3235
signs:
3336
- artifacts: checksum
3437
args:

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
HOSTNAME=github.com
22
NAMESPACE=iterative
33
NAME=iterative
4-
VERSION=0.0.0+development
4+
VERSION=0.0.${shell date +%s}+development
55
OS_ARCH=${shell go env GOOS}_${shell go env GOARCH}
66
BINARY=terraform-provider-${NAME}
77
INSTALL_PATH=~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
88

9-
default: install
9+
default: build
1010

1111
build:
1212
go build
@@ -15,7 +15,13 @@ install:
1515
GOBIN=${INSTALL_PATH} go install
1616

1717
test:
18-
go test ./... ${TESTARGS} -timeout=30s -parallel=4
18+
go test ./... ${TESTARGS} -timeout=30s -parallel=4 -short
19+
20+
smoke:
21+
go test ./task -v ${TESTARGS} -timeout=30m -count=1
22+
23+
sweep:
24+
SMOKE_TEST_SWEEP=true go test ./task -v ${TESTARGS} -timeout=30m -count=1
1925

2026
testacc:
2127
TF_ACC=1 go test ./... -v ${TESTARGS} -timeout 120m

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Terraform Provider Iterative](https://static.iterative.ai/img/cml/banner-terraform.png)
22

3-
# Terraform Iterative provider
3+
# Iterative Provider [![](https://img.shields.io/badge/-documentation-5c4ee5?logo=terraform)](https://registry.terraform.io/providers/iterative/iterative/latest/docs)
44

55
The Iterative Provider is a Terraform plugin that enables full lifecycle
66
management of cloud computing resources, including GPUs, from your favorite
@@ -20,6 +20,8 @@ The Provider is designed for benefits like:
2020

2121
## Usage
2222

23+
See [this guide](https://registry.terraform.io/providers/iterative/iterative/latest/docs/guides/getting-started) for more information.
24+
2325
### Runner
2426

2527
A self hosted runner based on a thin wrapper over the GitLab and GitHub

docs/guides/getting-started.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
page_title: Getting Started
3+
---
4+
5+
# Getting Started
6+
7+
Begin by [installing Terraform 1.0 or greater](https://learn.hashicorp.com/tutorials/terraform/install-cli#install-terraform) if needed.
8+
9+
## Defining a Task
10+
11+
In the project root directory:
12+
13+
1. Create a directory named `shared` to store input data and output artifacts.
14+
2. Create a file named `main.tf` with the following contents:
15+
16+
```hcl
17+
terraform {
18+
required_providers {
19+
iterative = {
20+
source = "iterative/iterative"
21+
}
22+
}
23+
}
24+
25+
provider "iterative" {}
26+
27+
resource "iterative_task" "example" {
28+
name = "example"
29+
cloud = "aws" # or any of: gcp, az, k8s
30+
31+
directory = "${path.root}/shared"
32+
33+
script = <<-END
34+
#!/bin/bash
35+
echo "Hello World!" > greeting.txt
36+
END
37+
}
38+
```
39+
40+
-> **Note**: The `script` argument can take anny string, including a [heredoc](https://www.terraform.io/docs/language/expressions/strings.html#heredoc-strings) or the contents of a file returned by the [`file`](https://www.terraform.io/docs/language/functions/file.html) function.
41+
42+
The project layout should look similar to this:
43+
44+
project/
45+
├─ shared/
46+
│ └─ ···
47+
└─ main.tf
48+
49+
## Initializing Terraform
50+
51+
```console
52+
$ terraform init
53+
```
54+
55+
This command will:
56+
57+
1. Download and install the Iterative Provider.
58+
2. Initialize Terraform in the current directory.
59+
60+
~> **Note:** None of the subsequent commands will work without first setting some [authentication environment variables](https://registry.terraform.io/providers/iterative/iterative/latest/docs#authentication).
61+
62+
## Launching Tasks
63+
64+
```console
65+
$ terraform apply
66+
···
67+
```
68+
69+
This command will:
70+
71+
1. Create all the required cloud resources.
72+
2. Upload the specified shared `directory` to the cloud.
73+
3. Launch the task `script`.
74+
75+
## Viewing Task Statuses
76+
77+
```console
78+
$ terraform refresh && terraform show
79+
resource "iterative_task" "example" {
80+
···
81+
}
82+
```
83+
84+
This command will:
85+
86+
1. Query the task status from the cloud.
87+
2. Display the task status.
88+
89+
## Deleting Tasks
90+
91+
```console
92+
terraform destroy
93+
```
94+
95+
This command will:
96+
97+
1. Download the specified shared `directory` from the cloud.
98+
2. Delete all the created cloud resources.
99+
100+
## Viewing Task Results
101+
102+
After running `terraform destroy`, the `shared/` directory should contain a file named `greeting.txt` with the text `Hello, World!`

docs/index.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Iterative Provider
2+
3+
Use the Iterative Provider to launch resource-intensive tasks in popular cloud
4+
providers with a single Terraform file.
5+
6+
## Example Usage
7+
8+
```hcl
9+
terraform {
10+
required_providers {
11+
iterative = {
12+
source = "iterative/iterative"
13+
}
14+
}
15+
}
16+
17+
provider "iterative" {}
18+
19+
resource "iterative_task" "task" {
20+
name = "example"
21+
cloud = "aws"
22+
23+
script = <<-END
24+
#!/bin/bash
25+
echo "hello!"
26+
END
27+
}
28+
```
29+
30+
-> **Note:** See the [Getting Started](https://registry.terraform.io/providers/iterative/iterative/latest/docs/guides/getting-started) for more information.
31+
32+
## Authentication
33+
34+
[Environment variables](https://registry.terraform.io/providers/iterative/iterative/latest/docs#authentication) are the only supported authentication method. They should
35+
be present when running any of the `terraform` commands.
36+
37+
### Example
38+
39+
```bash
40+
$ export GOOGLE_APPLICATION_CREDENTIALS_DATA="$(cat service_account.json)"
41+
$ terraform apply
42+
```
43+
44+
### Amazon Web Services
45+
46+
- `AWS_ACCESS_KEY_ID` - Access key identifier.
47+
- `AWS_SECRET_ACCESS_KEY` - Secret access key.
48+
- `AWS_SESSION_TOKEN` - (Optional) Session token.
49+
50+
### Google Cloud Platform
51+
52+
- `GOOGLE_APPLICATION_CREDENTIALS` - Path to a service account JSON key file.
53+
54+
-> **Note** you can also use `GOOGLE_APPLICATION_CREDENTIALS_DATA` with the
55+
**contents** of the service account JSON key file.
56+
57+
### Microsoft Azure
58+
59+
- `AZURE_CLIENT_ID` - Client identifier.
60+
- `AZURE_CLIENT_SECRET` - Client secret.
61+
- `AZURE_SUBSCRIPTION_ID` - Subscription identifier.
62+
- `AZURE_TENANT_ID` - Tenant identifier.
63+
64+
### Kubernetes
65+
66+
- `KUBECONFIG` - Path to a [`kubeconfig` file](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable).
67+
68+
-> **Note**: You can use `KUBECONFIG_DATA` instead, with the **contents** of the `kubeconfig` file.

0 commit comments

Comments
 (0)