Skip to content

Commit 3673a6b

Browse files
committed
update example
1 parent 332247c commit 3673a6b

File tree

2 files changed

+77
-25
lines changed

2 files changed

+77
-25
lines changed

examples/resources/envbuilder_cached_image/.terraform.lock.hcl

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,93 @@
1+
// The below example illustrates the behavior of the envbuilder_cached_image
2+
// resource.
3+
// 1) Run a local registry:
4+
//
5+
// ```shell
6+
// docker run -d -p 5000:5000 --name test-registry registry:2
7+
// ```
8+
//
9+
// 2) Running a `terraform plan` should result in the following outputs:
10+
//
11+
// ```
12+
// + builder_image = "ghcr.io/coder/envbuilder-preview:latest"
13+
// + exists = (known after apply)
14+
// + id = (known after apply)
15+
// + image = (known after apply)
16+
// ```
17+
//
18+
// 3) Running `terraform apply` should result in outputs similar to the below:
19+
//
20+
// ```
21+
// builder_image = "ghcr.io/coder/envbuilder-preview:latest"
22+
// exists = false
23+
// id = "00000000-0000-0000-0000-000000000000"
24+
// image = "ghcr.io/coder/envbuilder-preview:latest"
25+
// ```
26+
//
27+
// 4) Populate the cache by running Envbuilder and pushing the built image to
28+
// the local registry:
29+
//
30+
// ```shell
31+
// docker run -it --rm \
32+
// -e ENVBUILDER_CACHE_REPO=localhost:5000/test \
33+
// -e ENVBUILDER_GIT_URL=https://github.com/coder/envbuilder-starter-devcontainer \
34+
// -e ENVBUILDER_PUSH_IMAGE=true \
35+
// -e ENVBUILDER_INIT_SCRIPT=exit \
36+
// --net=host \
37+
// ghcr.io/coder/envbuilder-preview:latest
38+
// ```
39+
//
40+
// 5) Run `terraform plan` once more. Now, the cached image will be detected:
41+
//
42+
// ```
43+
// Note: Objects have changed outside of Terraform
44+
//
45+
// Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan:
46+
// envbuilder_cached_image.example has been deleted
47+
// - resource "envbuilder_cached_image" "example" {
48+
// - exists = false -> null
49+
// - id = "00000000-0000-0000-0000-000000000000" -> null
50+
// - image = "ghcr.io/coder/envbuilder-preview:latest" -> null
51+
// # (5 unchanged attributes hidden)
52+
// ```
53+
//
54+
// 6) Run `terraform apply` and the newly pushed image will be saved in the Terraform state:
55+
// ```shell
56+
// builder_image = "ghcr.io/coder/envbuilder-preview:latest"
57+
// exists = true
58+
// id = "sha256:xxx..."
59+
// image = "localhost:5000/test@sha256:xxx..."
60+
// ```
61+
162
terraform {
263
required_providers {
364
envbuilder = {
465
source = "coder/envbuilder"
566
}
6-
docker = {
7-
source = "kreuzwerker/docker"
8-
}
967
}
1068
}
1169

1270
resource "envbuilder_cached_image" "example" {
13-
builder_image = "ghcr.io/coder/envbuilder:latest"
71+
builder_image = "ghcr.io/coder/envbuilder-preview:latest"
1472
git_url = "https://github.com/coder/envbuilder-starter-devcontainer"
15-
cache_repo = "localhost:5000/local/test-cache"
73+
cache_repo = "localhost:5000/test"
1674
extra_env = {
1775
"ENVBUILDER_VERBOSE" : "true"
1876
}
1977
}
2078

21-
resource "docker_container" "container" {
22-
image = envbuilder_cached_image.example.image
23-
env = envbuilder_cached_image.example.env
24-
name = "myenv"
79+
output "builder_image" {
80+
value = envbuilder_cached_image.example.builder_image
81+
}
82+
83+
output "exists" {
84+
value = envbuilder_cached_image.example.exists
85+
}
86+
87+
output "id" {
88+
value = envbuilder_cached_image.example.id
89+
}
90+
91+
output "image" {
92+
value = envbuilder_cached_image.example.image
2593
}

0 commit comments

Comments
 (0)