Skip to content

Commit d69fb92

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents b7bf33e + 1305e67 commit d69fb92

128 files changed

Lines changed: 4438 additions & 1599 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package foo
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"regexp"
7+
"testing"
8+
9+
"github.com/google/uuid"
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
12+
)
13+
14+
func TestFooSavesIDsOnError(t *testing.T) {
15+
/* Setup code:
16+
- define known values for attributes used in id
17+
- create mock server
18+
- define minimal tf config with custom endpoint pointing to mock server
19+
*/
20+
var (
21+
projectId = uuid.NewString()
22+
barId = uuid.NewString()
23+
)
24+
const region = "eu01"
25+
s := testutil.NewMockServer(t)
26+
defer s.Server.Close()
27+
tfConfig := fmt.Sprintf(`
28+
provider "stackit" {
29+
foo_custom_endpoint = "%s"
30+
service_account_token = "mock-server-needs-no-auth"
31+
}
32+
33+
resource "stackit_foo" "foo" {
34+
project_id = "%s"
35+
}
36+
`, s.Server.URL, projectId)
37+
38+
/* Test steps:
39+
1. Create resource with mocked backend
40+
2. Verify with a refresh, that IDs are saved to state
41+
*/
42+
resource.UnitTest(t, resource.TestCase{
43+
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
44+
Steps: []resource.TestStep{
45+
{
46+
PreConfig: func() {
47+
/* Setup mock responses for create and waiter.
48+
The create response succeeds and returns the barId, but the waiter fails with an error.
49+
We can't check the state in this step, because the create returns early due to the waiter error.
50+
TF won't execute any Checks of the TestStep if there is an error.
51+
*/
52+
s.Reset(
53+
testutil.MockResponse{
54+
Description: "create foo",
55+
ToJsonBody: &BarResponse{
56+
BarId: barId,
57+
},
58+
},
59+
testutil.MockResponse{Description: "failing waiter", StatusCode: http.StatusInternalServerError},
60+
)
61+
},
62+
Config: tfConfig,
63+
ExpectError: regexp.MustCompile("Error creating foo.*"),
64+
},
65+
{
66+
PreConfig: func() {
67+
/* Setup mock responses for refresh and delete.
68+
The refresh response fails with an error, but we want to verify that the URL contains the correct IDs.
69+
After the test TF will automatically destroy the resource. So we set up mocks to simulate a successful delete.
70+
*/
71+
s.Reset(
72+
testutil.MockResponse{
73+
Description: "refresh",
74+
Handler: func(w http.ResponseWriter, req *http.Request) {
75+
expected := fmt.Sprintf("/v1/projects/%s/regions/%s/foo/%s", projectId, region, barId)
76+
if req.URL.Path != expected {
77+
t.Errorf("unexpected URL path: got %s, want %s", req.URL.Path, expected)
78+
}
79+
w.WriteHeader(http.StatusInternalServerError)
80+
},
81+
},
82+
testutil.MockResponse{Description: "delete"},
83+
testutil.MockResponse{Description: "delete waiter", StatusCode: http.StatusGone},
84+
)
85+
},
86+
RefreshState: true,
87+
ExpectError: regexp.MustCompile("Error reading foo.*"),
88+
},
89+
},
90+
})
91+
}

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
uses: actions/checkout@v6
5858

5959
- name: Check GoReleaser
60-
uses: goreleaser/goreleaser-action@v6
60+
uses: goreleaser/goreleaser-action@v7
6161
with:
6262
args: check
6363

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
3434
- name: Run GoReleaser
35-
uses: goreleaser/goreleaser-action@v6
35+
uses: goreleaser/goreleaser-action@v7
3636
with:
3737
args: release --clean
3838
env:

CONTRIBUTION.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,22 @@ If you want to onboard resources of a STACKIT service `foo` that was not yet in
8484
```
8585
4. Create a utils package, for service `foo` it would be `stackit/internal/foo/utils`. Add a `ConfigureClient()` func and use it in your resource and datasource implementations.
8686

87-
https://github.com/stackitcloud/terraform-provider-stackit/blob/main/.github/docs/contribution-guide/utils/util.go
87+
https://github.com/stackitcloud/terraform-provider-stackit/blob/main/.github/docs/contribution-guide/utils/util.go
88+
89+
5. If the service `foo` uses async creation (you have to use a waiter after creating the resource), we want to save the
90+
IDs as soon as possible to the state. Should the waiter time out, we'll still have the IDs in the state and allow
91+
further usage of that resource.
92+
93+
https://github.com/stackitcloud/terraform-provider-stackit/blob/main/.github/docs/contribution-guide/resource.go
94+
95+
The example in the contribution-guide linked above, does this by calling `utils.SetAndLogStateFields` before calling
96+
the waiter.
97+
98+
To test this we use terraforms acceptance tests in unit test mode. These tests are named `Test<RESOURCE>SavesIDsOnError`.
99+
You can find an annotated example of such tests in:
100+
101+
https://github.com/stackitcloud/terraform-provider-stackit/blob/main/.github/docs/contribution-guide/resource.go
102+
88103

89104
### Local development
90105

docs/data-sources/cdn_distribution.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ Read-Only:
5858

5959
Read-Only:
6060

61-
- `geofencing` (Map of List of String) A map of URLs to a list of countries where content is allowed.
62-
- `origin_request_headers` (Map of String) The configured origin request headers for the backend
63-
- `origin_url` (String) The configured backend type for the distribution
64-
- `type` (String) The configured backend type. Possible values are: `http`.
61+
- `bucket_url` (String) The URL of the bucket (e.g. https://s3.example.com). Required if type is 'bucket'.
62+
- `geofencing` (Map of List of String) The configured type http to configure countries where content is allowed. A map of URLs to a list of countries
63+
- `origin_request_headers` (Map of String) The configured type http origin request headers for the backend
64+
- `origin_url` (String) The configured backend type http for the distribution
65+
- `region` (String) The region where the bucket is hosted. Required if type is 'bucket'.
66+
- `type` (String) The configured backend type. Possible values are: `http`, `bucket`.
6567

6668

6769
<a id="nestedatt--config--optimizer"></a>

docs/data-sources/dns_zone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data "stackit_dns_zone" "example" {
2828

2929
### Optional
3030

31-
- `dns_name` (String) The zone name. E.g. `example.com`
31+
- `dns_name` (String) The zone name. E.g. `example.com` (must not end with a trailing dot).
3232
- `zone_id` (String) The zone ID.
3333

3434
### Read-Only

docs/data-sources/logs_access_token.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
page_title: "stackit_logs_access_token Data Source - stackit"
44
subcategory: ""
55
description: |-
6-
Logs access token data source schema.
7-
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
6+
Logs access token data source schema. Uses the default_region specified in the provider configuration as a fallback in case no region is defined on datasource level.
87
---
98

109
# stackit_logs_access_token (Data Source)
1110

12-
Logs access token data source schema.
13-
14-
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
11+
Logs access token data source schema. Uses the `default_region` specified in the provider configuration as a fallback in case no `region` is defined on datasource level.
1512

1613
## Example Usage
1714

docs/data-sources/logs_instance.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
page_title: "stackit_logs_instance Data Source - stackit"
44
subcategory: ""
55
description: |-
6-
Logs instance data source schema.
7-
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
6+
Logs instance data source schema. Uses the default_region specified in the provider configuration as a fallback in case no region is defined on datasource level.
87
---
98

109
# stackit_logs_instance (Data Source)
1110

12-
Logs instance data source schema.
13-
14-
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
11+
Logs instance data source schema. Uses the `default_region` specified in the provider configuration as a fallback in case no `region` is defined on datasource level.
1512

1613
## Example Usage
1714

docs/data-sources/network.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ data "stackit_network" "example" {
3333

3434
### Read-Only
3535

36+
- `dhcp` (Boolean) Shows if DHCP is enabled for the network.
3637
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`network_id`".
3738
- `ipv4_gateway` (String) The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
3839
- `ipv4_nameservers` (List of String) The IPv4 nameservers of the network.

docs/data-sources/rabbitmq_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ Read-Only:
5858
- `sgw_acl` (String) Comma separated list of IP networks in CIDR notation which are allowed to access this instance.
5959
- `syslog` (List of String) List of syslog servers to send logs to.
6060
- `tls_ciphers` (List of String) List of TLS ciphers to use.
61-
- `tls_protocols` (String) TLS protocol to use.
61+
- `tls_protocols` (List of String) TLS protocol versions to use.

0 commit comments

Comments
 (0)