Skip to content

Commit 16494fc

Browse files
Code review
1 parent 324f0d5 commit 16494fc

File tree

13 files changed

+163
-197
lines changed

13 files changed

+163
-197
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- run: make tfdocs-generate
4141
- name: Comparing generated Terraform documentation against main
4242
run: |
43-
git diff --compact-summary --exit-code || \
43+
git diff --exit-code || \
4444
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
4545
4646
test:

.gitignore

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
*.dll
2-
*.exe
3-
.DS_Store
4-
example.tf
5-
terraform.tfplan
6-
terraform.tfstate
7-
bin/
8-
dist/
9-
modules-dev/
10-
/pkg/
11-
website/.vagrant
12-
website/.bundle
13-
website/build
14-
website/node_modules
15-
.vagrant/
16-
*.backup
17-
./*.tfstate
18-
.terraform/
19-
*.log
20-
*.bak
21-
*~
22-
.*.swp
23-
.idea
24-
*.iml
25-
*.test
26-
*.iml
27-
28-
website/vendor
29-
30-
# Test exclusions
31-
!command/test-fixtures/**/*.tfstate
32-
!command/test-fixtures/**/.terraform/
33-
34-
# Keep windows files with windows line endings
35-
*.winfile eol=crlf
1+
*.dll
2+
*.exe
3+
.DS_Store
4+
example.tf
5+
terraform.tfplan
6+
terraform.tfstate
7+
bin/
8+
dist/
9+
modules-dev/
10+
/pkg/
11+
website/.vagrant
12+
website/.bundle
13+
website/build
14+
website/node_modules
15+
.vagrant/
16+
*.backup
17+
./*.tfstate
18+
.terraform/
19+
*.log
20+
*.bak
21+
*~
22+
.*.swp
23+
.idea
24+
*.iml
25+
*.test
26+
*.iml
27+
28+
website/vendor
29+
30+
# Test exclusions
31+
!command/test-fixtures/**/*.tfstate
32+
!command/test-fixtures/**/.terraform/
33+
34+
# Keep windows files with windows line endings
35+
*.winfile eol=crlf

.golangci.yml

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# Visit https://golangci-lint.run/ for usage documentation
2-
# and information on other useful linters
3-
issues:
4-
max-per-linter: 0
5-
max-same-issues: 0
6-
7-
linters:
8-
disable-all: true
9-
enable:
10-
- durationcheck
11-
- errcheck
12-
- exportloopref
13-
- forcetypeassert
14-
- godot
15-
- gosimple
16-
- ineffassign
17-
- makezero
18-
- misspell
19-
- nilerr
20-
- predeclared
21-
- staticcheck
22-
- tenv
23-
- unconvert
24-
- unparam
25-
- unused
26-
- vet
1+
# Visit https://golangci-lint.run/ for usage documentation
2+
# and information on other useful linters
3+
issues:
4+
max-per-linter: 0
5+
max-same-issues: 0
6+
7+
linters:
8+
disable-all: true
9+
enable:
10+
- durationcheck
11+
- errcheck
12+
- exportloopref
13+
- forcetypeassert
14+
- godot
15+
- gosimple
16+
- ineffassign
17+
- makezero
18+
- misspell
19+
- nilerr
20+
- predeclared
21+
- staticcheck
22+
- tenv
23+
- unconvert
24+
- unparam
25+
- unused
26+
- vet

docs/guides/howto-uselocalprovider.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ page_title: "Use local provider in terraform root moduls"
88

99
Use the local version of the terraform provider plugin to test the changes in an real life terraform root module using this provider.
1010

11-
## Step-By-Step
11+
1. Navigate to the root directory of the terraform provider and build the provider using the command `go build`. Make sure to run this command after every update to the provider.
1212

13-
1. Depending on the OS create the following file (see [CLI Configuration](https://developer.hashicorp.com/terraform/cli/config/config-file#locations))
13+
2. Depending on your operating system, create the appropriate configuration file for the CLI. On Linux/Apple, create `~/.terraformrc`. On Windows, create `%APPDATA\terraform.rc`. Inside the configuration file, add the following code:
1414

15-
- On Linux/Apple `~/.terraformrc`
16-
- On Windows `%APPDATA\terraform.rc`
15+
```hcl
16+
provider_installation {
17+
dev_overrides {
18+
"DigitecGalaxus/dg-servicebus" = "/mnt/c/Developement/terraform-provider-dg-servicebus"
19+
}
20+
}
21+
```
1722

18-
```hcl
19-
provider_installation {
20-
dev_overrides {
21-
"DigitecGalaxus/dg-servicebus" = "/mnt/c/Developement/terraform-provider-dg-servicebus"
22-
}
23-
}
24-
```
23+
3. Navigate to the root directory of the desired root module and run `terraform init -reconfigure`. You should see a warning message in the output indicating that the provider has been overwritten.
2524

26-
2. Go the root directory of the root module you want to deploy and run `terraform init -reconfigure`. Your should see the follwing message in the output:
27-
28-
![Provider overwrite warning](provider_overwrite.jpg)
25+
![Provider overwrite warning](provider_overwrite.jpg)

docs/resources/endpoint.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ resource "dgservicebus_endpoint" "example" {
2222
"Dg.SalesOrder.V1.AAA",
2323
]
2424
queue_options = {
25-
enable_partitioning = false,
26-
max_size_in_megabytes = 5120,
25+
enable_partitioning = false,
26+
max_size_in_megabytes = 5120,
2727
max_message_size_in_kilobytes = 256,
2828
}
2929
}

examples/provider/provider.tf

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
terraform {
2-
required_providers {
3-
dgservicebus = {
4-
source = "DigitecGalaxus/dg-servicebus"
5-
version = ">= 1.0.0, < 2.0.0"
6-
}
7-
}
8-
}
9-
10-
provider "dgservicebus" {
11-
azure_servicebus_hostname = "nservicebus.servicebus.windows.net"
12-
tenant_id = var.tenant_id
13-
client_id = var.client_id
14-
client_secret = var.client_secret
15-
}
1+
terraform {
2+
required_providers {
3+
dgservicebus = {
4+
source = "DigitecGalaxus/dg-servicebus"
5+
version = ">= 1.0.0, < 2.0.0"
6+
}
7+
}
8+
}
9+
10+
provider "dgservicebus" {
11+
azure_servicebus_hostname = "nservicebus.servicebus.windows.net"
12+
tenant_id = var.tenant_id
13+
client_id = var.client_id
14+
client_secret = var.client_secret
15+
}

examples/resources/dgservicebus_endpoint/resource.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ resource "dgservicebus_endpoint" "example" {
77
"Dg.SalesOrder.V1.AAA",
88
]
99
queue_options = {
10-
enable_partitioning = false,
11-
max_size_in_megabytes = 5120,
10+
enable_partitioning = false,
11+
max_size_in_megabytes = 5120,
1212
max_message_size_in_kilobytes = 256,
1313
}
1414
}
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package asb
2-
3-
import (
4-
az "github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/admin"
5-
)
6-
7-
type AsbClientWrapper struct {
8-
Client *az.Client
9-
}
1+
package asb
2+
3+
import (
4+
az "github.com/Azure/azure-sdk-for-go/sdk/messaging/azservicebus/admin"
5+
)
6+
7+
type AsbClientWrapper struct {
8+
Client *az.Client
9+
}

