Skip to content

Commit

Permalink
fix(schemautil): unmarshalling empty userconfig crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel committed Nov 2, 2023
1 parent ee9539f commit 6ace404
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ nav_order: 1

## [X.Y.Z] - YYYY-MM-DD

- Fix unmarshalling empty userconfig crash

## [4.9.3] - 2023-10-27

- Deprecating `project_user`, `account_team` and `account_team_member` resources
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build build-dev test test-unit test-acc test-examples lint lint-go lint-test lint-docs fmt fmt-test fmt-imports clean clean-tools clean-examples sweep generate gen-go docs
.PHONY: build build-dev debug test test-unit test-acc test-examples lint lint-go lint-test lint-docs fmt fmt-test fmt-imports clean clean-tools clean-examples sweep generate gen-go docs

#################################################
# Global
Expand Down Expand Up @@ -34,6 +34,7 @@ $(TERRAFMT): $(TOOLS_BIN_DIR) $(TOOLS_DIR)/go.mod
# See https://github.com/hashicorp/terraform/blob/main/tools/protobuf-compile/protobuf-compile.go#L215
ARCH ?= $(shell $(GO) env GOOS GOARCH | tr '\n' '_' | sed '$$s/_$$//')
BUILD_DEV_DIR ?= ~/.terraform.d/plugins/registry.terraform.io/aiven-dev/aiven/0.0.0+dev/$(ARCH)
BUILD_DEV_BIN ?= $(BUILD_DEV_DIR)/terraform-provider-aiven_v0.0.0+dev

$(BUILD_DEV_DIR):
mkdir -p $(BUILD_DEV_DIR)
Expand All @@ -57,7 +58,14 @@ build:
# }
#}
build-dev: $(BUILD_DEV_DIR)
$(GO) build -o $(BUILD_DEV_DIR)/terraform-provider-aiven_v0.0.0+dev
$(GO) build -gcflags='all=-N -l' -o $(BUILD_DEV_BIN)

#################################################
# Debug
#################################################

debug: build-dev
$(BUILD_DEV_BIN) -debug

#################################################
# Test
Expand Down
5 changes: 4 additions & 1 deletion internal/schemautil/schemautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ func unmarshalUserConfig(src interface{}) ([]map[string]interface{}, error) {
return nil, fmt.Errorf("%w: expected []interface{}", errInvalidStateType)
}

if len(configList) == 0 {
// For some reason, it looks like this is never empty, even if the user config is not set.
// We will keep this check here just in case, but the actual check that breaks the code is
// the one where we check if the first element is nil.
if len(configList) == 0 || configList[0] == nil {
return nil, nil
}

Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (

//go:generate go test -tags userconfig ./internal/schemautil/userconfig

// registryPrefix is the registry prefix for the provider.
const registryPrefix = "registry.terraform.io/"

// version is the version of the provider.
var version = "dev"

Expand All @@ -31,8 +34,15 @@ func main() {
serveOpts = append(serveOpts, tf6server.WithManagedDebug())
}

name := registryPrefix + "aiven/aiven"

//goland:noinspection GoBoolExpressions
if version == "dev" {
name = registryPrefix + "aiven-dev/aiven"
}

err = tf6server.Serve(
"registry.terraform.io/aiven/aiven",
name,
func() tfprotov6.ProviderServer {
return muxServer
},
Expand Down

0 comments on commit 6ace404

Please sign in to comment.