1
1
# Terraform Provider for Stacklet
2
2
3
- This Terraform Provider allows you to interact with Stacklet's GraphQL API to manage your resources through Infrastructure as Code.
3
+ This Terraform Provider allows you to interact with Stacklet's GraphQL API to
4
+ manage your resources through Infrastructure as Code.
4
5
5
- ## Requirements
6
-
7
- - [ Terraform] ( https://www.terraform.io/downloads.html ) >= 1.11
8
- - [ Go] ( https://golang.org/doc/install ) >= 1.24.2
9
-
10
- ## Building The Provider
11
-
12
- 1 . Clone the repository:
13
- ``` bash
14
- git clone https://github.com/stacklet/terraform-provider-stacklet.git
15
- cd terraform-provider-stacklet
16
- ```
17
-
18
- 2 . Build the provider:
19
- ``` bash
20
- just build
21
- ```
22
6
23
7
## Using the provider
24
8
25
- ### Local Development
26
-
27
- When developing locally, you can use the provider by configuring Terraform to use your local build:
28
-
29
- 1 . Override the provider location for development, by creating a ` ~/.terraformrc ` with the following content:
30
-
31
- ``` terraform
32
- provider_installation {
33
- dev_overrides {
34
- "stacklet/stacklet" = "<absolute path to the repository directory>"
35
- }
36
-
37
- # For all other providers, install them directly from their origin provider
38
- # registries as normal. If you omit this, Terraform will _only_ use the
39
- # dev_overrides block, and so no other providers will be available.
40
- direct {}
41
- }
42
- ```
43
-
44
- 2 . Declare the provider in the terraform file
9
+ The provider is configured as follows:
45
10
46
11
``` terraform
47
12
terraform {
@@ -53,45 +18,30 @@ terraform {
53
18
}
54
19
55
20
provider "stacklet" {
56
- endpoint = "https://api.<myinstance >.stacklet.io/" # Or use STACKLET_ENDPOINT env var
57
- api_key = "your-api-key" # Or use STACKLET_API_KEY env var
21
+ endpoint = "https://api.<INSTANCE_NAME >.stacklet.io/"
22
+ api_key = "<API_KEY>"
58
23
}
59
24
```
60
25
61
- 3 . Run ` terraform plan ` or ` terraform apply ` with the local resources configuration.
62
-
63
-
64
- ** Note** : ` terraform init ` must not be run when working with a locally installed provider.
65
-
66
-
67
- #### Debugging the provider
68
-
69
- Debug messages and output are not visible when running the provider directly from terraform.
70
- To enable debug
26
+ ### Environment variables
71
27
72
- 1 . run ` ./terraform-provider-stacklet -debug `
73
-
74
- 2 . export the ` TF_REATTACH_PROVIDERS ` variable provided in the output in the shell where ` terraform ` is run
75
-
76
-
77
- ### Environment Variables
78
-
79
- The provider can be configured using environment variables:
28
+ As an alternative, endpoint and key can be defined as environment variables:
80
29
81
30
``` bash
82
- export STACKLET_ENDPOINT=" https://api.<myinstance >.stacklet.io/"
83
- export STACKLET_API_KEY=" your-api-key "
31
+ export STACKLET_ENDPOINT=" https://api.<INSTANCE_NAME >.stacklet.io/"
32
+ export STACKLET_API_KEY=" <API_KEY> "
84
33
```
85
34
86
- ### Login via stacklet-admin CLI
87
-
88
- The provider can look up authentication details from the [ ` stacklet-admin ` ] ( https://github.com/stacklet/stacklet-admin ) CLI.
35
+ ### Login via ` stacklet-admin ` CLI
89
36
90
- After configuring and logging in to the instance via the CLI ( ` stacklet-admin login ` ), the provider will be able to connect
91
- to it .
37
+ The provider can also look up authentication details from the
38
+ [ ` stacklet-admin ` ] ( https://github.com/stacklet/stacklet-admin ) CLI .
92
39
40
+ After configuring and logging in to the instance via the CLI (`stacklet-admin
41
+ login`), the provider will be able to connect to it without needing to specify
42
+ credentials in the configuration or via environment variables.
93
43
94
- ### Example Terraform
44
+ ### Example configuration
95
45
96
46
Below is a full example of a configuration to create a few resources in Stacklet.
97
47
@@ -105,8 +55,8 @@ terraform {
105
55
}
106
56
107
57
provider "stacklet" {
108
- endpoint = "https://api.<myinstance >.stacklet.io/"
109
- api_key = "$api_key_here "
58
+ endpoint = "https://api.<INSTANCE_NAME >.stacklet.io/"
59
+ api_key = "<API_KEY> "
110
60
}
111
61
112
62
data "stacklet_policy_collection" "example" {
@@ -167,3 +117,76 @@ data "stacklet_binding" "binding" {
167
117
name = "AWS Posture"
168
118
}
169
119
```
120
+
121
+
122
+ ## Local development
123
+
124
+ For local development, make sure you have the tools declared in the
125
+ [ ` .tool-versions ` ] ( ./.tool-versions ) file installed.
126
+
127
+ ### Building the provider
128
+
129
+ 1 . Clone the repository:
130
+ ``` bash
131
+ git clone https://github.com/stacklet/terraform-provider-stacklet.git
132
+ cd terraform-provider-stacklet
133
+ ```
134
+
135
+ 2 . Build the provider:
136
+ ``` bash
137
+ just build
138
+ ```
139
+
140
+ ### Running locally built provider
141
+
142
+ To run the locally built copy of the provider, terraform must be configured as
143
+ follows:
144
+
145
+ 1 . Override the provider location for development, by creating a
146
+ ` ~/.terraformrc ` with the following content:
147
+
148
+ ``` terraform
149
+ provider_installation {
150
+ dev_overrides {
151
+ "stacklet/stacklet" = "<absolute path to the repository directory>"
152
+ }
153
+
154
+ # For all other providers, install them directly from their origin provider
155
+ # registries as normal. If you omit this, Terraform will _only_ use the
156
+ # dev_overrides block, and so no other providers will be available.
157
+ direct {}
158
+ }
159
+ ```
160
+
161
+ 2 . Declare the provider in your terraform configuration as
162
+
163
+ ``` terraform
164
+ terraform {
165
+ required_providers {
166
+ stacklet = {
167
+ source = "stacklet/stacklet"
168
+ }
169
+ }
170
+ }
171
+
172
+ provider "stacklet" {
173
+ endpoint = "https://api.<INSTANCE_NAME>.stacklet.io/" # Or set STACKLET_ENDPOINT env var
174
+ api_key = "<API_KEY>" # Or set STACKLET_API_KEY env var
175
+ }
176
+ ```
177
+
178
+ 3 . Run ` terraform plan ` or ` terraform apply ` with the local resources configuration.
179
+
180
+
181
+ ** Note** : ` terraform init ` must not be run when working with a locally installed provider.
182
+
183
+ ### Debugging
184
+
185
+ Debug messages and output are not visible when running the provider directly
186
+ from terraform. To enable debug:
187
+
188
+ 1 . Run ` ./terraform-provider-stacklet -debug ` in one terminal.
189
+
190
+ 2 . In a separate terminal, export the value for the ` TF_REATTACH_PROVIDERS `
191
+ variable provided in the output of the previous command, and run
192
+ ` terraform ` .
0 commit comments