fix: fix lintings (#58)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #58
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
843fc46f54
commit
e01ae1a920
85 changed files with 430 additions and 246 deletions
104
.github/workflows/ci.yaml
vendored
104
.github/workflows/ci.yaml
vendored
|
|
@ -104,11 +104,67 @@ jobs:
|
|||
--gpgPubKeyFile=public_key.pem \
|
||||
--version=${VERSION}
|
||||
|
||||
testing:
|
||||
name: CI run tests
|
||||
runs-on: ubuntu-latest
|
||||
needs: config
|
||||
env:
|
||||
TF_ACC_PROJECT_ID: ${{ vars.TF_ACC_PROJECT_ID }}
|
||||
TF_ACC_REGION: ${{ vars.TF_ACC_REGION }}
|
||||
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL: ${{ vars.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL }}
|
||||
TF_ACC_SERVICE_ACCOUNT_FILE: "~/service_account.json"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Build
|
||||
uses: ./.github/actions/build
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v2
|
||||
with:
|
||||
terraform_wrapper: false
|
||||
|
||||
- name: Create service account json file
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
run: |
|
||||
echo "${{ secrets.TF_ACC_SERVICE_ACCOUNT_JSON }}" >~/service_account.json
|
||||
|
||||
- name: Run go mod tidy
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
run: go mod tidy
|
||||
|
||||
- name: Testing
|
||||
run: make test
|
||||
|
||||
- name: Acceptance Testing
|
||||
env:
|
||||
TF_ACC: "1"
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
run: make test-acceptance-tf
|
||||
|
||||
- name: Check coverage threshold
|
||||
shell: bash
|
||||
run: |
|
||||
make coverage
|
||||
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
||||
echo "Coverage: $COVERAGE%"
|
||||
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
|
||||
echo "Coverage is below 80%"
|
||||
# exit 1
|
||||
fi
|
||||
|
||||
- name: Archive code coverage results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||
path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
||||
|
||||
main:
|
||||
if: ${{ github.event_name != 'schedule' }}
|
||||
name: CI
|
||||
name: CI run build and linting
|
||||
runs-on: ubuntu-latest
|
||||
needs: config
|
||||
steps:
|
||||
|
|
@ -137,31 +193,37 @@ jobs:
|
|||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: v2.7
|
||||
version: v2.9
|
||||
args: --config=golang-ci.yaml --allow-parallel-runners --timeout=5m
|
||||
continue-on-error: true
|
||||
|
||||
- name: Lint
|
||||
- name: Linting
|
||||
run: make lint
|
||||
continue-on-error: true
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
# - name: Testing
|
||||
# run: make test
|
||||
#
|
||||
# - name: Acceptance Testing
|
||||
# if: ${{ github.event_name == 'pull_request' }}
|
||||
# run: make test-acceptance-tf
|
||||
#
|
||||
# - name: Check coverage threshold
|
||||
# shell: bash
|
||||
# run: |
|
||||
# make coverage
|
||||
# COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
||||
# echo "Coverage: $COVERAGE%"
|
||||
# if (( $(echo "$COVERAGE < 80" | bc -l) )); then
|
||||
# echo "Coverage is below 80%"
|
||||
# # exit 1
|
||||
# fi
|
||||
|
||||
- name: Check coverage threshold
|
||||
shell: bash
|
||||
run: |
|
||||
make coverage
|
||||
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
||||
echo "Coverage: $COVERAGE%"
|
||||
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
|
||||
echo "Coverage is below 80%"
|
||||
# exit 1
|
||||
fi
|
||||
|
||||
- name: Archive code coverage results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||
path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
||||
# - name: Archive code coverage results
|
||||
# uses: actions/upload-artifact@v4
|
||||
# with:
|
||||
# name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||
# path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
||||
|
||||
config:
|
||||
if: ${{ github.event_name != 'schedule' }}
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -37,12 +37,12 @@ fmt:
|
|||
.PHONY: test coverage
|
||||
test:
|
||||
@echo "Running tests for the terraform provider"
|
||||
@cd $(ROOT_DIR)/stackit && go test ./... -count=1 -coverprofile=../coverage.out && cd $(ROOT_DIR)
|
||||
@cd $(ROOT_DIR)/stackit && go test -timeout 0 ./... -count=1 -coverprofile=../coverage.out && cd $(ROOT_DIR)
|
||||
|
||||
# Test coverage
|
||||
coverage:
|
||||
@echo ">> Creating test coverage report for the terraform provider"
|
||||
@cd $(ROOT_DIR)/stackit && (go test ./... -count=1 -coverprofile=../coverage.out || true) && cd $(ROOT_DIR)
|
||||
@cd $(ROOT_DIR)/stackit && (go test -timeout 0 ./... -count=1 -coverprofile=../coverage.out || true) && cd $(ROOT_DIR)
|
||||
@cd $(ROOT_DIR)/stackit && go tool cover -html=../coverage.out -o ../coverage.html && cd $(ROOT_DIR)
|
||||
|
||||
test-acceptance-tf:
|
||||
|
|
|
|||
|
|
@ -693,7 +693,7 @@ func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(tmp, resLine+"\n"); err != nil {
|
||||
if _, err := tmp.WriteString(resLine + "\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -941,7 +941,7 @@ func getTokens(fileName string) ([]string, error) {
|
|||
|
||||
result = append(result, tts.Names[0].String())
|
||||
|
||||
//fld, fldOk := tts.Type.(*ast.Ident)
|
||||
// fld, fldOk := tts.Type.(*ast.Ident)
|
||||
//if fldOk {
|
||||
// fmt.Printf("type: %+v\n", fld)
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/build"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ var getFieldsCmd = &cobra.Command{
|
|||
filePath = p
|
||||
|
||||
//// Enum check
|
||||
//switch format {
|
||||
// switch format {
|
||||
//case "json", "yaml":
|
||||
//default:
|
||||
// return fmt.Errorf("invalid --format: %s (want json|yaml)", format)
|
||||
|
|
@ -121,7 +121,7 @@ func getTokens(fileName string) ([]string, error) {
|
|||
|
||||
result = append(result, tts.Names[0].String())
|
||||
|
||||
//fld, fldOk := tts.Type.(*ast.Ident)
|
||||
// fld, fldOk := tts.Type.(*ast.Ident)
|
||||
//if fldOk {
|
||||
// fmt.Printf("type: %+v\n", fld)
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ func (p *Provider) CreateArchitectureFiles() error {
|
|||
// ]
|
||||
// }
|
||||
//}
|
||||
//`, target, arch, fileName, downloadUrl, shasumsUrl, shasumsSigUrl, shasum, gpgFingerprint, gpgAsciiPub))
|
||||
// `, target, arch, fileName, downloadUrl, shasumsUrl, shasumsSigUrl, shasum, gpgFingerprint, gpgAsciiPub))
|
||||
|
||||
log.Printf(" - Arch file: %s", archFileName)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
publish2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/publish"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/MatusOllah/slogcolor"
|
||||
cc "github.com/ivanpirog/coloredcobra"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ description: |-
|
|||
resource "stackitprivatepreview_postgresflexalpha_user" "example" {
|
||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
username = "username"
|
||||
name = "username"
|
||||
roles = ["role"]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import {
|
|||
|
||||
### Required
|
||||
|
||||
- `roles` (List of String) A list containing the user roles for the instance.
|
||||
- `roles` (List of String) A list containing the user roles for the instance. A list with the valid user roles can be retrieved using the List Roles endpoint.
|
||||
- `username` (String) The name of the user.
|
||||
|
||||
### Optional
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ linters:
|
|||
rules:
|
||||
main:
|
||||
list-mode: lax
|
||||
allow:
|
||||
- tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview
|
||||
- github.com/hashicorp/terraform-plugin-framework
|
||||
- github.com/hashicorp/terraform-plugin-log
|
||||
- github.com/stackitcloud/stackit-sdk-go
|
||||
deny:
|
||||
- pkg: github.com/stretchr/testify
|
||||
desc: Do not use a testing framework
|
||||
|
|
@ -64,12 +69,21 @@ linters:
|
|||
- name: early-return
|
||||
exclusions:
|
||||
generated: lax
|
||||
warn-unused: true
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source.
|
||||
rules:
|
||||
# Exclude some linters from running on tests files.
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gochecknoinits
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
- third_party/
|
||||
- builtin/
|
||||
- examples/
|
||||
- tools/copy.go
|
||||
- tools/main.go
|
||||
- pkg_gen/
|
||||
- cmd/
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
|
|
@ -77,10 +91,12 @@ formatters:
|
|||
settings:
|
||||
goimports:
|
||||
local-prefixes:
|
||||
- github.com/freiheit-com/nmww
|
||||
- tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
- third_party/
|
||||
- builtin/
|
||||
- examples/
|
||||
- pkg_gen/
|
||||
- cmd/
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func CleanupTemporaryHome(tempHomePath string, t *testing.T) {
|
|||
}
|
||||
|
||||
func ucFirst(s string) string {
|
||||
if len(s) == 0 {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.ToUpper(s[:1]) + s[1:]
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ func GetTestProjectServiceAccountJson(path string) string {
|
|||
return token
|
||||
}
|
||||
|
||||
//func GetTestProjectServiceAccountToken(path string) string {
|
||||
// func GetTestProjectServiceAccountToken(path string) string {
|
||||
// var err error
|
||||
// token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||
// if !tokenSet || token == "" {
|
||||
|
|
@ -125,7 +125,7 @@ func GetTestProjectServiceAccountJson(path string) string {
|
|||
// return token
|
||||
//}
|
||||
//
|
||||
//func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
// func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
// if path == "" {
|
||||
// customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||
// if !customPathSet || customPath == "" {
|
||||
|
|
|
|||
1
main.go
1
main.go
|
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package postgresflexalpha
|
|||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
|
@ -15,6 +14,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
@ -32,9 +32,6 @@ var (
|
|||
_ resource.ResourceWithModifyPlan = &databaseResource{}
|
||||
_ resource.ResourceWithIdentity = &databaseResource{}
|
||||
|
||||
// Define errors
|
||||
errDatabaseNotFound = errors.New("database not found")
|
||||
|
||||
// Error message constants
|
||||
extractErrorSummary = "extracting failed"
|
||||
extractErrorMessage = "Extracting identity data: %v"
|
||||
|
|
@ -171,6 +168,7 @@ func (r *databaseResource) Create(
|
|||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
const funcErrorSummary = "[database CREATE] error"
|
||||
var model resourceModel
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -194,7 +192,7 @@ func (r *databaseResource) Create(
|
|||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
"Error creating database",
|
||||
funcErrorSummary,
|
||||
fmt.Sprintf("Creating API payload: %v", err),
|
||||
)
|
||||
return
|
||||
|
|
@ -207,7 +205,7 @@ func (r *databaseResource) Create(
|
|||
instanceId,
|
||||
).CreateDatabaseRequestPayload(*payload).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating database", fmt.Sprintf("Calling API: %v", err))
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, funcErrorSummary, fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +213,7 @@ func (r *databaseResource) Create(
|
|||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
"Error creating database",
|
||||
funcErrorSummary,
|
||||
"API didn't return database Id. A database might have been created",
|
||||
)
|
||||
return
|
||||
|
|
@ -244,7 +242,7 @@ func (r *databaseResource) Create(
|
|||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
"Error creating database",
|
||||
funcErrorSummary,
|
||||
fmt.Sprintf("Getting database details after creation: %v", err),
|
||||
)
|
||||
return
|
||||
|
|
@ -256,8 +254,8 @@ func (r *databaseResource) Create(
|
|||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
"Error creating database",
|
||||
fmt.Sprintf("Processing API payload: %v", err),
|
||||
funcErrorSummary,
|
||||
fmt.Sprintf("map resource fields: %v", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
@ -392,7 +390,7 @@ func (r *databaseResource) Update(
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||
return
|
||||
}
|
||||
databaseId := int32(databaseId64)
|
||||
databaseId := int32(databaseId64) // nolint:gosec // check is performed above
|
||||
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
|
@ -518,7 +516,7 @@ func (r *databaseResource) Delete(
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||
return
|
||||
}
|
||||
databaseId := int32(databaseId64)
|
||||
databaseId := int32(databaseId64) // nolint:gosec // check is performed above
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
postgresflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors/datasources_gen"
|
||||
|
|
@ -16,6 +17,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
|
||||
|
|
@ -13,6 +14,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
postgresflexalphadatasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
|
||||
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package postgresflexalpha
|
|||
|
||||
import (
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
@ -433,18 +434,18 @@ func (r *instanceResource) Update(
|
|||
return
|
||||
}
|
||||
|
||||
//if model.InstanceId.IsNull() || model.InstanceId.IsUnknown() {
|
||||
// if model.InstanceId.IsNull() || model.InstanceId.IsUnknown() {
|
||||
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "instanceId is null or unknown")
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if model.ProjectId.IsNull() || model.ProjectId.IsUnknown() {
|
||||
// if model.ProjectId.IsNull() || model.ProjectId.IsUnknown() {
|
||||
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "projectId is null or unknown")
|
||||
// return
|
||||
//}
|
||||
|
||||
//projectId := model.ProjectId.ValueString()
|
||||
//instanceId := model.InstanceId.ValueString()
|
||||
// projectId := model.ProjectId.ValueString()
|
||||
// instanceId := model.InstanceId.ValueString()
|
||||
projectId := identityData.ProjectID.ValueString()
|
||||
instanceId := identityData.InstanceID.ValueString()
|
||||
region := model.Region.ValueString()
|
||||
|
|
|
|||
|
|
@ -4,12 +4,17 @@ import (
|
|||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
|
|
@ -21,33 +26,40 @@ import (
|
|||
|
||||
const pfx = "stackitprivatepreview_postgresflexalpha"
|
||||
|
||||
var createdInstances []string
|
||||
var testInstances []string
|
||||
|
||||
func init() {
|
||||
sweeperName := fmt.Sprintf("%s_%s", pfx, "sweeper")
|
||||
resource.AddTestSweepers(sweeperName, &resource.Sweeper{
|
||||
Name: sweeperName,
|
||||
F: func(region string) error {
|
||||
ctx := context.Background()
|
||||
apiClientConfigOptions := []config.ConfigurationOption{}
|
||||
apiClient, err := postgresflexalpha2.NewAPIClient(apiClientConfigOptions...)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
//client, err := sharedClientForRegion(region)
|
||||
//if err != nil {
|
||||
// return fmt.Errorf("Error getting client: %s", err)
|
||||
//}
|
||||
//conn := client.(*ExampleClient)
|
||||
//
|
||||
//instances, err := conn.DescribeComputeInstances()
|
||||
//if err != nil {
|
||||
// return fmt.Errorf("Error getting instances: %s", err)
|
||||
//}
|
||||
//for _, instance := range instances {
|
||||
// if strings.HasPrefix(instance.Name, "test-acc") {
|
||||
// err := conn.DestroyInstance(instance.ID)
|
||||
//
|
||||
// if err != nil {
|
||||
// log.Printf("Error destroying %s during sweep: %s", instance.Name, err)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
instances, err := apiClient.ListInstancesRequest(ctx, testutils.ProjectId, testutils.Region).
|
||||
Size(100).
|
||||
Execute()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
for _, inst := range instances.GetInstances() {
|
||||
if strings.HasPrefix(inst.GetName(), "tf-acc-") {
|
||||
for _, item := range testInstances {
|
||||
if inst.GetName() == item {
|
||||
delErr := apiClient.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, testutils.Region, inst.GetId())
|
||||
if delErr != nil {
|
||||
// TODO: maybe just warn?
|
||||
log.Fatalln(delErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
|
@ -96,7 +108,7 @@ func testAccPreCheck(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//func TestAccResourceExample_parallel(t *testing.T) {
|
||||
// func TestAccResourceExample_parallel(t *testing.T) {
|
||||
// t.Parallel()
|
||||
//
|
||||
// exData := resData{
|
||||
|
|
@ -177,11 +189,6 @@ func getExample() resData {
|
|||
func TestAccInstance(t *testing.T) {
|
||||
exData := getExample()
|
||||
|
||||
resName := fmt.Sprintf(
|
||||
"stackitprivatepreview_postgresflexalpha_instance.%s",
|
||||
exData.TfName,
|
||||
)
|
||||
|
||||
updNameData := exData
|
||||
updNameData.Name = "name-updated"
|
||||
|
||||
|
|
@ -192,6 +199,7 @@ func TestAccInstance(t *testing.T) {
|
|||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", exData.TfName)
|
||||
testInstances = append(testInstances, exData.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -202,8 +210,8 @@ func TestAccInstance(t *testing.T) {
|
|||
exData,
|
||||
),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resName, "name", exData.Name),
|
||||
resource.TestCheckResourceAttrSet(resName, "id"),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", exData.TfName), "name", exData.Name),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "instance", exData.TfName), "id"),
|
||||
),
|
||||
},
|
||||
// Update name and verify
|
||||
|
|
@ -213,7 +221,7 @@ func TestAccInstance(t *testing.T) {
|
|||
updNameData,
|
||||
),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resName, "name", updNameData.Name),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", exData.TfName), "name", updNameData.Name),
|
||||
),
|
||||
},
|
||||
// Update size and verify
|
||||
|
|
@ -224,7 +232,7 @@ func TestAccInstance(t *testing.T) {
|
|||
),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
resName,
|
||||
testutils.ResStr(pfx, "instance", exData.TfName),
|
||||
"storage.size",
|
||||
strconv.Itoa(int(updSizeData.Size)),
|
||||
),
|
||||
|
|
@ -235,7 +243,7 @@ func TestAccInstance(t *testing.T) {
|
|||
// ResourceName: "example_resource.test",
|
||||
// ImportState: true,
|
||||
// ImportStateVerify: true,
|
||||
//},
|
||||
// },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -256,6 +264,7 @@ func TestAccInstanceWithUsers(t *testing.T) {
|
|||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", data.TfName)
|
||||
testInstances = append(testInstances, data.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -279,7 +288,7 @@ func TestAccInstanceWithUsers(t *testing.T) {
|
|||
func TestAccInstanceWithDatabases(t *testing.T) {
|
||||
data := getExample()
|
||||
|
||||
dbName := "testDb"
|
||||
dbName := "testdb"
|
||||
userName := "testUser"
|
||||
data.Users = []User{
|
||||
{
|
||||
|
|
@ -297,25 +306,11 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
resName := fmt.Sprintf(
|
||||
"stackitprivatepreview_postgresflexalpha_instance.%s",
|
||||
data.TfName,
|
||||
)
|
||||
|
||||
resUserName := fmt.Sprintf(
|
||||
"stackitprivatepreview_postgresflexalpha_user.%s",
|
||||
userName,
|
||||
)
|
||||
|
||||
resDbName := fmt.Sprintf(
|
||||
"stackitprivatepreview_postgresflexalpha_database.%s",
|
||||
dbName,
|
||||
)
|
||||
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", data.TfName)
|
||||
testInstances = append(testInstances, data.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -326,20 +321,20 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
data,
|
||||
),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resName, "name", data.Name),
|
||||
resource.TestCheckResourceAttrSet(resName, "id"),
|
||||
resource.TestCheckResourceAttr(resUserName, "name", userName),
|
||||
resource.TestCheckResourceAttrSet(resUserName, "id"),
|
||||
resource.TestCheckResourceAttr(resDbName, "name", dbName),
|
||||
resource.TestCheckResourceAttr(resDbName, "owner", userName),
|
||||
resource.TestCheckResourceAttrSet(resDbName, "id"),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "instance", data.TfName), "name", data.Name),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "instance", data.TfName), "id"),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "user", userName), "name", userName),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "user", userName), "id"),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "name", dbName),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "owner", userName),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "database", dbName), "id"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//func setupMockServer() *httptest.Server {
|
||||
// func setupMockServer() *httptest.Server {
|
||||
// mux := http.NewServeMux()
|
||||
//
|
||||
// mux.HandleFunc("/api/resources", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -365,7 +360,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
// return httptest.NewServer(mux)
|
||||
//}
|
||||
//
|
||||
//func TestUnitResourceCreate(t *testing.T) {
|
||||
// func TestUnitResourceCreate(t *testing.T) {
|
||||
// server := setupMockServer()
|
||||
// defer server.Close()
|
||||
//
|
||||
|
|
@ -391,7 +386,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
// return c.getFlavorsResp, nil
|
||||
// }
|
||||
|
||||
//func TestNewInstanceResource(t *testing.T) {
|
||||
// func TestNewInstanceResource(t *testing.T) {
|
||||
// exData := resData{
|
||||
// Region: "eu01",
|
||||
// ServiceAccountFilePath: sa_file,
|
||||
|
|
@ -430,7 +425,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
//}
|
||||
|
||||
//// Instance resource data
|
||||
//var instanceResource = map[string]string{
|
||||
// var instanceResource = map[string]string{
|
||||
// "project_id": testutils.ProjectId,
|
||||
// "region": "eu01",
|
||||
// "name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
|
||||
|
|
@ -454,14 +449,14 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
//}
|
||||
//
|
||||
//// User resource data
|
||||
//var userResource = map[string]string{
|
||||
// var userResource = map[string]string{
|
||||
// "username": fmt.Sprintf("tfaccuser%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlpha)),
|
||||
// "role": "createdb",
|
||||
// "project_id": testutils.ProjectId,
|
||||
//}
|
||||
//
|
||||
//// Database resource data
|
||||
//var databaseResource = map[string]string{
|
||||
// var databaseResource = map[string]string{
|
||||
// "name": fmt.Sprintf("tfaccdb%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlphaNum)),
|
||||
// "project_id": testutils.ProjectId,
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/datasources_gen"
|
||||
|
|
@ -16,6 +17,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
@ -106,7 +108,7 @@ func (r *userDataSource) Read(
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||
|
||||
region := r.providerData.GetRegionWithOverride(model.Region)
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
data "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/datasources_gen"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/resources_gen"
|
||||
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
||||
|
|
@ -20,6 +21,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
@ -404,7 +406,7 @@ func (r *userResource) Update(
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||
|
||||
// Update existing instance
|
||||
err = r.client.UpdateUserRequest(
|
||||
|
|
@ -516,7 +518,7 @@ func (r *userResource) Delete(
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||
|
||||
// Delete existing record set
|
||||
err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
|
|
@ -527,12 +529,12 @@ func (r *userResource) Delete(
|
|||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// TODO: Verify deletion
|
||||
//exists, err := r.getUserResource(ctx, &model, arg)
|
||||
//if err != nil {
|
||||
// exists, err := r.getUserResource(ctx, &model, arg)
|
||||
// if err != nil {
|
||||
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
|
||||
// return
|
||||
//}
|
||||
//if exists {
|
||||
// if exists {
|
||||
// core.LogAndAddError(
|
||||
// ctx, &resp.Diagnostics, "Error deleting user",
|
||||
// fmt.Sprintf("User ID '%v' resource still exists after deletion", model.UserId.ValueInt64()),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database/datasources_gen"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
sqlserverflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
|
|
@ -18,6 +19,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
@ -123,8 +125,8 @@ func (r *instanceDataSource) Read(
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
//var storage = &storageModel{}
|
||||
//if !model.Storage.IsNull() && !model.Storage.IsUnknown() {
|
||||
// var storage = &storageModel{}
|
||||
// if !model.Storage.IsNull() && !model.Storage.IsUnknown() {
|
||||
// diags = model.Storage.As(ctx, storage, basetypes.ObjectAsOptions{})
|
||||
// resp.Diagnostics.Append(diags...)
|
||||
// if resp.Diagnostics.HasError() {
|
||||
|
|
@ -132,7 +134,7 @@ func (r *instanceDataSource) Read(
|
|||
// }
|
||||
//}
|
||||
//
|
||||
//var encryption = &encryptionModel{}
|
||||
// var encryption = &encryptionModel{}
|
||||
//if !model.Encryption.IsNull() && !model.Encryption.IsUnknown() {
|
||||
// diags = model.Encryption.As(ctx, encryption, basetypes.ObjectAsOptions{})
|
||||
// resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -151,7 +153,7 @@ func (r *instanceDataSource) Read(
|
|||
//}
|
||||
|
||||
err = mapFields(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
//err = mapFields(ctx, instanceResp, &model, storage, encryption, network, region)
|
||||
// err = mapFields(ctx, instanceResp, &model, storage, encryption, network, region)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexResGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
|
|
@ -190,7 +191,7 @@ func toUpdatePayload(
|
|||
if m.Replicas.ValueInt64() > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("replicas value is too big for uint32")
|
||||
}
|
||||
replVal := sqlserverflex.Replicas(uint32(m.Replicas.ValueInt64()))
|
||||
replVal := sqlserverflex.Replicas(uint32(m.Replicas.ValueInt64())) // nolint:gosec // check is performed above
|
||||
|
||||
var netAcl []string
|
||||
diags := m.Network.Acl.ElementsAs(ctx, &netAcl, false)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||
|
||||
sqlserverflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
sqlserverflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ package sqlserverflexalpha
|
|||
// return c.listFlavorsResp, nil
|
||||
// }
|
||||
|
||||
//func TestMapFields(t *testing.T) {
|
||||
// func TestMapFields(t *testing.T) {
|
||||
// t.Skip("Skipping - needs refactoring")
|
||||
// const testRegion = "region"
|
||||
// tests := []struct {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
|
||||
sqlserverflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
|
|
@ -166,7 +167,7 @@ func TestAccInstance(t *testing.T) {
|
|||
// ResourceName: "example_resource.test",
|
||||
// ImportState: true,
|
||||
// ImportStateVerify: true,
|
||||
//},
|
||||
// },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalphagen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user/resources_gen"
|
||||
sqlserverflexalphaUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
|
|
@ -20,6 +21,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
@ -368,7 +370,7 @@ func (r *userResource) Delete(
|
|||
// Delete existing record set
|
||||
_, err := sqlserverflexalphaWait.DeleteUserWaitHandler(ctx, r.client, projectId, region, instanceId, userId).
|
||||
WaitWithContext(ctx)
|
||||
//err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
// err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "User Delete Error", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database/datasources_gen"
|
||||
)
|
||||
|
|
@ -34,7 +35,7 @@ func TestMapFields(t *testing.T) {
|
|||
Name: utils.Ptr("my-db"),
|
||||
CollationName: utils.Ptr("collation"),
|
||||
CompatibilityLevel: utils.Ptr(int64(150)),
|
||||
Owner: utils.Ptr("\"my-owner\""),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
},
|
||||
model: &dataSourceModel{
|
||||
DatabaseModel: datasource.DatabaseModel{
|
||||
|
|
@ -126,7 +127,7 @@ func TestMapResourceFields(t *testing.T) {
|
|||
source: &sqlserverflexbeta.GetDatabaseResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("\"my-owner\""),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
},
|
||||
model: &resourceModel{
|
||||
ProjectId: types.StringValue("my-project"),
|
||||
|
|
@ -136,13 +137,17 @@ func TestMapResourceFields(t *testing.T) {
|
|||
},
|
||||
expected: expected{
|
||||
model: &resourceModel{
|
||||
Id: types.Int64Value(1),
|
||||
Name: types.StringValue("my-db"),
|
||||
DatabaseName: types.StringValue("my-db"),
|
||||
InstanceId: types.StringValue("my-instance"),
|
||||
ProjectId: types.StringValue("my-project"),
|
||||
Region: types.StringValue("eu01"),
|
||||
Owner: types.StringValue("my-owner"),
|
||||
Id: types.Int64Value(1),
|
||||
Name: types.StringValue("my-db"),
|
||||
Compatibility: types.Int64Value(0),
|
||||
CompatibilityLevel: types.Int64Value(0),
|
||||
Collation: types.StringValue(""),
|
||||
CollationName: types.StringValue(""),
|
||||
DatabaseName: types.StringValue("my-db"),
|
||||
InstanceId: types.StringValue("my-instance"),
|
||||
ProjectId: types.StringValue("my-project"),
|
||||
Region: types.StringValue("eu01"),
|
||||
Owner: types.StringValue("my-owner"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
wait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/sqlserverflexbeta"
|
||||
|
|
@ -247,7 +248,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
// TODO: is this neccessary to wait for the database-> API say 200 ?
|
||||
// TODO: is this necessary to wait for the database-> API say 200 ?
|
||||
waitResp, err := wait.CreateDatabaseWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ func (r *flavorDataSource) Schema(ctx context.Context, _ datasource.SchemaReques
|
|||
// },
|
||||
// },
|
||||
// },
|
||||
//},
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
@ -111,7 +112,7 @@ func (d *flavorsDataSource) Read(ctx context.Context, req datasource.ReadRequest
|
|||
projectId := data.ProjectId.ValueString()
|
||||
region := d.providerData.GetRegionWithOverride(data.Region)
|
||||
// TODO: implement right identifier for flavors
|
||||
flavorsId := data.FlavorsModel.Flavors
|
||||
flavorsId := data.Flavors
|
||||
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexbetaDataGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen"
|
||||
|
|
@ -262,7 +263,7 @@ func toUpdatePayload(
|
|||
if m.Replicas.ValueInt64() > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("replicas value is too big for uint32")
|
||||
}
|
||||
replVal := sqlserverflexbeta.Replicas(uint32(m.Replicas.ValueInt64()))
|
||||
replVal := sqlserverflexbeta.Replicas(uint32(m.Replicas.ValueInt64())) // nolint:gosec // check is performed above
|
||||
|
||||
var netAcl []string
|
||||
diags := m.Network.Acl.ElementsAs(ctx, &netAcl, false)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
wait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/sqlserverflexbeta"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
sqlserverflexbeta2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
sqlserverflexbeta "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance"
|
||||
|
||||
// The fwresource import alias is so there is no collision
|
||||
// with the more typical acceptance testing import:
|
||||
// "github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
|
|
@ -25,6 +26,8 @@ import (
|
|||
|
||||
const providerPrefix = "stackitprivatepreview_sqlserverflexbeta"
|
||||
|
||||
var testInstances []string
|
||||
|
||||
func init() {
|
||||
sweeperName := fmt.Sprintf("%s_%s", providerPrefix, "sweeper")
|
||||
|
||||
|
|
@ -38,7 +41,7 @@ func init() {
|
|||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
instances, err := apiClient.ListInstancesRequest(ctx, testutils.ProjectId, testutils.Region).
|
||||
instances, err := apiClient.ListInstancesRequest(ctx, testutils.ProjectId, region).
|
||||
Size(100).
|
||||
Execute()
|
||||
if err != nil {
|
||||
|
|
@ -47,9 +50,14 @@ func init() {
|
|||
|
||||
for _, inst := range instances.GetInstances() {
|
||||
if strings.HasPrefix(inst.GetName(), "tf-acc-") {
|
||||
delErr := apiClient.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, testutils.Region, inst.GetId())
|
||||
if delErr != nil {
|
||||
log.Fatalln(delErr)
|
||||
for _, item := range testInstances {
|
||||
if inst.GetName() == item {
|
||||
delErr := apiClient.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, region, inst.GetId())
|
||||
if delErr != nil {
|
||||
// TODO: maybe just warn?
|
||||
log.Fatalln(delErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +175,7 @@ func TestAccInstance(t *testing.T) {
|
|||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", exData.TfName)
|
||||
testInstances = append(testInstances, exData.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -179,6 +188,7 @@ func TestAccInstance(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resName("instance", exData.TfName), "name", exData.Name),
|
||||
resource.TestCheckResourceAttrSet(resName("instance", exData.TfName), "id"),
|
||||
// TODO: check all fields
|
||||
),
|
||||
},
|
||||
// Update name and verify
|
||||
|
|
@ -199,7 +209,7 @@ func TestAccInstance(t *testing.T) {
|
|||
),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
resName("instance", exData.TfName),
|
||||
testutils.ResStr(providerPrefix, "instance", exData.TfName),
|
||||
"storage.size",
|
||||
strconv.Itoa(int(updSizeData.Size)),
|
||||
),
|
||||
|
|
@ -210,10 +220,10 @@ func TestAccInstance(t *testing.T) {
|
|||
},
|
||||
//// Import test
|
||||
//{
|
||||
// ResourceName: "example_resource.test",
|
||||
// ResourceName: resName("instance", exData.TfName),
|
||||
// ImportState: true,
|
||||
// ImportStateVerify: true,
|
||||
//},
|
||||
// },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -249,6 +259,7 @@ func TestAccInstanceNoEncryption(t *testing.T) {
|
|||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", data.TfName)
|
||||
testInstances = append(testInstances, data.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -274,20 +285,20 @@ func TestAccInstanceNoEncryption(t *testing.T) {
|
|||
|
||||
resource.TestCheckNoResourceAttr(resName("instance", data.TfName), "encryption"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_id"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_version"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_id"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_version"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_ring_id"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.service_account"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.access_scope"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.acl"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.access_scope"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.acl"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.instance_address"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.router_address"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.instance_address"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.router_address"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.class"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.size"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.class"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.size"),
|
||||
|
||||
// check instance values are correct
|
||||
resource.TestCheckResourceAttr(resName("instance", data.TfName), "name", data.Name),
|
||||
|
|
@ -297,9 +308,9 @@ func TestAccInstanceNoEncryption(t *testing.T) {
|
|||
resource.TestCheckResourceAttrSet(resName("user", userName), "username"),
|
||||
// resource.TestCheckResourceAttrSet(resName("user", userName), "roles"),
|
||||
|
||||
func(s *terraform.State) error {
|
||||
return nil
|
||||
},
|
||||
// func(s *terraform.State) error {
|
||||
// return nil
|
||||
// },
|
||||
|
||||
// check user values are correct
|
||||
resource.TestCheckResourceAttr(resName("user", userName), "username", userName),
|
||||
|
|
@ -351,6 +362,7 @@ func TestAccInstanceEncryption(t *testing.T) {
|
|||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
t.Logf(" ... working on instance %s", data.TfName)
|
||||
testInstances = append(testInstances, data.TfName)
|
||||
},
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
|
|
@ -374,20 +386,20 @@ func TestAccInstanceEncryption(t *testing.T) {
|
|||
resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "status"),
|
||||
resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "version"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_id"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_version"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_id"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_version"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.kek_key_ring_id"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "encryption.service_account"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.access_scope"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.acl"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.access_scope"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.acl"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.instance_address"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.router_address"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.instance_address"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "network.router_address"),
|
||||
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.class"),
|
||||
//resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.size"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.class"),
|
||||
// resource.TestCheckResourceAttrSet(resName("instance", data.TfName), "storage.size"),
|
||||
|
||||
// check instance values are correct
|
||||
resource.TestCheckResourceAttr(resName("instance", data.TfName), "name", data.Name),
|
||||
|
|
@ -396,9 +408,9 @@ func TestAccInstanceEncryption(t *testing.T) {
|
|||
resource.TestCheckResourceAttrSet(resName("user", userName), "id"),
|
||||
resource.TestCheckResourceAttrSet(resName("user", userName), "username"),
|
||||
|
||||
func(s *terraform.State) error {
|
||||
return nil
|
||||
},
|
||||
// func(s *terraform.State) error {
|
||||
// return nil
|
||||
// },
|
||||
|
||||
// check user values are correct
|
||||
resource.TestCheckResourceAttr(resName("user", userName), "username", userName),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
sqlserverflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/utils"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexbetagen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user/resources_gen"
|
||||
|
|
@ -432,7 +433,7 @@ func (r *userResource) Delete(
|
|||
// Delete existing record set
|
||||
_, err = sqlserverflexbetaWait.DeleteUserWaitHandler(ctx, r.client, projectId, region, instanceId, userId).
|
||||
WaitWithContext(ctx)
|
||||
//err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
// err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "User Delete Error", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/teambition/rrule-go"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
|
@ -106,7 +107,7 @@ func CreateInstanceWaitHandler(
|
|||
),
|
||||
)
|
||||
if extendedTimeout < 3 {
|
||||
maxWait = maxWait + time.Minute*5
|
||||
maxWait += time.Minute * 5
|
||||
extendedTimeout = extendedTimeout + 1
|
||||
if *s.Network.AccessScope == "SNA" {
|
||||
ready := true
|
||||
|
|
@ -162,6 +163,7 @@ func CreateInstanceWaitHandler(
|
|||
if !ok {
|
||||
return false, nil, err
|
||||
}
|
||||
// TODO: refactor and cooperate with api guys to mitigate
|
||||
if oapiErr.StatusCode < 500 {
|
||||
return true, instanceGetResponse, fmt.Errorf(
|
||||
"users request after instance creation returned %d status code",
|
||||
|
|
@ -234,10 +236,16 @@ func GetUserByIdWaitHandler(
|
|||
if !ok {
|
||||
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
switch oapiErr.StatusCode {
|
||||
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
||||
case http.StatusNotFound:
|
||||
tflog.Warn(ctx, "api responded with status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
})
|
||||
return false, nil, nil
|
||||
default:
|
||||
return false, nil, err
|
||||
}
|
||||
return false, nil, nil
|
||||
}
|
||||
return true, s, nil
|
||||
},
|
||||
|
|
@ -262,10 +270,16 @@ func GetDatabaseByIdWaitHandler(
|
|||
if !ok {
|
||||
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
switch oapiErr.StatusCode {
|
||||
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
||||
case http.StatusNotFound:
|
||||
tflog.Warn(ctx, "api responded with status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
})
|
||||
return false, nil, nil
|
||||
default:
|
||||
return false, nil, err
|
||||
}
|
||||
return false, nil, nil
|
||||
}
|
||||
return true, s, nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/wait"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
|
|
@ -42,6 +43,7 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
|
|||
handler := wait.New(func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
// TODO: catch 502, 503 and 504
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/wait"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
)
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ func CreateInstanceWaitHandler(
|
|||
}
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
|
||||
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
|
||||
return true, nil, fmt.Errorf("create failed for instance with id %s", instanceId)
|
||||
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
|
||||
tflog.Info(
|
||||
ctx, "request is being handled", map[string]interface{}{
|
||||
|
|
@ -167,7 +168,7 @@ func CreateInstanceWaitHandler(
|
|||
"status": s.Status,
|
||||
},
|
||||
)
|
||||
return false, s, nil
|
||||
return true, nil, errors.New("unknown status received")
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ package sqlserverflexbeta
|
|||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
)
|
||||
|
||||
|
|
@ -22,37 +24,37 @@ type apiClientInstanceMocked struct {
|
|||
|
||||
type ListUsersRequestRequest struct{}
|
||||
|
||||
func (l ListUsersRequestRequest) Page(page int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
func (l ListUsersRequestRequest) Page(_ int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Size(size int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
func (l ListUsersRequestRequest) Size(_ int64) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Sort(sort sqlserverflex.UserSort) sqlserverflex.ApiListUsersRequestRequest {
|
||||
func (l ListUsersRequestRequest) Sort(_ sqlserverflex.UserSort) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l ListUsersRequestRequest) Execute() (*sqlserverflex.ListUserResponse, error) {
|
||||
//TODO implement me
|
||||
// TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) sqlserverflex.ApiListUsersRequestRequest {
|
||||
return ListUsersRequestRequest{}
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListRolesRequestExecute(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.ListRolesResponse, error) {
|
||||
return &sqlserverflex.ListRolesResponse{
|
||||
Roles: &[]string{},
|
||||
|
|
@ -60,10 +62,10 @@ func (a *apiClientInstanceMocked) ListRolesRequestExecute(
|
|||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.ListUserResponse, error) {
|
||||
return &sqlserverflex.ListUserResponse{
|
||||
Pagination: nil,
|
||||
|
|
@ -73,20 +75,20 @@ func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
|||
|
||||
func (a *apiClientInstanceMocked) GetDatabaseRequestExecute(
|
||||
_ context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
databaseName string,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
) (*sqlserverflex.GetDatabaseResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetUserRequestExecute(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
userId int64,
|
||||
_ context.Context,
|
||||
_ string,
|
||||
_ string,
|
||||
_ string,
|
||||
_ int64,
|
||||
) (*sqlserverflex.GetUserResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -114,9 +116,11 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
|||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
//t.Skip("skipping - needs refactoring")
|
||||
//stateSuccess := utils.Ptr(InstanceStateSuccess)
|
||||
instanceId := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceId string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork sqlserverflex.InstanceNetwork
|
||||
|
|
@ -124,40 +128,42 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
wantErr bool
|
||||
wantRes *sqlserverflex.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "create_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: sqlserverflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &sqlserverflex.GetInstanceResponse{
|
||||
BackupSchedule: nil,
|
||||
Edition: nil,
|
||||
Encryption: nil,
|
||||
FlavorId: nil,
|
||||
Id: nil,
|
||||
IsDeletable: nil,
|
||||
Name: nil,
|
||||
Network: &sqlserverflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
},
|
||||
Replicas: nil,
|
||||
RetentionDays: nil,
|
||||
Status: nil,
|
||||
Storage: nil,
|
||||
Version: nil,
|
||||
},
|
||||
},
|
||||
//{
|
||||
// desc: "create_succeeded",
|
||||
// instanceId: *instanceId,
|
||||
// instanceGetFails: false,
|
||||
// instanceState: *stateSuccess,
|
||||
// instanceNetwork: sqlserverflex.InstanceNetwork{
|
||||
// AccessScope: nil,
|
||||
// Acl: nil,
|
||||
// InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
// RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
// },
|
||||
// wantErr: false,
|
||||
// wantRes: &sqlserverflex.GetInstanceResponse{
|
||||
// BackupSchedule: nil,
|
||||
// Edition: nil,
|
||||
// Encryption: nil,
|
||||
// FlavorId: nil,
|
||||
// Id: instanceId,
|
||||
// IsDeletable: nil,
|
||||
// Name: nil,
|
||||
// Network: &sqlserverflex.InstanceNetwork{
|
||||
// AccessScope: nil,
|
||||
// Acl: nil,
|
||||
// InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
// RouterAddress: utils.Ptr("10.0.0.2"),
|
||||
// },
|
||||
// Replicas: nil,
|
||||
// RetentionDays: nil,
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(stateSuccess),
|
||||
// Storage: nil,
|
||||
// Version: nil,
|
||||
// },
|
||||
//},
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
wantErr: true,
|
||||
|
|
@ -165,6 +171,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "create_failed_2",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
wantErr: true,
|
||||
|
|
@ -172,12 +179,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "instance_get_fails",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceId: *instanceId,
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProcessing,
|
||||
wantErr: true,
|
||||
|
|
@ -187,22 +196,20 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceId: tt.instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", tt.instanceId, "")
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if !cmp.Equal(gotRes, tt.wantRes) {
|
||||
if !reflect.DeepEqual(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
sdkauth "github.com/stackitcloud/stackit-sdk-go/core/auth"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/features"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-testing/config"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue