Skip to content

Commit 4289012

Browse files
authored
feat(docs): improve contribution docs (#1008)
relates to STACKITTPR-317
1 parent 8aa4d29 commit 4289012

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

CONTRIBUTION.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ https://github.com/stackitcloud/terraform-provider-stackit/blob/1b9225598a007cda
9393
To test your changes locally, you have to compile the provider (requires Go 1.24) and configure the Terraform CLI to use the local version.
9494

9595
1. Clone the repository.
96+
1. Run `$ make build` to build the Terraform provider binary in `<PATH_TO_REPO>/bin/`
9697
1. Create a `.terraformrc` config file in your home directory (`~`) for the terraform CLI with the following content:
9798

9899
```hcl
99100
provider_installation {
100101
dev_overrides {
101-
"registry.terraform.io/stackitcloud/stackit" = "<PATH_TO_BINARY>"
102+
"registry.terraform.io/stackitcloud/stackit" = "<PATH_TO_REPO>/bin/"
102103
}
103104

104105
# For all other providers, install them directly from their origin provider
@@ -163,6 +164,16 @@ To make your contribution, follow these steps:
163164
5. Create a pull request with your changes.
164165
6. The pull request will be reviewed by the repo maintainers. If you need to make further changes, make additional commits to keep commit history. When the PR is merged, commits will be squashed.
165166

167+
> [!TIP]
168+
>
169+
> To ensure smooth review and integration of your code contributions, follow these guidelines:
170+
>
171+
> **Break down large changes into smaller PRs**: Separate new features or bigger changes into multiple smaller Pull Requests.
172+
> This allows us to provide earlier feedback and makes it easier to review your PR.
173+
>
174+
> **Create a draft PR for early feedback**: If you want feedback during the implementation process, create a draft PR so we can have a look.
175+
176+
166177
## Bug Reports
167178

168179
If you would like to report a bug, please open a [GitHub issue](https://github.com/stackitcloud/terraform-provider-stackit/issues/new).

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ coverage:
4646
test-acceptance-tf:
4747
@if [ -z $(TF_ACC_PROJECT_ID) ]; then echo "Input TF_ACC_PROJECT_ID missing"; exit 1; fi
4848
@if [ -z $(TF_ACC_ORGANIZATION_ID) ]; then echo "Input TF_ACC_ORGANIZATION_ID missing"; exit 1; fi
49+
@if [ -z $(TF_ACC_REGION) ]; then echo "Input TF_ACC_REGION missing"; exit 1; fi
4950
@if [ -z $(TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH) ]; then \
5051
echo "Input TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH missing. Creating a default file for testing."; \
5152
fi
5253
@echo "Running acceptance tests for the terraform provider"
5354
@cd $(ROOT_DIR)/stackit && TF_ACC=1 \
5455
TF_ACC_PROJECT_ID=$(TF_ACC_PROJECT_ID) \
5556
TF_ACC_ORGANIZATION_ID=$(TF_ACC_ORGANIZATION_ID) \
57+
TF_ACC_REGION=$(TF_ACC_REGION) \
5658
go test ./... -count=1 -timeout=30m && \
5759
cd $(ROOT_DIR)

README.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,68 @@ If you don't need these fields, don't set the experiment flag `network`, to use
207207

208208
## Acceptance Tests
209209

210+
> [!WARNING]
211+
> Acceptance tests will create real resources, which may incur in costs.
212+
> Some resource may leftover after a test run. This could happen if the tests are modified, tests are stopped during the run or losing the network connection.
213+
> These resource must be removed manually with the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli) or the STACKIT Portal.
214+
210215
Terraform acceptance tests are run using the command `make test-acceptance-tf`. For all services,
211216

212217
- The env var `TF_ACC_PROJECT_ID` must be set with the ID of the STACKIT test project to test it.
218+
- The env var `TF_ACC_REGION` must be set with the region in which the tests should be run.
213219
- Authentication is set as usual.
214220
- Optionally, the env var `TF_ACC_XXXXXX_CUSTOM_ENDPOINT` (where `XXXXXX` is the uppercase name of the service) can be set to use endpoints other than the default value.
215221
- There are some acceptance test where it is needed to provide additional parameters, some of them have default values in order to run normally without manual interaction. Those default values can be overwritten (see testutils.go for a full list.)
216222

217223
Additionally:
218224

219-
- For the Resource Manager service:
220-
- A service account with permissions to create and delete projects is required
221-
- The env var `TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL` must be set as the email of the service account
222-
- The env var `TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN` must be set as a valid token of the service account. Can also be set in the credentials file used by authentication (see [Authentication](#authentication) for more details)
223-
- The env var `TF_ACC_PROJECT_ID` is ignored
225+
| Env var | Value | Example value | needed for Acc tests of the following services |
226+
|---------------------------------------------|---------------------------------------------------------------------------------------------------------|----------------------------------------|------------------------------------------------|
227+
| `TF_ACC_ORGANIZATION_ID` | ID of the STACKIT test organization | `5353ccfa-a984-4b96-a71d-b863dd2b7087` | `authorization`, `iaas` |
228+
| `TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL` | Email of the STACKIT service account | `[email protected]` | `authorization`, `resourcemanager` |
229+
| `TF_ACC_SERVER_ID` | ID of a STACKIT Server with STACKIT Server Agent enabled | `5353ccfa-a984-4b96-a71d-b863dd2b7087` | `serverbackup`, `serverupdate` |
230+
| `TF_ACC_TEST_PROJECT_PARENT_CONTAINER_ID` | Container ID of the project parent container (folder within an organization or the organization itself) | `organization-d2b7087` | `resourcemanager` |
231+
| `TF_ACC_TEST_PROJECT_PARENT_UUID` | UUID ID of the project parent container (folder within an organization or the organization itself) | `5353ccfa-a984-4b96-a71d-b863dd2b7087` | `resourcemanager` |
232+
233+
### Run Acceptance Tests of a single service
234+
235+
> [!WARNING]
236+
> Acceptance tests will create real resources, which may incur in costs.
237+
> Some resource may leftover after a test run. This could happen if the tests are modified, tests are stopped during the run or losing the network connection.
238+
> These resource must be removed manually with the [STACKIT CLI](https://github.com/stackitcloud/stackit-cli) or the STACKIT Portal.
239+
240+
For running the acceptance tests of a single service, set the required env vars from above.
241+
Set the env var `TF_ACC=1`, to enable the acceptance tests.
242+
243+
Start the acceptance tests:
244+
245+
1. Configure your env vars in a file, e.g.
246+
```sh
247+
# acc-tests.env
248+
export TF_ACC="1"
249+
export TF_ACC_REGION="eu01"
250+
...
251+
```
252+
2. Read the env vars from the file
253+
```sh
254+
source acc-tests.env
255+
```
256+
3. Start the acceptance tests
257+
```sh
258+
$ go test -timeout=60m -v stackit/internal/services/<service>/<service>_acc_test.go
259+
```
260+
261+
Alternative, set your env vars inline and start the acceptance test:
262+
```sh
263+
$ TF_ACC=1 \
264+
TF_ACC_PROJECT_ID=<PROJECT_ID> \
265+
TF_ACC_REGION=<REGION> \
266+
STACKIT_SERVICE_ACCOUNT_KEY_PATH=<PATH/TO/SA_KEY.json> \
267+
go test -timeout=60m -v stackit/internal/services/<service>/<service>_acc_test.go
268+
```
269+
224270

225-
**WARNING:** Acceptance tests will create real resources, which may incur in costs.
271+
For some services the acceptance tests take more time. By setting the timeout via the flag `-timeout=` to a higher time, you ensure that the tests will not be stopped.
226272

227273
## Migration
228274

stackit/internal/services/ske/ske_acc_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ var testConfigVarsMin = config.Variables{
5353

5454
var testConfigVarsMax = config.Variables{
5555
"project_id": config.StringVariable(testutil.ProjectId),
56-
"organization_id": config.StringVariable(testutil.OrganizationId),
5756
"name": config.StringVariable(maxTestName),
5857
"nodepool_availability_zone1": config.StringVariable(fmt.Sprintf("%s-1", testutil.Region)),
5958
"nodepool_machine_type": config.StringVariable("g2i.2"),

0 commit comments

Comments
 (0)