internal/provider/asb/endpoint_subscription.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ func (w *AsbClientWrapper) GetAsbSubscriptionsRules(
6262

6363
func convertToAsbSubscriptionRule(rule az.RuleProperties) (*AsbSubscriptionRule, error) {
6464
if ruleFilter, ok := rule.Filter.(*az.CorrelationFilter); ok {
65-
ruleFilterValus, ok := ruleFilter.ApplicationProperties[CORRELATIONFILTER_HEADER].(string)
65+
ruleFilterValue, ok := ruleFilter.ApplicationProperties[CORRELATIONFILTER_HEADER].(string)
6666
if !ok {
6767
return nil, fmt.Errorf("rule filter could not be converted to string")
6868
}
6969

7070
return &AsbSubscriptionRule{
7171
Name: rule.Name,
72-
Filter: ruleFilterValus,
72+
Filter: ruleFilterValue,
7373
FilterType: "correlation",
7474
}, nil
7575
}

internal/provider/endpoint/endpoint_resource_import.go

+4-33
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,13 @@ package endpoint
22

33
import (
44
"context"
5-
"fmt"
6-
"strings"
7-
"terraform-provider-dg-servicebus/internal/provider/asb"
85

9-
"github.com/hashicorp/terraform-plugin-framework/path"
106
"github.com/hashicorp/terraform-plugin-framework/resource"
117
)
128

139
func (r *endpointResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
14-
idParts := strings.Split(req.ID, ",")
15-
hasNonEmptySubscriptionArgument := len(idParts) == 3 && idParts[2] != ""
16-
hasNoSubscriptionArgument := len(idParts) == 2
17-
hasEmptyIdValues := len(idParts) >= 2 && idParts[0] == "" && idParts[1] == ""
18-
19-
if !(hasNonEmptySubscriptionArgument || hasNoSubscriptionArgument) || hasEmptyIdValues {
20-
resp.Diagnostics.AddWarning("Foo", fmt.Sprintf("%t %t %t", hasNonEmptySubscriptionArgument, hasNoSubscriptionArgument, hasEmptyIdValues))
21-
resp.Diagnostics.AddError(
22-
"Unexpected import Identifier",
23-
fmt.Sprintf(
24-
"Expected two or three identifier in format: topic_name,endpoint_name,<SubscriptionOne;SubscriptionTwo>. Got %q",
25-
req.ID,
26-
),
27-
)
28-
29-
return
30-
}
31-
32-
model := asb.AsbEndpointModel{TopicName: idParts[0], EndpointName: idParts[1]}
33-
34-
subscriptionNames := []string{}
35-
if hasNonEmptySubscriptionArgument {
36-
subscriptionNames = strings.Split(idParts[2], ";")
37-
}
38-
39-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("topic_name"), model.TopicName)...)
40-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("endpoint_name"), model.EndpointName)...)
41-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("queue_options"), &endpointResourceQueueOptionsModel{})...)
42-
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("subscriptions"), subscriptionNames)...)
10+
resp.Diagnostics.AddError(
11+
"Import not supported yet",
12+
"Import is not supported for this resource",
13+
)
4314
}

internal/provider/endpoint/endpoint_resource_update.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ func (r *endpointResource) UpdateSubscriptions(
7878
resp *resource.UpdateResponse,
7979
) error {
8080
planModel := plan.ToAsbModel()
81-
82-
// tflog.Info(ctx, fmt.Sprintf("Previous state: %s", strings.Join(previousState.Subscriptions, ", ")))
83-
// tflog.Info(ctx, fmt.Sprintf("Plan: %s", strings.Join(plan.Subscriptions, ", ")))
84-
8581
// This is deliberately done in this order, such that if subscriptions are replaced,
8682
// the new subscriptions are created before the old ones are deleted, thus avoiding
8783
// the Endpoint missing events for a short period of time.
@@ -104,6 +100,8 @@ func (r *endpointResource) UpdateSubscriptions(
104100
if err == nil {
105101
continue
106102
}
103+
104+
return err
107105
}
108106

109107
if rule.FilterType != planSubscription.FilterType.ValueString() {

0 commit comments

Comments
 (0)