feat: add branch_protection resource #72

Merged
techknowlogick merged 3 commits from venc0r/terraform-provider-gitea:branch_protection into main 2024-09-11 17:32:49 +00:00
Contributor

added terraform tests for the resource

added terraform tests for the resource
Author
Contributor

In my opionion the terraform validate should check the syntax of the examples. By running without any directory specified, it runs in the root dir, where no tf code is found and complains about my tests, because the -test-directory defaults to tests.

❯ terraform validate examples/ ╷ │ Warning: Provider development overrides are in effect │ │ The following provider development overrides are set in the CLI configuration: │ - go-gitea/gitea in /home/v3nc/Documents/git/gitea.com/gitea/terraform-provider-gitea │ │ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 57, in resource "gitea_team" "test_team": │ 57: members = [gitea_user.test.username] │ │ An argument named "members" is not expected here. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 65, in resource "gitea_team" "admin_team": │ 65: members = [data.gitea_user.me.username] │ │ An argument named "members" is not expected here. ╵ ╷ │ Error: Missing required argument │ │ on examples/main.tf line 99, in resource "gitea_token" "test_token": │ 99: resource "gitea_token" "test_token" { │ │ The argument "scopes" is required, but no definition was found. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 100, in resource "gitea_token" "test_token": │ 100: username = data.gitea_user.me.username │ │ An argument named "username" is not expected here. ╵ 

That reveals that there are some bugs in the examples at the moment. I will update the examples and point the tf validate to the examples dir in the pipeline.

In my opionion the `terraform validate` should check the syntax of the examples. By running without any directory specified, it runs in the root dir, where no tf code is found and complains about my tests, because the `-test-directory` defaults to `tests`. ``` ❯ terraform validate examples/ ╷ │ Warning: Provider development overrides are in effect │ │ The following provider development overrides are set in the CLI configuration: │ - go-gitea/gitea in /home/v3nc/Documents/git/gitea.com/gitea/terraform-provider-gitea │ │ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 57, in resource "gitea_team" "test_team": │ 57: members = [gitea_user.test.username] │ │ An argument named "members" is not expected here. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 65, in resource "gitea_team" "admin_team": │ 65: members = [data.gitea_user.me.username] │ │ An argument named "members" is not expected here. ╵ ╷ │ Error: Missing required argument │ │ on examples/main.tf line 99, in resource "gitea_token" "test_token": │ 99: resource "gitea_token" "test_token" { │ │ The argument "scopes" is required, but no definition was found. ╵ ╷ │ Error: Unsupported argument │ │ on examples/main.tf line 100, in resource "gitea_token" "test_token": │ 100: username = data.gitea_user.me.username │ │ An argument named "username" is not expected here. ╵ ``` That reveals that there are some bugs in the examples at the moment. I will update the examples and point the `tf validate` to the examples dir in the pipeline.
venc0r force-pushed branch_protection from 09526153ba to 4e094034ef 2024-08-15 21:00:29 +00:00 Compare
venc0r force-pushed branch_protection from 4e094034ef to dfc2023664 2024-08-15 21:02:54 +00:00 Compare
venc0r force-pushed branch_protection from dfc2023664 to 5a80d39424 2024-08-15 21:22:42 +00:00 Compare
venc0r force-pushed branch_protection from 5a80d39424 to 4205db6f3b 2024-08-15 21:26:37 +00:00 Compare
venc0r force-pushed branch_protection from 4205db6f3b to 2972a542f6 2024-08-15 21:28:50 +00:00 Compare
Author
Contributor

The terraform validate uses the released version of the provider not the code from the pr. I`m not sure about the purpose of this pipeline, it will never validate the example code before the new version is published published. It will fail after releasing with not up to date examples or it will fail before the release with updated examples which are (mayby) not supported by the current provider version.

I would suggest to build the provider from the pr with development override enabled and test the example for the current commit.

The validate does not work recursive, so only the ./examples/main.tf is tested, the more useful examples in the ./examples/resources directory will still not be validated.

The `terraform validate` uses the released version of the provider not the code from the pr. I`m not sure about the purpose of this pipeline, it will never validate the example code before the new version is published published. It will fail after releasing with not up to date examples or it will fail before the release with updated examples which are (mayby) not supported by the current provider version. I would suggest to build the provider from the pr with development override enabled and test the example for the current commit. The validate does not work recursive, so only the `./examples/main.tf` is tested, the more useful examples in the `./examples/resources` directory will still not be validated.
techknowlogick added 1 commit 2024-09-11 17:32:04 +00:00
Merge branch 'main' into branch_protection
All checks were successful
Setup Terraform / Terraform Versions (pull_request) Successful in 15s
5462207198
techknowlogick merged commit a07bd291f5 into main 2024-09-11 17:32:49 +00:00
Sign in to join this conversation.