Compare commits
33 commits
v0.0.5-alp
...
alpha
| Author | SHA1 | Date | |
|---|---|---|---|
| 635a9abf20 | |||
| 07458c5677 | |||
| eb13630d2f | |||
| 4a2819787d | |||
| 36eccc52c3 | |||
| 841e702b95 | |||
| aba831cbdd | |||
| 89a24ce780 | |||
| f05e90c35a | |||
| 7ee82366d7 | |||
| d5644ec27f | |||
| 20e9b3ca4c | |||
| 43223f5d1f | |||
| 452f73877f | |||
| 55a0917a86 | |||
| d90236b02e | |||
| b1f8c8a4d9 | |||
| e01ae1a920 | |||
| 843fc46f54 | |||
| 10af1dbbba | |||
| 459120d3b3 | |||
| 82c654f3ba | |||
| 0c9ecfc670 | |||
| 131e1700bb | |||
| 86fc98461c | |||
| ed7ff0f58e | |||
| f2bffa9ece | |||
| 399e8ccb0c | |||
| e21fe64326 | |||
| 4991897eca | |||
| b737875c68 | |||
| 9dbf36dd35 | |||
| 00a43dfb4c |
171 changed files with 13429 additions and 7689 deletions
71
.github/actions/setup-cache-go/action.yaml
vendored
Normal file
71
.github/actions/setup-cache-go/action.yaml
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
name: 'Setup Go and cache dependencies'
|
||||||
|
author: 'Forgejo authors, Marcel S. Henselin'
|
||||||
|
description: |
|
||||||
|
Wrap the setup-go with improved dependency caching.
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
username:
|
||||||
|
description: 'User for which to manage the dependency cache'
|
||||||
|
default: root
|
||||||
|
|
||||||
|
go-version:
|
||||||
|
description: "go version to install"
|
||||||
|
default: '1.25'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: "Install zstd for faster caching"
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get -q install -qq -y zstd
|
||||||
|
|
||||||
|
- name: "Set up Go using setup-go"
|
||||||
|
uses: https://code.forgejo.org/actions/setup-go@v6
|
||||||
|
id: go-version
|
||||||
|
with:
|
||||||
|
go-version: ${{ inputs.go-version }}
|
||||||
|
check-latest: true # Always check for the latest patch release
|
||||||
|
# go-version-file: "go.mod"
|
||||||
|
# do not cache dependencies, we do this manually
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
- name: "Get go environment information"
|
||||||
|
shell: bash
|
||||||
|
id: go-environment
|
||||||
|
run: |
|
||||||
|
chmod 755 $HOME # ensure ${RUN_AS_USER} has permission when go is located in $HOME
|
||||||
|
export GOROOT="$(go env GOROOT)"
|
||||||
|
echo "modcache=$(su ${RUN_AS_USER} -c '${GOROOT}/bin/go env GOMODCACHE')" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "cache=$(su ${RUN_AS_USER} -c '${GOROOT}/bin/go env GOCACHE')" >> "$GITHUB_OUTPUT"
|
||||||
|
env:
|
||||||
|
RUN_AS_USER: ${{ inputs.username }}
|
||||||
|
GO_VERSION: ${{ steps.go-version.outputs.go-version }}
|
||||||
|
|
||||||
|
- name: "Create cache folders with correct permissions (for non-root users)"
|
||||||
|
shell: bash
|
||||||
|
if: inputs.username != 'root'
|
||||||
|
# when the cache is restored, only the permissions of the last part are restored
|
||||||
|
# so assuming that /home/user exists and we are restoring /home/user/go/pkg/mod,
|
||||||
|
# both folders will have the correct permissions, but
|
||||||
|
# /home/user/go and /home/user/go/pkg might be owned by root
|
||||||
|
run: |
|
||||||
|
su ${RUN_AS_USER} -c 'mkdir -p "${MODCACHE_DIR}" "${CACHE_DIR}"'
|
||||||
|
env:
|
||||||
|
RUN_AS_USER: ${{ inputs.username }}
|
||||||
|
MODCACHE_DIR: ${{ steps.go-environment.outputs.modcache }}
|
||||||
|
CACHE_DIR: ${{ steps.go-environment.outputs.cache }}
|
||||||
|
|
||||||
|
- name: "Restore Go dependencies from cache or mark for later caching"
|
||||||
|
id: cache-deps
|
||||||
|
uses: https://code.forgejo.org/actions/cache@v5
|
||||||
|
with:
|
||||||
|
key: setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-${{ steps.go-version.outputs.go_version }}-${{ hashFiles('go.sum', 'go.mod') }}
|
||||||
|
restore-keys: |
|
||||||
|
setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-${{ steps.go-version.outputs.go_version }}-
|
||||||
|
setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-
|
||||||
|
path: |
|
||||||
|
${{ steps.go-environment.outputs.modcache }}
|
||||||
|
${{ steps.go-environment.outputs.cache }}
|
||||||
134
.github/workflows/ci.yaml
vendored
134
.github/workflows/ci.yaml
vendored
|
|
@ -6,6 +6,11 @@ on:
|
||||||
- alpha
|
- alpha
|
||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
# every sunday at 00:00
|
||||||
|
# - cron: '0 0 * * 0'
|
||||||
|
# every day at 00:00
|
||||||
|
- cron: '0 0 * * *'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '!main'
|
- '!main'
|
||||||
|
|
@ -17,6 +22,39 @@ env:
|
||||||
CODE_COVERAGE_ARTIFACT_NAME: "code-coverage"
|
CODE_COVERAGE_ARTIFACT_NAME: "code-coverage"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
runner_test:
|
||||||
|
name: "Test STACKIT runner"
|
||||||
|
runs-on: stackit-docker
|
||||||
|
steps:
|
||||||
|
- name: Install needed tools
|
||||||
|
run: |
|
||||||
|
apt-get -y -qq update
|
||||||
|
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
|
||||||
|
- name: Install go tools
|
||||||
|
run: |
|
||||||
|
go install golang.org/x/tools/cmd/goimports@latest
|
||||||
|
go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest
|
||||||
|
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest
|
||||||
|
|
||||||
|
- name: Setup JAVA
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||||
|
java-version: '21'
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Run build pkg directory
|
||||||
|
run: |
|
||||||
|
go run cmd/main.go build
|
||||||
|
|
||||||
publish_test:
|
publish_test:
|
||||||
name: "Test readiness for publishing provider"
|
name: "Test readiness for publishing provider"
|
||||||
needs: config
|
needs: config
|
||||||
|
|
@ -99,9 +137,67 @@ jobs:
|
||||||
--gpgPubKeyFile=public_key.pem \
|
--gpgPubKeyFile=public_key.pem \
|
||||||
--version=${VERSION}
|
--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:
|
main:
|
||||||
name: CI
|
if: ${{ github.event_name != 'schedule' }}
|
||||||
|
name: CI run build and linting
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: config
|
needs: config
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -130,22 +226,40 @@ jobs:
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v9
|
||||||
with:
|
with:
|
||||||
version: v2.7
|
version: v2.9
|
||||||
args: --config=golang-ci.yaml --allow-parallel-runners --timeout=5m
|
args: --config=golang-ci.yaml --allow-parallel-runners --timeout=5m
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Lint
|
- name: Linting
|
||||||
run: make lint
|
run: make lint
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Test
|
# - name: Testing
|
||||||
run: make test
|
# 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: Archive code coverage results
|
# - name: Archive code coverage results
|
||||||
uses: actions/upload-artifact@v4
|
# uses: actions/upload-artifact@v4
|
||||||
with:
|
# with:
|
||||||
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
# name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||||
path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
# path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
||||||
|
|
||||||
config:
|
config:
|
||||||
|
if: ${{ github.event_name != 'schedule' }}
|
||||||
name: Check GoReleaser config
|
name: Check GoReleaser config
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
29
.github/workflows/runnerstats.yaml
vendored
Normal file
29
.github/workflows/runnerstats.yaml
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: Runner stats
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stats-own:
|
||||||
|
name: "Get own runner stats"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install needed tools
|
||||||
|
run: |
|
||||||
|
apt-get -y -qq update
|
||||||
|
apt-get -y -qq install inxi
|
||||||
|
|
||||||
|
- name: Show stats
|
||||||
|
run: inxi -c 0
|
||||||
|
|
||||||
|
stats-stackit:
|
||||||
|
name: "Get STACKIT runner stats"
|
||||||
|
runs-on: stackit-docker
|
||||||
|
steps:
|
||||||
|
- name: Install needed tools
|
||||||
|
run: |
|
||||||
|
apt-get -y -qq update
|
||||||
|
apt-get -y -qq install inxi
|
||||||
|
|
||||||
|
- name: Show stats
|
||||||
|
run: inxi -c 0
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -46,3 +46,5 @@ dist
|
||||||
|
|
||||||
pkg_gen
|
pkg_gen
|
||||||
/release/
|
/release/
|
||||||
|
.env
|
||||||
|
**/.env
|
||||||
|
|
|
||||||
|
|
@ -19,20 +19,20 @@ builds:
|
||||||
ldflags:
|
ldflags:
|
||||||
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
|
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
|
||||||
goos:
|
goos:
|
||||||
# - freebsd
|
- freebsd
|
||||||
# - windows
|
- windows
|
||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
# - '386'
|
- '386'
|
||||||
# - arm
|
- arm
|
||||||
- arm64
|
- arm64
|
||||||
# ignore:
|
ignore:
|
||||||
# - goos: darwin
|
- goos: darwin
|
||||||
# goarch: '386'
|
goarch: '386'
|
||||||
# - goos: windows
|
- goos: windows
|
||||||
# goarch: arm
|
goarch: arm
|
||||||
binary: '{{ .ProjectName }}_v{{ .Version }}'
|
binary: '{{ .ProjectName }}_v{{ .Version }}'
|
||||||
archives:
|
archives:
|
||||||
- formats: [ 'zip' ]
|
- formats: [ 'zip' ]
|
||||||
|
|
|
||||||
13
Makefile
13
Makefile
|
|
@ -12,9 +12,10 @@ project-tools:
|
||||||
# LINT
|
# LINT
|
||||||
lint-golangci-lint:
|
lint-golangci-lint:
|
||||||
@echo "Linting with golangci-lint"
|
@echo "Linting with golangci-lint"
|
||||||
@$(SCRIPTS_BASE)/lint-golangci-lint.sh
|
@go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint run --fix --config golang-ci.yaml
|
||||||
|
|
||||||
lint-tf:
|
|
||||||
|
lint-tf:
|
||||||
@echo "Linting terraform files"
|
@echo "Linting terraform files"
|
||||||
@terraform fmt -check -diff -recursive
|
@terraform fmt -check -diff -recursive
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ lint: lint-golangci-lint lint-tf
|
||||||
# DOCUMENTATION GENERATION
|
# DOCUMENTATION GENERATION
|
||||||
generate-docs:
|
generate-docs:
|
||||||
@echo "Generating documentation with tfplugindocs"
|
@echo "Generating documentation with tfplugindocs"
|
||||||
|
|
||||||
@$(SCRIPTS_BASE)/tfplugindocs.sh
|
@$(SCRIPTS_BASE)/tfplugindocs.sh
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
|
@ -34,15 +36,16 @@ fmt:
|
||||||
@terraform fmt -diff -recursive
|
@terraform fmt -diff -recursive
|
||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
|
.PHONY: test coverage
|
||||||
test:
|
test:
|
||||||
@echo "Running tests for the terraform provider"
|
@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
|
# Test coverage
|
||||||
coverage:
|
coverage:
|
||||||
@echo ">> Creating test coverage report for the terraform provider"
|
@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)
|
@cd $(ROOT_DIR)/stackit && go tool cover -html=../coverage.out -o ../coverage.html && cd $(ROOT_DIR)
|
||||||
|
|
||||||
test-acceptance-tf:
|
test-acceptance-tf:
|
||||||
@if [ -z $(TF_ACC_PROJECT_ID) ]; then echo "Input TF_ACC_PROJECT_ID missing"; exit 1; fi
|
@if [ -z $(TF_ACC_PROJECT_ID) ]; then echo "Input TF_ACC_PROJECT_ID missing"; exit 1; fi
|
||||||
|
|
|
||||||
19
README.md
19
README.md
|
|
@ -1,15 +1,14 @@
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<br>
|
|
||||||
<img src=".github/images/stackit-logo.svg" alt="STACKIT logo" width="50%"/>
|
<img src=".github/images/stackit-logo.svg" alt="STACKIT logo" width="50%"/>
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
# STACKIT Terraform Provider (PRIVATE PREVIEW)
|
# STACKIT Terraform Provider <br />(PRIVATE PREVIEW)
|
||||||
|
|
||||||
[](https://registry.terraform.io/providers/stackitcloud/stackit/latest)  [](https://www.apache.org/licenses/LICENSE-2.0)
|
[](https://registry.terraform.io/providers/stackitcloud/stackit/latest)  [](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
This project is the official [Terraform Provider](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs) for [STACKIT](https://www.stackit.de/en/), which allows you to manage STACKIT resources through Terraform.
|
This project is the **NOT** official [Terraform Provider](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs) for [STACKIT](https://www.stackit.de/en/)!
|
||||||
|
|
||||||
|
This a **private preview only**, which allows you to manage STACKIT resources through Terraform.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|
@ -18,20 +17,22 @@ To install the [STACKIT Terraform Provider](https://registry.terraform.io/provid
|
||||||
```hcl
|
```hcl
|
||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
stackit = {
|
stackitprivatepreview = {
|
||||||
source = "stackitcloud/stackit"
|
source = "tfregistry.sysops.stackit.rocks/mhenselin/stackitprivatepreview"
|
||||||
version = "X.X.X"
|
version = "= 0.0.5-alpha"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provider "stackit" {
|
provider "stackitprivatepreview" {
|
||||||
# Configuration options
|
# Configuration options
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Check one of the examples in the [examples](examples/) folder.
|
Check one of the examples in the [examples](examples/) folder.
|
||||||
|
|
||||||
|
<big font-size="3rem">TODO: revise the following sections</big>
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
To authenticate, you will need a [service account](https://docs.stackit.cloud/platform/access-and-identity/service-accounts/). Create it in the [STACKIT Portal](https://portal.stackit.cloud/) and assign the necessary permissions to it, e.g. `project.owner`. There are multiple ways to authenticate:
|
To authenticate, you will need a [service account](https://docs.stackit.cloud/platform/access-and-identity/service-accounts/). Create it in the [STACKIT Portal](https://portal.stackit.cloud/) and assign the necessary permissions to it, e.g. `project.owner`. There are multiple ways to authenticate:
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ const (
|
||||||
GEN_REPO = "https://github.com/stackitcloud/stackit-sdk-generator.git"
|
GEN_REPO = "https://github.com/stackitcloud/stackit-sdk-generator.git"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedVersions = []string{"alpha", "beta"}
|
|
||||||
|
|
||||||
type version struct {
|
type version struct {
|
||||||
verString string
|
verString string
|
||||||
major int
|
major int
|
||||||
|
|
@ -62,7 +60,7 @@ func (b *Builder) Build() error {
|
||||||
|
|
||||||
if !b.PackagesOnly {
|
if !b.PackagesOnly {
|
||||||
slog.Info(" ... Checking needed commands available")
|
slog.Info(" ... Checking needed commands available")
|
||||||
err := checkCommands([]string{"tfplugingen-framework", "tfplugingen-openapi"})
|
err := checkCommands([]string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +111,7 @@ func (b *Builder) Build() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Creating OAS dir")
|
slog.Info("Creating OAS dir")
|
||||||
err = os.MkdirAll(path.Join(genDir, "oas"), 0755)
|
err = os.MkdirAll(path.Join(genDir, "oas"), 0o755) //nolint:gosec // this dir is not sensitive, so we can use 0755
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +158,17 @@ func (b *Builder) Build() error {
|
||||||
if err = cmd.Wait(); err != nil {
|
if err = cmd.Wait(); err != nil {
|
||||||
var exitErr *exec.ExitError
|
var exitErr *exec.ExitError
|
||||||
if errors.As(err, &exitErr) {
|
if errors.As(err, &exitErr) {
|
||||||
slog.Error("cmd.Wait", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"cmd.Wait",
|
||||||
|
"code",
|
||||||
|
exitErr.ExitCode(),
|
||||||
|
"error",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -194,7 +202,11 @@ func (b *Builder) Build() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Rearranging package directories")
|
slog.Info("Rearranging package directories")
|
||||||
err = os.MkdirAll(path.Join(*root, "pkg_gen"), 0755) // noqa:gosec
|
//nolint:gosec // this dir is not sensitive, so we can use 0755
|
||||||
|
err = os.MkdirAll(
|
||||||
|
path.Join(*root, "pkg_gen"),
|
||||||
|
0o755,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -204,20 +216,21 @@ func (b *Builder) Build() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.IsDir() {
|
if !item.IsDir() {
|
||||||
slog.Info(" -> package", "name", item.Name())
|
continue
|
||||||
tgtDir := path.Join(*root, "pkg_gen", item.Name())
|
}
|
||||||
if fileExists(tgtDir) {
|
slog.Info(" -> package", "name", item.Name())
|
||||||
delErr := os.RemoveAll(tgtDir)
|
tgtDir := path.Join(*root, "pkg_gen", item.Name())
|
||||||
if delErr != nil {
|
if fileExists(tgtDir) {
|
||||||
return delErr
|
delErr := os.RemoveAll(tgtDir)
|
||||||
}
|
if delErr != nil {
|
||||||
}
|
return delErr
|
||||||
err = os.Rename(path.Join(srcDir, item.Name()), tgtDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err = os.Rename(path.Join(srcDir, item.Name()), tgtDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !b.PackagesOnly {
|
if !b.PackagesOnly {
|
||||||
|
|
@ -277,8 +290,8 @@ type templateData struct {
|
||||||
Fields []string
|
Fields []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileExists(path string) bool {
|
func fileExists(pathValue string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(pathValue)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -314,10 +327,22 @@ func createBoilerplate(rootFolder, folder string) error {
|
||||||
|
|
||||||
resourceName := res.Name()
|
resourceName := res.Name()
|
||||||
|
|
||||||
dsFile := path.Join(folder, svc.Name(), res.Name(), "datasources_gen", fmt.Sprintf("%s_data_source_gen.go", res.Name()))
|
dsFile := path.Join(
|
||||||
|
folder,
|
||||||
|
svc.Name(),
|
||||||
|
res.Name(),
|
||||||
|
"datasources_gen",
|
||||||
|
fmt.Sprintf("%s_data_source_gen.go", res.Name()),
|
||||||
|
)
|
||||||
handleDS = fileExists(dsFile)
|
handleDS = fileExists(dsFile)
|
||||||
|
|
||||||
resFile := path.Join(folder, svc.Name(), res.Name(), "resources_gen", fmt.Sprintf("%s_resource_gen.go", res.Name()))
|
resFile := path.Join(
|
||||||
|
folder,
|
||||||
|
svc.Name(),
|
||||||
|
res.Name(),
|
||||||
|
"resources_gen",
|
||||||
|
fmt.Sprintf("%s_resource_gen.go", res.Name()),
|
||||||
|
)
|
||||||
handleRes = fileExists(resFile)
|
handleRes = fileExists(resFile)
|
||||||
|
|
||||||
dsGoFile := path.Join(folder, svc.Name(), res.Name(), "datasource.go")
|
dsGoFile := path.Join(folder, svc.Name(), res.Name(), "datasource.go")
|
||||||
|
|
@ -409,7 +434,6 @@ func createBoilerplate(rootFolder, folder string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -418,7 +442,7 @@ func createBoilerplate(rootFolder, folder string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ucfirst(s string) string {
|
func ucfirst(s string) string {
|
||||||
if len(s) == 0 {
|
if s == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return strings.ToUpper(s[:1]) + s[1:]
|
return strings.ToUpper(s[:1]) + s[1:]
|
||||||
|
|
@ -453,8 +477,8 @@ func writeTemplateToFile(tplName, tplFile, outFile string, data *templateData) e
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServiceFiles(rootDir, generatorDir string) error {
|
func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
// slog.Info("Generating specs folder")
|
//nolint:gosec // this file is not sensitive, so we can use 0755
|
||||||
err := os.MkdirAll(path.Join(rootDir, "generated", "specs"), 0755)
|
err := os.MkdirAll(path.Join(rootDir, "generated", "specs"), 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -492,7 +516,6 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Checking spec", "name", spec.Name())
|
|
||||||
r := regexp.MustCompile(`^(.*)_config.yml$`)
|
r := regexp.MustCompile(`^(.*)_config.yml$`)
|
||||||
matches := r.FindAllStringSubmatch(specFile.Name(), -1)
|
matches := r.FindAllStringSubmatch(specFile.Name(), -1)
|
||||||
if matches != nil {
|
if matches != nil {
|
||||||
|
|
@ -508,27 +531,44 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
resource,
|
resource,
|
||||||
)
|
)
|
||||||
|
|
||||||
oasFile := path.Join(generatorDir, "oas", fmt.Sprintf("%s%s.json", service.Name(), svcVersion.Name()))
|
oasFile := path.Join(
|
||||||
|
generatorDir,
|
||||||
|
"oas",
|
||||||
|
fmt.Sprintf("%s%s.json", service.Name(), svcVersion.Name()),
|
||||||
|
)
|
||||||
if _, oasErr := os.Stat(oasFile); os.IsNotExist(oasErr) {
|
if _, oasErr := os.Stat(oasFile); os.IsNotExist(oasErr) {
|
||||||
slog.Warn(" could not find matching oas", "svc", service.Name(), "version", svcVersion.Name())
|
slog.Warn(
|
||||||
|
" could not find matching oas",
|
||||||
|
"svc",
|
||||||
|
service.Name(),
|
||||||
|
"version",
|
||||||
|
svcVersion.Name(),
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
scName := fmt.Sprintf("%s%s", service.Name(), svcVersion.Name())
|
scName := fmt.Sprintf("%s%s", service.Name(), svcVersion.Name())
|
||||||
scName = strings.ReplaceAll(scName, "-", "")
|
scName = strings.ReplaceAll(scName, "-", "")
|
||||||
err = os.MkdirAll(path.Join(rootDir, "generated", "internal", "services", scName, resource), 0755)
|
//nolint:gosec // this file is not sensitive, so we can use 0755
|
||||||
|
err = os.MkdirAll(path.Join(rootDir, "generated", "internal", "services", scName, resource), 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Generating openapi spec json")
|
specJsonFile := path.Join(
|
||||||
specJsonFile := path.Join(rootDir, "generated", "specs", fmt.Sprintf("%s_%s_spec.json", scName, resource))
|
rootDir,
|
||||||
|
"generated",
|
||||||
|
"specs",
|
||||||
|
fmt.Sprintf("%s_%s_spec.json", scName, resource),
|
||||||
|
)
|
||||||
|
|
||||||
var stdOut, stdErr bytes.Buffer
|
var stdOut, stdErr bytes.Buffer
|
||||||
|
|
||||||
// noqa:gosec
|
// nolint:gosec // #nosec this command is not using any untrusted input, so we can ignore gosec warning
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"tfplugingen-openapi",
|
"go",
|
||||||
|
"run",
|
||||||
|
"github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi",
|
||||||
"generate",
|
"generate",
|
||||||
"--config",
|
"--config",
|
||||||
path.Join(rootDir, "service_specs", service.Name(), svcVersion.Name(), fileName),
|
path.Join(rootDir, "service_specs", service.Name(), svcVersion.Name(), fileName),
|
||||||
|
|
@ -555,11 +595,29 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
if err = cmd.Wait(); err != nil {
|
if err = cmd.Wait(); err != nil {
|
||||||
var exitErr *exec.ExitError
|
var exitErr *exec.ExitError
|
||||||
if errors.As(err, &exitErr) {
|
if errors.As(err, &exitErr) {
|
||||||
slog.Error("tfplugingen-openapi generate", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-openapi generate",
|
||||||
|
"code",
|
||||||
|
exitErr.ExitCode(),
|
||||||
|
"error",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("tfplugingen-openapi generate", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-openapi generate",
|
||||||
|
"err",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -567,18 +625,26 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
slog.Warn(" command output", "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Warn(" command output", "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Creating terraform svc resource files folder")
|
tgtFolder := path.Join(
|
||||||
tgtFolder := path.Join(rootDir, "generated", "internal", "services", scName, resource, "resources_gen")
|
rootDir,
|
||||||
err = os.MkdirAll(tgtFolder, 0755)
|
"generated",
|
||||||
|
"internal",
|
||||||
|
"services",
|
||||||
|
scName,
|
||||||
|
resource,
|
||||||
|
"resources_gen",
|
||||||
|
)
|
||||||
|
//nolint:gosec // this file is not sensitive, so we can use 0755
|
||||||
|
err = os.MkdirAll(tgtFolder, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Generating terraform svc resource files")
|
// nolint:gosec // #nosec this command is not using any untrusted input, so we can ignore gosec warning
|
||||||
|
|
||||||
// noqa:gosec
|
|
||||||
cmd2 := exec.Command(
|
cmd2 := exec.Command(
|
||||||
"tfplugingen-framework",
|
"go",
|
||||||
|
"run",
|
||||||
|
"github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework",
|
||||||
"generate",
|
"generate",
|
||||||
"resources",
|
"resources",
|
||||||
"--input",
|
"--input",
|
||||||
|
|
@ -599,27 +665,53 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
if err = cmd2.Wait(); err != nil {
|
if err = cmd2.Wait(); err != nil {
|
||||||
var exitErr *exec.ExitError
|
var exitErr *exec.ExitError
|
||||||
if errors.As(err, &exitErr) {
|
if errors.As(err, &exitErr) {
|
||||||
slog.Error("tfplugingen-framework generate resources", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-framework generate resources",
|
||||||
|
"code",
|
||||||
|
exitErr.ExitCode(),
|
||||||
|
"error",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("tfplugingen-framework generate resources", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-framework generate resources",
|
||||||
|
"err",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Creating terraform svc datasource files folder")
|
tgtFolder = path.Join(
|
||||||
tgtFolder = path.Join(rootDir, "generated", "internal", "services", scName, resource, "datasources_gen")
|
rootDir,
|
||||||
err = os.MkdirAll(tgtFolder, 0755)
|
"generated",
|
||||||
|
"internal",
|
||||||
|
"services",
|
||||||
|
scName,
|
||||||
|
resource,
|
||||||
|
"datasources_gen",
|
||||||
|
)
|
||||||
|
//nolint:gosec // this directory is not sensitive, so we can use 0755
|
||||||
|
err = os.MkdirAll(tgtFolder, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// slog.Info("Generating terraform svc resource files")
|
// nolint:gosec // #nosec this command is not using any untrusted input, so we can ignore gosec warning
|
||||||
|
|
||||||
// noqa:gosec
|
|
||||||
cmd3 := exec.Command(
|
cmd3 := exec.Command(
|
||||||
"tfplugingen-framework",
|
"go",
|
||||||
|
"run",
|
||||||
|
"github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework",
|
||||||
"generate",
|
"generate",
|
||||||
"data-sources",
|
"data-sources",
|
||||||
"--input",
|
"--input",
|
||||||
|
|
@ -641,11 +733,29 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
if err = cmd3.Wait(); err != nil {
|
if err = cmd3.Wait(); err != nil {
|
||||||
var exitErr *exec.ExitError
|
var exitErr *exec.ExitError
|
||||||
if errors.As(err, &exitErr) {
|
if errors.As(err, &exitErr) {
|
||||||
slog.Error("tfplugingen-framework generate data-sources", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-framework generate data-sources",
|
||||||
|
"code",
|
||||||
|
exitErr.ExitCode(),
|
||||||
|
"error",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("tfplugingen-framework generate data-sources", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
slog.Error(
|
||||||
|
"tfplugingen-framework generate data-sources",
|
||||||
|
"err",
|
||||||
|
err,
|
||||||
|
"stdout",
|
||||||
|
stdOut.String(),
|
||||||
|
"stderr",
|
||||||
|
stdErr.String(),
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -676,10 +786,10 @@ func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
root, err := getRoot()
|
root, err := getRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
//nolint:gocritic // in this case, we want to log the error and exit, as we cannot proceed without the root directory
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -687,7 +797,6 @@ func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer tmp.Close()
|
|
||||||
|
|
||||||
sc := bufio.NewScanner(f)
|
sc := bufio.NewScanner(f)
|
||||||
for sc.Scan() {
|
for sc.Scan() {
|
||||||
|
|
@ -695,7 +804,7 @@ func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := io.WriteString(tmp, resLine+"\n"); err != nil {
|
if _, err := tmp.WriteString(resLine + "\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -711,6 +820,7 @@ func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:gosec // path traversal is not a concern here
|
||||||
if err := os.Rename(tmp.Name(), filePath); err != nil {
|
if err := os.Rename(tmp.Name(), filePath); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -775,13 +885,23 @@ func copyFile(src, dst string) (int64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer source.Close()
|
defer func(source *os.File) {
|
||||||
|
err := source.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("copyFile", "err", err)
|
||||||
|
}
|
||||||
|
}(source)
|
||||||
|
|
||||||
destination, err := os.Create(dst)
|
destination, err := os.Create(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer destination.Close()
|
defer func(destination *os.File) {
|
||||||
|
err := destination.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("copyFile", "err", err)
|
||||||
|
}
|
||||||
|
}(destination)
|
||||||
nBytes, err := io.Copy(destination, source)
|
nBytes, err := io.Copy(destination, source)
|
||||||
return nBytes, err
|
return nBytes, err
|
||||||
}
|
}
|
||||||
|
|
@ -792,10 +912,8 @@ func getOnlyLatest(m map[string]version) (map[string]version, error) {
|
||||||
item, ok := tmpMap[k]
|
item, ok := tmpMap[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
tmpMap[k] = v
|
tmpMap[k] = v
|
||||||
} else {
|
} else if item.major == v.major && item.minor < v.minor {
|
||||||
if item.major == v.major && item.minor < v.minor {
|
tmpMap[k] = v
|
||||||
tmpMap[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tmpMap, nil
|
return tmpMap, nil
|
||||||
|
|
@ -809,18 +927,19 @@ func getVersions(dir string) (map[string]version, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range children {
|
for _, entry := range children {
|
||||||
if entry.IsDir() {
|
if !entry.IsDir() {
|
||||||
versions, err := os.ReadDir(path.Join(dir, "services", entry.Name()))
|
continue
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
versions, err := os.ReadDir(path.Join(dir, "services", entry.Name()))
|
||||||
}
|
if err != nil {
|
||||||
m, err2 := extractVersions(entry.Name(), versions)
|
return nil, err
|
||||||
if err2 != nil {
|
}
|
||||||
return m, err2
|
m, err2 := extractVersions(entry.Name(), versions)
|
||||||
}
|
if err2 != nil {
|
||||||
for k, v := range m {
|
return m, err2
|
||||||
res[k] = v
|
}
|
||||||
}
|
for k, v := range m {
|
||||||
|
res[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
@ -829,20 +948,21 @@ func getVersions(dir string) (map[string]version, error) {
|
||||||
func extractVersions(service string, versionDirs []os.DirEntry) (map[string]version, error) {
|
func extractVersions(service string, versionDirs []os.DirEntry) (map[string]version, error) {
|
||||||
res := make(map[string]version)
|
res := make(map[string]version)
|
||||||
for _, vDir := range versionDirs {
|
for _, vDir := range versionDirs {
|
||||||
if vDir.IsDir() {
|
if !vDir.IsDir() {
|
||||||
r := regexp.MustCompile(`v([0-9]+)([a-z]+)([0-9]*)`)
|
continue
|
||||||
matches := r.FindAllStringSubmatch(vDir.Name(), -1)
|
}
|
||||||
if matches == nil {
|
r := regexp.MustCompile(`v(\d+)([a-z]+)(\d*)`)
|
||||||
continue
|
matches := r.FindAllStringSubmatch(vDir.Name(), -1)
|
||||||
}
|
if matches == nil {
|
||||||
svc, ver, err := handleVersion(service, matches[0])
|
continue
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
svc, ver, err := handleVersion(service, matches[0])
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if svc != nil && ver != nil {
|
if svc != nil && ver != nil {
|
||||||
res[*svc] = *ver
|
res[*svc] = *ver
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
@ -929,30 +1049,25 @@ func getTokens(fileName string) ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ast.Inspect(node, func(n ast.Node) bool {
|
ast.Inspect(
|
||||||
// Suche nach Typ-Deklarationen (structs)
|
node, func(n ast.Node) bool {
|
||||||
ts, ok := n.(*ast.TypeSpec)
|
// Suche nach Typ-Deklarationen (structs)
|
||||||
if ok {
|
ts, ok := n.(*ast.TypeSpec)
|
||||||
if strings.Contains(ts.Name.Name, "Model") {
|
if ok {
|
||||||
// fmt.Printf("found model: %s\n", ts.Name.Name)
|
if strings.Contains(ts.Name.Name, "Model") {
|
||||||
ast.Inspect(ts, func(sn ast.Node) bool {
|
ast.Inspect(
|
||||||
tts, tok := sn.(*ast.Field)
|
ts, func(sn ast.Node) bool {
|
||||||
if tok {
|
tts, tok := sn.(*ast.Field)
|
||||||
// fmt.Printf(" found: %+v\n", tts.Names[0])
|
if tok {
|
||||||
// spew.Dump(tts.Type)
|
result = append(result, tts.Names[0].String())
|
||||||
|
}
|
||||||
result = append(result, tts.Names[0].String())
|
return true
|
||||||
|
},
|
||||||
//fld, fldOk := tts.Type.(*ast.Ident)
|
)
|
||||||
//if fldOk {
|
}
|
||||||
// fmt.Printf("type: %+v\n", fld)
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
return true
|
||||||
return true
|
},
|
||||||
})
|
)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package build
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -74,14 +75,24 @@ func Copy(srcFile, dstFile string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer out.Close()
|
defer func(out *os.File) {
|
||||||
|
err := out.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("failed to close file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(out)
|
||||||
|
|
||||||
in, err := os.Open(srcFile)
|
in, err := os.Open(srcFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer in.Close()
|
defer func(in *os.File) {
|
||||||
|
err := in.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("error closing destination file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(in)
|
||||||
|
|
||||||
_, err = io.Copy(out, in)
|
_, err = io.Copy(out, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -39,17 +39,25 @@ type {{.NameCamel}}Resource struct{
|
||||||
providerData core.ProviderData
|
providerData core.ProviderData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resourceModel represents the Terraform resource state
|
||||||
|
type resourceModel = {{.PackageName}}.{{.NamePascal}}Model
|
||||||
|
|
||||||
type {{.NamePascal}}ResourceIdentityModel struct {
|
type {{.NamePascal}}ResourceIdentityModel struct {
|
||||||
ProjectID types.String `tfsdk:"project_id"`
|
ProjectID types.String `tfsdk:"project_id"`
|
||||||
Region types.String `tfsdk:"region"`
|
Region types.String `tfsdk:"region"`
|
||||||
{{.NamePascal}}ID types.String `tfsdk:"instance_id"`
|
|
||||||
// TODO: implement further needed parts
|
// TODO: implement further needed parts
|
||||||
|
{{.NamePascal}}ID types.String `tfsdk:"{{.NameSnake}}_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metadata defines terraform resource name
|
||||||
func (r *{{.NameCamel}}Resource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
func (r *{{.NameCamel}}Resource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||||
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed planModifiers.yaml
|
||||||
|
var modifiersFileByte []byte
|
||||||
|
|
||||||
|
// Schema loads the schema from generated files and adds plan modifiers
|
||||||
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
schema = {{.PackageName}}ResGen.{{.NamePascal}}ResourceSchema(ctx)
|
schema = {{.PackageName}}ResGen.{{.NamePascal}}ResourceSchema(ctx)
|
||||||
|
|
||||||
|
|
@ -67,6 +75,7 @@ func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.Schema
|
||||||
resp.Schema = schema
|
resp.Schema = schema
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IdentitySchema defines the identity schema
|
||||||
func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
|
func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
|
||||||
resp.IdentitySchema = identityschema.Schema{
|
resp.IdentitySchema = identityschema.Schema{
|
||||||
Attributes: map[string]identityschema.Attribute{
|
Attributes: map[string]identityschema.Attribute{
|
||||||
|
|
@ -79,11 +88,11 @@ func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.Identity
|
||||||
"instance_id": identityschema.StringAttribute{
|
"instance_id": identityschema.StringAttribute{
|
||||||
RequiredForImport: true, // can be defaulted by the provider configuration
|
RequiredForImport: true, // can be defaulted by the provider configuration
|
||||||
},
|
},
|
||||||
|
// TODO: implement remaining schema parts
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the resource.
|
// Configure adds the provider configured client to the resource.
|
||||||
func (r *{{.NameCamel}}Resource) Configure(
|
func (r *{{.NameCamel}}Resource) Configure(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|
@ -152,27 +161,12 @@ func (r *{{.NameCamel}}Resource) ModifyPlan(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var identityModel {{.NamePascal}}ResourceIdentityModel
|
|
||||||
identityModel.ProjectID = planModel.ProjectId
|
|
||||||
identityModel.Region = planModel.Region
|
|
||||||
if !planModel.{{.NamePascal}}Id.IsNull() && !planModel.{{.NamePascal}}Id.IsUnknown() {
|
|
||||||
identityModel.{{.NamePascal}}ID = planModel.{{.NamePascal}}Id
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identityModel)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed planModifiers.yaml
|
|
||||||
var modifiersFileByte []byte
|
|
||||||
|
|
||||||
// Create creates a new resource
|
// Create creates a new resource
|
||||||
func (r *{{.NameCamel}}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
func (r *{{.NameCamel}}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||||
var data {{.PackageName}}ResGen.{{.NamePascal}}Model
|
var data {{.PackageName}}ResGen.{{.NamePascal}}Model
|
||||||
|
|
@ -184,19 +178,13 @@ func (r *{{.NameCamel}}Resource) Create(ctx context.Context, req resource.Create
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData {{.NamePascal}}ResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := identityData.ProjectID.ValueString()
|
projectId := data.ProjectId.ValueString()
|
||||||
region := identityData.Region.ValueString()
|
region := data.Region.ValueString()
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
// TODO: add remaining fields
|
||||||
|
|
||||||
// TODO: Create API call logic
|
// TODO: Create API call logic
|
||||||
/*
|
/*
|
||||||
|
|
@ -320,7 +308,7 @@ func (r *{{.NameCamel}}Resource) Read(ctx context.Context, req resource.ReadRequ
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
||||||
// Todo: Read API call logic
|
// TODO: Read API call logic
|
||||||
|
|
||||||
// Save updated data into Terraform state
|
// Save updated data into Terraform state
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
@ -348,22 +336,26 @@ func (r *{{.NameCamel}}Resource) Update(ctx context.Context, req resource.Update
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData {{.NamePascal}}ResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := identityData.ProjectID.ValueString()
|
projectId := data.ProjectId.ValueString()
|
||||||
region := identityData.Region.ValueString()
|
region := data.Region.ValueString()
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
||||||
// Todo: Update API call logic
|
// TODO: Update API call logic
|
||||||
|
|
||||||
|
// TODO: Set data returned by API in identity
|
||||||
|
identity := {{.NamePascal}}ResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(projectId),
|
||||||
|
Region: types.StringValue(region),
|
||||||
|
// TODO: add missing values
|
||||||
|
{{.NamePascal}}ID: types.StringValue({{.NamePascal}}Id),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Save updated data into Terraform state
|
// Save updated data into Terraform state
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
@ -395,7 +387,7 @@ func (r *{{.NameCamel}}Resource) Delete(ctx context.Context, req resource.Delete
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
||||||
// Todo: Delete API call logic
|
// TODO: Delete API call logic
|
||||||
|
|
||||||
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} deleted")
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} deleted")
|
||||||
}
|
}
|
||||||
|
|
@ -409,7 +401,8 @@ func (r *{{.NameCamel}}Resource) ImportState(
|
||||||
) {
|
) {
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
// Todo: Import logic
|
// TODO: Import logic
|
||||||
|
// TODO: fix len and parts itself
|
||||||
if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" {
|
if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx, &resp.Diagnostics,
|
ctx, &resp.Diagnostics,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/build"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/build"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -15,7 +16,7 @@ var buildCmd = &cobra.Command{
|
||||||
Use: "build",
|
Use: "build",
|
||||||
Short: "Build the necessary boilerplate",
|
Short: "Build the necessary boilerplate",
|
||||||
Long: `...`,
|
Long: `...`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
b := build.Builder{
|
b := build.Builder{
|
||||||
SkipClone: skipClone,
|
SkipClone: skipClone,
|
||||||
SkipCleanup: skipCleanup,
|
SkipCleanup: skipCleanup,
|
||||||
|
|
@ -29,7 +30,7 @@ func NewBuildCmd() *cobra.Command {
|
||||||
return buildCmd
|
return buildCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { // nolint: gochecknoinits
|
func init() { //nolint:gochecknoinits // This is the standard way to set up Cobra commands
|
||||||
buildCmd.Flags().BoolVarP(&skipCleanup, "skip-clean", "c", false, "Skip cleanup steps")
|
buildCmd.Flags().BoolVarP(&skipCleanup, "skip-clean", "c", false, "Skip cleanup steps")
|
||||||
buildCmd.Flags().BoolVarP(&skipClone, "skip-clone", "g", false, "Skip cloning from git")
|
buildCmd.Flags().BoolVarP(&skipClone, "skip-clone", "g", false, "Skip cloning from git")
|
||||||
buildCmd.Flags().BoolVarP(&packagesOnly, "packages-only", "p", false, "Only generate packages")
|
buildCmd.Flags().BoolVarP(&packagesOnly, "packages-only", "p", false, "Only generate packages")
|
||||||
|
|
|
||||||
114
cmd/cmd/examplesCmd.go
Normal file
114
cmd/cmd/examplesCmd.go
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var examplesCmd = &cobra.Command{
|
||||||
|
Use: "examples",
|
||||||
|
Short: "create examples",
|
||||||
|
Long: `...`,
|
||||||
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
|
// filePathStr := "stackit/internal/services/postgresflexalpha/database/datasources_gen/database_data_source_gen.go"
|
||||||
|
//
|
||||||
|
// src, err := os.ReadFile(filePathStr)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// i := interp.New(
|
||||||
|
// interp.Options{
|
||||||
|
// GoPath: "/home/henselinm/.asdf/installs/golang/1.25.6/packages",
|
||||||
|
// BuildTags: nil,
|
||||||
|
// Stdin: nil,
|
||||||
|
// Stdout: nil,
|
||||||
|
// Stderr: nil,
|
||||||
|
// Args: nil,
|
||||||
|
// Env: nil,
|
||||||
|
// SourcecodeFilesystem: nil,
|
||||||
|
// Unrestricted: false,
|
||||||
|
// },
|
||||||
|
//)
|
||||||
|
// err = i.Use(i.Symbols("github.com/hashicorp/terraform-plugin-framework-validators"))
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
// err = i.Use(stdlib.Symbols)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
// _, err = i.Eval(string(src))
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// v, err := i.Eval("DatabaseDataSourceSchema")
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// bar := v.Interface().(func(string) string)
|
||||||
|
//
|
||||||
|
// r := bar("Kung")
|
||||||
|
// println(r)
|
||||||
|
//
|
||||||
|
// evalPath, err := i.EvalPath(filePathStr)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// fmt.Printf("%+v\n", evalPath)
|
||||||
|
|
||||||
|
// _, err = i.Eval(`import "fmt"`)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
// _, err = i.Eval(`func Hallo() { fmt.Println("Hi!") }`)
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
|
// v = i.Symbols("Hallo")
|
||||||
|
|
||||||
|
// fmt.Println(v)
|
||||||
|
return workServices()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func workServices() error {
|
||||||
|
startPath := path.Join("stackit", "internal", "services")
|
||||||
|
|
||||||
|
services, err := os.ReadDir(startPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range services {
|
||||||
|
if !entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resources, err := os.ReadDir(path.Join(startPath, entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, res := range resources {
|
||||||
|
if !res.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println("Gefunden:", startPath, "subdir", entry.Name(), "resource", res.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExamplesCmd() *cobra.Command {
|
||||||
|
return examplesCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// func init() { // nolint: gochecknoinits
|
||||||
|
// examplesCmd.Flags().BoolVarP(&example, "example", "e", false, "example")
|
||||||
|
//}
|
||||||
|
|
@ -24,7 +24,7 @@ var getFieldsCmd = &cobra.Command{
|
||||||
Use: "get-fields",
|
Use: "get-fields",
|
||||||
Short: "get fields from file",
|
Short: "get fields from file",
|
||||||
Long: `...`,
|
Long: `...`,
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
PreRunE: func(_ *cobra.Command, _ []string) error {
|
||||||
typeStr := "data_source"
|
typeStr := "data_source"
|
||||||
if resType != "resource" && resType != "datasource" {
|
if resType != "resource" && resType != "datasource" {
|
||||||
return fmt.Errorf("--type can only be resource or datasource")
|
return fmt.Errorf("--type can only be resource or datasource")
|
||||||
|
|
@ -75,14 +75,14 @@ var getFieldsCmd = &cobra.Command{
|
||||||
filePath = p
|
filePath = p
|
||||||
|
|
||||||
//// Enum check
|
//// Enum check
|
||||||
//switch format {
|
// switch format {
|
||||||
//case "json", "yaml":
|
// case "json", "yaml":
|
||||||
//default:
|
//default:
|
||||||
// return fmt.Errorf("invalid --format: %s (want json|yaml)", format)
|
// return fmt.Errorf("invalid --format: %s (want json|yaml)", format)
|
||||||
//}
|
//}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
return getFields(filePath)
|
return getFields(filePath)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -107,31 +107,26 @@ func getTokens(fileName string) ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ast.Inspect(node, func(n ast.Node) bool {
|
ast.Inspect(
|
||||||
// Suche nach Typ-Deklarationen (structs)
|
node, func(n ast.Node) bool {
|
||||||
ts, ok := n.(*ast.TypeSpec)
|
// Suche nach Typ-Deklarationen (structs)
|
||||||
if ok {
|
ts, ok := n.(*ast.TypeSpec)
|
||||||
if strings.Contains(ts.Name.Name, "Model") {
|
if ok {
|
||||||
// fmt.Printf("found model: %s\n", ts.Name.Name)
|
if strings.Contains(ts.Name.Name, "Model") {
|
||||||
ast.Inspect(ts, func(sn ast.Node) bool {
|
ast.Inspect(
|
||||||
tts, tok := sn.(*ast.Field)
|
ts, func(sn ast.Node) bool {
|
||||||
if tok {
|
tts, tok := sn.(*ast.Field)
|
||||||
// fmt.Printf(" found: %+v\n", tts.Names[0])
|
if tok {
|
||||||
// spew.Dump(tts.Type)
|
result = append(result, tts.Names[0].String())
|
||||||
|
}
|
||||||
result = append(result, tts.Names[0].String())
|
return true
|
||||||
|
},
|
||||||
//fld, fldOk := tts.Type.(*ast.Ident)
|
)
|
||||||
//if fldOk {
|
}
|
||||||
// fmt.Printf("type: %+v\n", fld)
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
return true
|
||||||
return true
|
},
|
||||||
})
|
)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,9 +134,15 @@ func NewGetFieldsCmd() *cobra.Command {
|
||||||
return getFieldsCmd
|
return getFieldsCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { // nolint: gochecknoinits
|
func init() { //nolint:gochecknoinits //this is the only way to add the command to the rootCmd
|
||||||
getFieldsCmd.Flags().StringVarP(&inFile, "infile", "i", "", "input filename incl path")
|
getFieldsCmd.Flags().StringVarP(&inFile, "infile", "i", "", "input filename incl path")
|
||||||
getFieldsCmd.Flags().StringVarP(&svcName, "service", "s", "", "service name")
|
getFieldsCmd.Flags().StringVarP(&svcName, "service", "s", "", "service name")
|
||||||
getFieldsCmd.Flags().StringVarP(&resName, "resource", "r", "", "resource name")
|
getFieldsCmd.Flags().StringVarP(&resName, "resource", "r", "", "resource name")
|
||||||
getFieldsCmd.Flags().StringVarP(&resType, "type", "t", "resource", "resource type (data-source or resource [default])")
|
getFieldsCmd.Flags().StringVarP(
|
||||||
|
&resType,
|
||||||
|
"type",
|
||||||
|
"t",
|
||||||
|
"resource",
|
||||||
|
"resource type (data-source or resource [default])",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,36 +35,27 @@ type GpgPublicKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) CreateArchitectureFiles() error {
|
func (p *Provider) CreateArchitectureFiles() error {
|
||||||
// var namespace, provider, distPath, repoName, version, gpgFingerprint, gpgPubKeyFile, domain string
|
|
||||||
|
|
||||||
log.Println("* Creating architecture files in target directories")
|
log.Println("* Creating architecture files in target directories")
|
||||||
|
|
||||||
// filename = terraform-provider-[provider]_0.0.1_darwin_amd64.zip - provider_name + version + target + architecture + .zip
|
|
||||||
// prefix := fmt.Sprintf("v1/providers/%s/%s/%s/", namespace, provider, version)
|
|
||||||
prefix := path.Join("v1", "providers", p.Namespace, p.Provider, p.Version)
|
prefix := path.Join("v1", "providers", p.Namespace, p.Provider, p.Version)
|
||||||
|
|
||||||
// pathPrefix := fmt.Sprintf("release/%s", prefix)
|
|
||||||
pathPrefix := path.Join("release", prefix)
|
pathPrefix := path.Join("release", prefix)
|
||||||
|
|
||||||
// urlPrefix := fmt.Sprintf("https://%s/%s", domain, prefix)
|
|
||||||
urlPrefix, err := url.JoinPath("https://", p.Domain, prefix)
|
urlPrefix, err := url.JoinPath("https://", p.Domain, prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating base url: %w", err)
|
return fmt.Errorf("error creating base url: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// download url = https://example.com/v1/providers/namespace/provider/0.0.1/download/terraform-provider_0.0.1_darwin_amd64.zip
|
|
||||||
downloadUrlPrefix, err := url.JoinPath(urlPrefix, "download")
|
downloadUrlPrefix, err := url.JoinPath(urlPrefix, "download")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error crearting download url: %w", err)
|
return fmt.Errorf("error crearting download url: %w", err)
|
||||||
}
|
}
|
||||||
downloadPathPrefix := path.Join(pathPrefix, "download")
|
downloadPathPrefix := path.Join(pathPrefix, "download")
|
||||||
|
|
||||||
// shasums url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS
|
|
||||||
shasumsUrl, err := url.JoinPath(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version))
|
shasumsUrl, err := url.JoinPath(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating shasums url: %w", err)
|
return fmt.Errorf("error creating shasums url: %w", err)
|
||||||
}
|
}
|
||||||
// shasums_signature_url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS.sig
|
|
||||||
shasumsSigUrl := shasumsUrl + ".sig"
|
shasumsSigUrl := shasumsUrl + ".sig"
|
||||||
|
|
||||||
gpgAsciiPub, err := p.ReadGpgFile()
|
gpgAsciiPub, err := p.ReadGpgFile()
|
||||||
|
|
@ -116,33 +107,6 @@ func (p *Provider) CreateArchitectureFiles() error {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// var architectureTemplate = []byte(fmt.Sprintf(`
|
|
||||||
//{
|
|
||||||
// "protocols": [
|
|
||||||
// "4.0",
|
|
||||||
// "5.1",
|
|
||||||
// "6.0"
|
|
||||||
// ],
|
|
||||||
// "os": "%s",
|
|
||||||
// "arch": "%s",
|
|
||||||
// "filename": "%s",
|
|
||||||
// "download_url": "%s",
|
|
||||||
// "shasums_url": "%s",
|
|
||||||
// "shasums_signature_url": "%s",
|
|
||||||
// "shasum": "%s",
|
|
||||||
// "signing_keys": {
|
|
||||||
// "gpg_public_keys": [
|
|
||||||
// {
|
|
||||||
// "key_id": "%s",
|
|
||||||
// "ascii_armor": "%s",
|
|
||||||
// "trust_signature": "",
|
|
||||||
// "source": "",
|
|
||||||
// "source_url": ""
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//`, target, arch, fileName, downloadUrl, shasumsUrl, shasumsSigUrl, shasum, gpgFingerprint, gpgAsciiPub))
|
|
||||||
|
|
||||||
log.Printf(" - Arch file: %s", archFileName)
|
log.Printf(" - Arch file: %s", archFileName)
|
||||||
|
|
||||||
|
|
@ -160,8 +124,12 @@ func WriteArchitectureFile(filePath string, arch Architecture) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error encoding data: %w", err)
|
return fmt.Errorf("error encoding data: %w", err)
|
||||||
}
|
}
|
||||||
|
//nolint:gosec // this file is not sensitive, so we can use os.ModePerm
|
||||||
err = os.WriteFile(filePath, jsonString, os.ModePerm)
|
err = os.WriteFile(
|
||||||
|
filePath,
|
||||||
|
jsonString,
|
||||||
|
os.ModePerm,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing data: %w", err)
|
return fmt.Errorf("error writing data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ func (p *Provider) createVersionsFile() error {
|
||||||
// Build the versions file...
|
// Build the versions file...
|
||||||
version := Version{
|
version := Version{
|
||||||
Version: p.Version,
|
Version: p.Version,
|
||||||
Protocols: []string{"5.1"},
|
Protocols: []string{"5.1", "6.1"},
|
||||||
Platforms: nil,
|
Platforms: nil,
|
||||||
}
|
}
|
||||||
for _, sum := range shasums {
|
for _, sum := range shasums {
|
||||||
|
|
@ -161,10 +161,12 @@ func (p *Provider) createVersionsFile() error {
|
||||||
target := fileNameSplit[2]
|
target := fileNameSplit[2]
|
||||||
arch := fileNameSplit[3]
|
arch := fileNameSplit[3]
|
||||||
|
|
||||||
version.Platforms = append(version.Platforms, Platform{
|
version.Platforms = append(
|
||||||
OS: target,
|
version.Platforms, Platform{
|
||||||
Arch: arch,
|
OS: target,
|
||||||
})
|
Arch: arch,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := Data{}
|
data := Data{}
|
||||||
|
|
@ -206,16 +208,19 @@ func (p *Provider) CreateWellKnown() error {
|
||||||
log.Println("* Creating .well-known directory")
|
log.Println("* Creating .well-known directory")
|
||||||
pathString := path.Join(p.RootPath, "release", ".well-known")
|
pathString := path.Join(p.RootPath, "release", ".well-known")
|
||||||
|
|
||||||
|
//nolint:gosec // this file is not sensitive, so we can use ModePerm
|
||||||
err := os.MkdirAll(pathString, os.ModePerm)
|
err := os.MkdirAll(pathString, os.ModePerm)
|
||||||
if err != nil && !errors.Is(err, fs.ErrExist) {
|
if err != nil && !errors.Is(err, fs.ErrExist) {
|
||||||
return fmt.Errorf("error creating '%s' dir: %w", pathString, err)
|
return fmt.Errorf("error creating '%s' dir: %w", pathString, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(" - Writing to .well-known/terraform.json file")
|
log.Println(" - Writing to .well-known/terraform.json file")
|
||||||
|
|
||||||
|
//nolint:gosec // this file is not sensitive, so we can use 0644
|
||||||
err = os.WriteFile(
|
err = os.WriteFile(
|
||||||
fmt.Sprintf("%s/terraform.json", pathString),
|
fmt.Sprintf("%s/terraform.json", pathString),
|
||||||
[]byte(`{"providers.v1": "/v1/providers/"}`),
|
[]byte(`{"providers.v1": "/v1/providers/"}`),
|
||||||
0644,
|
0o644,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -224,9 +229,10 @@ func (p *Provider) CreateWellKnown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDir(path string) error {
|
func CreateDir(pathValue string) error {
|
||||||
log.Printf("* Creating %s directory", path)
|
log.Printf("* Creating %s directory", pathValue)
|
||||||
err := os.MkdirAll(path, os.ModePerm)
|
//nolint:gosec // this file is not sensitive, so we can use ModePerm
|
||||||
|
err := os.MkdirAll(pathValue, os.ModePerm)
|
||||||
if errors.Is(err, fs.ErrExist) {
|
if errors.Is(err, fs.ErrExist) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -269,13 +275,23 @@ func CopyFile(src, dst string) (int64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer source.Close()
|
defer func(source *os.File) {
|
||||||
|
err := source.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("error closing source file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(source)
|
||||||
|
|
||||||
destination, err := os.Create(dst)
|
destination, err := os.Create(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer destination.Close()
|
defer func(destination *os.File) {
|
||||||
|
err := destination.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("error closing destination file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(destination)
|
||||||
nBytes, err := io.Copy(destination, source)
|
nBytes, err := io.Copy(destination, source)
|
||||||
return nBytes, err
|
return nBytes, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
cmd/cmd/publish/templates/Caddyfile
Normal file
38
cmd/cmd/publish/templates/Caddyfile
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
log {
|
||||||
|
level debug
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
filesystem tf s3 {
|
||||||
|
bucket "terraform-provider-privatepreview"
|
||||||
|
region eu01
|
||||||
|
endpoint https://object.storage.eu01.onstackit.cloud
|
||||||
|
use_path_style
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tfregistry.sysops.stackit.rocks {
|
||||||
|
encode zstd gzip
|
||||||
|
|
||||||
|
handle_path /docs/* {
|
||||||
|
root /srv/www
|
||||||
|
templates
|
||||||
|
|
||||||
|
@md {
|
||||||
|
file {path}
|
||||||
|
path *.md
|
||||||
|
}
|
||||||
|
|
||||||
|
rewrite @md /markdown.html
|
||||||
|
|
||||||
|
file_server {
|
||||||
|
browse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_server {
|
||||||
|
fs tf
|
||||||
|
browse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,16 +22,25 @@ type Platform struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
|
Id string `json:"id,omitempty"`
|
||||||
Versions []Version `json:"versions"`
|
Versions []Version `json:"versions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) WriteToFile(filePath string) error {
|
func (d *Data) WriteToFile(filePath string) error {
|
||||||
|
// TODO: make it variable
|
||||||
|
d.Id = "tfregistry.sysops.stackit.rocks/mhenselin/stackitprivatepreview"
|
||||||
|
|
||||||
jsonString, err := json.Marshal(d)
|
jsonString, err := json.Marshal(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error encoding data: %w", err)
|
return fmt.Errorf("error encoding data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(filePath, jsonString, os.ModePerm)
|
//nolint:gosec // this file is not sensitive, so we can use os.ModePerm
|
||||||
|
err = os.WriteFile(
|
||||||
|
filePath,
|
||||||
|
jsonString,
|
||||||
|
os.ModePerm,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing data: %w", err)
|
return fmt.Errorf("error writing data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +91,13 @@ func (d *Data) LoadFromUrl(uri string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(file.Name()) // Clean up
|
defer func(name string) {
|
||||||
|
//nolint:gosec // The file path is generated by os.CreateTemp and is not user-controllable
|
||||||
|
err := os.Remove(name)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("failed to remove temporary file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(file.Name()) // Clean up
|
||||||
|
|
||||||
err = DownloadFile(
|
err = DownloadFile(
|
||||||
u.String(),
|
u.String(),
|
||||||
|
|
@ -119,20 +134,30 @@ func (v *Version) AddProtocol(p string) error {
|
||||||
// DownloadFile will download a url and store it in local filepath.
|
// DownloadFile will download a url and store it in local filepath.
|
||||||
// It writes to the destination file as it downloads it, without
|
// It writes to the destination file as it downloads it, without
|
||||||
// loading the entire file into memory.
|
// loading the entire file into memory.
|
||||||
func DownloadFile(url string, filepath string) error {
|
func DownloadFile(urlValue, filepath string) error {
|
||||||
// Create the file
|
// Create the file
|
||||||
|
//nolint:gosec // path traversal is not a concern here, as the filepath is generated by us and not user input
|
||||||
out, err := os.Create(filepath)
|
out, err := os.Create(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer func(out *os.File) {
|
||||||
|
err := out.Close()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("failed to close file", slog.Any("err", err))
|
||||||
|
}
|
||||||
|
}(out)
|
||||||
|
|
||||||
// Get the data
|
// Get the data
|
||||||
resp, err := http.Get(url)
|
|
||||||
|
//nolint:gosec,bodyclose // this is a controlled URL, not user input
|
||||||
|
resp, err := http.Get(urlValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func(Body io.ReadCloser) {
|
||||||
|
_ = Body.Close()
|
||||||
|
}(resp.Body)
|
||||||
|
|
||||||
// Write the body to file
|
// Write the body to file
|
||||||
_, err = io.Copy(out, resp.Body)
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
publish2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/publish"
|
publish2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/publish"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -28,20 +29,32 @@ var publishCmd = &cobra.Command{
|
||||||
Use: "publish",
|
Use: "publish",
|
||||||
Short: "Publish terraform provider",
|
Short: "Publish terraform provider",
|
||||||
Long: `...`,
|
Long: `...`,
|
||||||
RunE: func(_ *cobra.Command, args []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
return publish()
|
return publish()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { // nolint: gochecknoinits
|
func init() { //nolint:gochecknoinits //this is the standard way to set up cobra commands
|
||||||
publishCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&domain, "domain", "d", "", "Domain for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&domain, "domain", "d", "", "Domain for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&providerName, "providerName", "p", "", "ProviderName for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&providerName, "providerName", "p", "", "ProviderName for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&distPath, "distPath", "x", "dist", "Dist Path for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&distPath, "distPath", "x", "dist", "Dist Path for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&repoName, "repoName", "r", "", "RepoName for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&repoName, "repoName", "r", "", "RepoName for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&version, "version", "v", "", "Version for the Terraform registry.")
|
publishCmd.Flags().StringVarP(&version, "version", "v", "", "Version for the Terraform registry.")
|
||||||
publishCmd.Flags().StringVarP(&gpgFingerprint, "gpgFingerprint", "f", "", "GPG Fingerprint for the Terraform registry.")
|
publishCmd.Flags().StringVarP(
|
||||||
publishCmd.Flags().StringVarP(&gpgPubKeyFile, "gpgPubKeyFile", "k", "", "GPG PubKey file name for the Terraform registry.")
|
&gpgFingerprint,
|
||||||
|
"gpgFingerprint",
|
||||||
|
"f",
|
||||||
|
"",
|
||||||
|
"GPG Fingerprint for the Terraform registry.",
|
||||||
|
)
|
||||||
|
publishCmd.Flags().StringVarP(
|
||||||
|
&gpgPubKeyFile,
|
||||||
|
"gpgPubKeyFile",
|
||||||
|
"k",
|
||||||
|
"",
|
||||||
|
"GPG PubKey file name for the Terraform registry.",
|
||||||
|
)
|
||||||
|
|
||||||
err := publishCmd.MarkFlagRequired("namespace")
|
err := publishCmd.MarkFlagRequired("namespace")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -104,6 +117,7 @@ func publish() error {
|
||||||
|
|
||||||
// Create release dir - only the contents of this need to be uploaded to S3
|
// Create release dir - only the contents of this need to be uploaded to S3
|
||||||
log.Printf("* Creating release directory")
|
log.Printf("* Creating release directory")
|
||||||
|
//nolint:gosec // this directory is not sensitive, so we can use 0750
|
||||||
err = os.MkdirAll(path.Join(p.RootPath, "release"), os.ModePerm)
|
err = os.MkdirAll(path.Join(p.RootPath, "release"), os.ModePerm)
|
||||||
if err != nil && !errors.Is(err, fs.ErrExist) {
|
if err != nil && !errors.Is(err, fs.ErrExist) {
|
||||||
return fmt.Errorf("error creating '%s' dir: %w", path.Join(p.RootPath, "release"), err)
|
return fmt.Errorf("error creating '%s' dir: %w", path.Join(p.RootPath, "release"), err)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/MatusOllah/slogcolor"
|
"github.com/SladkyCitron/slogcolor"
|
||||||
cc "github.com/ivanpirog/coloredcobra"
|
cc "github.com/ivanpirog/coloredcobra"
|
||||||
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ func main() {
|
||||||
cmd.NewBuildCmd(),
|
cmd.NewBuildCmd(),
|
||||||
cmd.NewPublishCmd(),
|
cmd.NewPublishCmd(),
|
||||||
cmd.NewGetFieldsCmd(),
|
cmd.NewGetFieldsCmd(),
|
||||||
|
cmd.NewExamplesCmd(),
|
||||||
)
|
)
|
||||||
|
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_database Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_database (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_postgresflexalpha_database" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `database_id` (Number) The ID of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`,`database_id`\".",
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
- `tf_original_api_id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_flavor Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_flavor (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_postgresflexalpha_flavor" "flavor" {
|
|
||||||
project_id = var.project_id
|
|
||||||
region = var.region
|
|
||||||
cpu = 4
|
|
||||||
ram = 16
|
|
||||||
node_type = "Single"
|
|
||||||
storage_class = "premium-perf2-stackit"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `cpu` (Number) The cpu count of the instance.
|
|
||||||
- `node_type` (String) defines the nodeType it can be either single or replica
|
|
||||||
- `project_id` (String) The cpu count of the instance.
|
|
||||||
- `ram` (Number) The memory of the instance in Gibibyte.
|
|
||||||
- `region` (String) The flavor description.
|
|
||||||
- `storage_class` (String) The memory of the instance in Gibibyte.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `description` (String) The flavor description.
|
|
||||||
- `flavor_id` (String) The flavor id of the instance flavor.
|
|
||||||
- `id` (String) The terraform id of the instance flavor.
|
|
||||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
|
||||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
|
||||||
- `storage_classes` (Attributes List) (see [below for nested schema](#nestedatt--storage_classes))
|
|
||||||
|
|
||||||
<a id="nestedatt--storage_classes"></a>
|
|
||||||
### Nested Schema for `storage_classes`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String)
|
|
||||||
- `max_io_per_sec` (Number)
|
|
||||||
- `max_through_in_mb` (Number)
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_flavors Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_flavors (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `page` (Number) Number of the page of items list to be returned.
|
|
||||||
- `size` (Number) Number of items to be returned on each page.
|
|
||||||
- `sort` (String) Sorting of the flavors to be returned on each page.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `flavors` (Attributes List) List of flavors available for the project. (see [below for nested schema](#nestedatt--flavors))
|
|
||||||
- `pagination` (Attributes) (see [below for nested schema](#nestedatt--pagination))
|
|
||||||
|
|
||||||
<a id="nestedatt--flavors"></a>
|
|
||||||
### Nested Schema for `flavors`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `cpu` (Number) The cpu count of the instance.
|
|
||||||
- `description` (String) The flavor description.
|
|
||||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
|
||||||
- `memory` (Number) The memory of the instance in Gibibyte.
|
|
||||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
|
||||||
- `node_type` (String) defines the nodeType it can be either single or replica
|
|
||||||
- `storage_classes` (Attributes List) maximum storage which can be ordered for the flavor in Gigabyte. (see [below for nested schema](#nestedatt--flavors--storage_classes))
|
|
||||||
- `tf_original_api_id` (String) The id of the instance flavor.
|
|
||||||
|
|
||||||
<a id="nestedatt--flavors--storage_classes"></a>
|
|
||||||
### Nested Schema for `flavors.storage_classes`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String)
|
|
||||||
- `max_io_per_sec` (Number)
|
|
||||||
- `max_through_in_mb` (Number)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--pagination"></a>
|
|
||||||
### Nested Schema for `pagination`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `page` (Number)
|
|
||||||
- `size` (Number)
|
|
||||||
- `sort` (String)
|
|
||||||
- `total_pages` (Number)
|
|
||||||
- `total_rows` (Number)
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_instance Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_instance (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `connection_info` (Attributes) The DNS name and port in the instance overview (see [below for nested schema](#nestedatt--connection_info))
|
|
||||||
- `encryption` (Attributes) The configuration for instance's volume and backup storage encryption.
|
|
||||||
|
|
||||||
⚠︝ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `retention_days` (Number) How long backups are retained. The value can only be between 32 and 365 days.
|
|
||||||
- `status` (String) The current status of the instance.
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `tf_original_api_id` (String) The ID of the instance.
|
|
||||||
- `version` (String) The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.
|
|
||||||
|
|
||||||
<a id="nestedatt--connection_info"></a>
|
|
||||||
### Nested Schema for `connection_info`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `host` (String) The host of the instance.
|
|
||||||
- `port` (Number) The port of the instance.
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The encryption-key key identifier
|
|
||||||
- `kek_key_ring_id` (String) The encryption-key keyring identifier
|
|
||||||
- `kek_key_version` (String) The encryption-key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `access_scope` (String) The access scope of the instance. It defines if the instance is public or airgapped.
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `performance_class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_user Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_user (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_postgresflexalpha_user" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
- `user_id` (Number) The ID of the user.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`,`user_id`\".",
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `name` (String) The name of the user.
|
|
||||||
- `roles` (List of String) A list of user roles.
|
|
||||||
- `status` (String) The current status of the user.
|
|
||||||
- `tf_original_api_id` (Number) The ID of the user.
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_database Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_database (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `database_name` (String) The name of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`,`database_id`\".",
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
- `tf_original_api_id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_flavor Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_flavor (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexalpha_flavor" "flavor" {
|
|
||||||
project_id = var.project_id
|
|
||||||
region = var.region
|
|
||||||
cpu = 4
|
|
||||||
ram = 16
|
|
||||||
node_type = "Single"
|
|
||||||
storage_class = "premium-perf2-stackit"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `cpu` (Number) The cpu count of the instance.
|
|
||||||
- `node_type` (String) defines the nodeType it can be either single or replica
|
|
||||||
- `project_id` (String) The cpu count of the instance.
|
|
||||||
- `ram` (Number) The memory of the instance in Gibibyte.
|
|
||||||
- `region` (String) The flavor description.
|
|
||||||
- `storage_class` (String) The memory of the instance in Gibibyte.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `description` (String) The flavor description.
|
|
||||||
- `flavor_id` (String) The flavor id of the instance flavor.
|
|
||||||
- `id` (String) The terraform id of the instance flavor.
|
|
||||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
|
||||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
|
||||||
- `storage_classes` (Attributes List) (see [below for nested schema](#nestedatt--storage_classes))
|
|
||||||
|
|
||||||
<a id="nestedatt--storage_classes"></a>
|
|
||||||
### Nested Schema for `storage_classes`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String)
|
|
||||||
- `max_io_per_sec` (Number)
|
|
||||||
- `max_through_in_mb` (Number)
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_instance (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexalpha_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`\".
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
|
||||||
- `status` (String)
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `tf_original_api_id` (String) The ID of the instance.
|
|
||||||
- `version` (String) The sqlserver version used for the instance.
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
|
||||||
- `kek_key_version` (String) The key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `access_scope` (String) The network access scope of the instance
|
|
||||||
|
|
||||||
⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_user Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
SQLServer Flex user data source schema. Must have a region specified in the provider configuration.
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_user (Data Source)
|
|
||||||
|
|
||||||
SQLServer Flex user data source schema. Must have a `region` specified in the provider configuration.
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexalpha_user" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) ID of the SQLServer Flex instance.
|
|
||||||
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
|
||||||
- `user_id` (Number) User ID.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `region` (String) The resource region. If not defined, the provider region is used.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `default_database` (String)
|
|
||||||
- `host` (String)
|
|
||||||
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
|
|
||||||
- `port` (Number)
|
|
||||||
- `roles` (Set of String) Database access levels for the user.
|
|
||||||
- `status` (String)
|
|
||||||
- `username` (String) Username of the SQLServer Flex instance.
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_database Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_database (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexbeta_database" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
database_name = "dbname"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `database_name` (String) The name of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `id` (String) The terraform internal identifier.
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
- `tf_original_api_id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_flavor Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_flavor (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexbeta_flavor" "flavor" {
|
|
||||||
project_id = var.project_id
|
|
||||||
region = var.region
|
|
||||||
cpu = 4
|
|
||||||
ram = 16
|
|
||||||
node_type = "Single"
|
|
||||||
storage_class = "premium-perf2-stackit"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `cpu` (Number) The cpu count of the instance.
|
|
||||||
- `node_type` (String) defines the nodeType it can be either single or HA
|
|
||||||
- `project_id` (String) The project ID of the flavor.
|
|
||||||
- `ram` (Number) The memory of the instance in Gibibyte.
|
|
||||||
- `region` (String) The region of the flavor.
|
|
||||||
- `storage_class` (String) The memory of the instance in Gibibyte.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `description` (String) The flavor description.
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `id` (String) The id of the instance flavor.
|
|
||||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
|
||||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
|
||||||
- `storage_classes` (Attributes List) maximum storage which can be ordered for the flavor in Gigabyte. (see [below for nested schema](#nestedatt--storage_classes))
|
|
||||||
|
|
||||||
<a id="nestedatt--storage_classes"></a>
|
|
||||||
### Nested Schema for `storage_classes`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String)
|
|
||||||
- `max_io_per_sec` (Number)
|
|
||||||
- `max_through_in_mb` (Number)
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_instance Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_instance (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
data "stackitprivatepreview_sqlserverflexbeta_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
|
||||||
- `status` (String)
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `tf_original_api_id` (String) The ID of the instance.
|
|
||||||
- `version` (String) The sqlserver version used for the instance.
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
|
||||||
- `kek_key_version` (String) The key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `access_scope` (String) The network access scope of the instance
|
|
||||||
|
|
||||||
⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview Provider"
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview Provider
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
}
|
|
||||||
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
service_account_key_path = "service_account.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Authentication
|
|
||||||
|
|
||||||
# Key flow
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
service_account_key = var.service_account_key
|
|
||||||
private_key = var.private_key
|
|
||||||
}
|
|
||||||
|
|
||||||
# Key flow (using path)
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
service_account_key_path = var.service_account_key_path
|
|
||||||
private_key_path = var.private_key_path
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `authorization_custom_endpoint` (String) Custom endpoint for the Membership service
|
|
||||||
- `cdn_custom_endpoint` (String) Custom endpoint for the CDN service
|
|
||||||
- `credentials_path` (String) Path of JSON from where the credentials are read. Takes precedence over the env var `STACKIT_CREDENTIALS_PATH`. Default value is `~/.stackit/credentials.json`.
|
|
||||||
- `default_region` (String) Region will be used as the default location for regional services. Not all services require a region, some are global
|
|
||||||
- `dns_custom_endpoint` (String) Custom endpoint for the DNS service
|
|
||||||
- `enable_beta_resources` (Boolean) Enable beta resources. Default is false.
|
|
||||||
- `experiments` (List of String) Enables experiments. These are unstable features without official support. More information can be found in the README. Available Experiments: iam, routing-tables, network
|
|
||||||
- `git_custom_endpoint` (String) Custom endpoint for the Git service
|
|
||||||
- `iaas_custom_endpoint` (String) Custom endpoint for the IaaS service
|
|
||||||
- `kms_custom_endpoint` (String) Custom endpoint for the KMS service
|
|
||||||
- `loadbalancer_custom_endpoint` (String) Custom endpoint for the Load Balancer service
|
|
||||||
- `logme_custom_endpoint` (String) Custom endpoint for the LogMe service
|
|
||||||
- `mariadb_custom_endpoint` (String) Custom endpoint for the MariaDB service
|
|
||||||
- `modelserving_custom_endpoint` (String) Custom endpoint for the AI Model Serving service
|
|
||||||
- `mongodbflex_custom_endpoint` (String) Custom endpoint for the MongoDB Flex service
|
|
||||||
- `objectstorage_custom_endpoint` (String) Custom endpoint for the Object Storage service
|
|
||||||
- `observability_custom_endpoint` (String) Custom endpoint for the Observability service
|
|
||||||
- `opensearch_custom_endpoint` (String) Custom endpoint for the OpenSearch service
|
|
||||||
- `postgresflex_custom_endpoint` (String) Custom endpoint for the PostgresFlex service
|
|
||||||
- `private_key` (String) Private RSA key used for authentication, relevant for the key flow. It takes precedence over the private key that is included in the service account key.
|
|
||||||
- `private_key_path` (String) Path for the private RSA key used for authentication, relevant for the key flow. It takes precedence over the private key that is included in the service account key.
|
|
||||||
- `rabbitmq_custom_endpoint` (String) Custom endpoint for the RabbitMQ service
|
|
||||||
- `redis_custom_endpoint` (String) Custom endpoint for the Redis service
|
|
||||||
- `region` (String, Deprecated) Region will be used as the default location for regional services. Not all services require a region, some are global
|
|
||||||
- `resourcemanager_custom_endpoint` (String) Custom endpoint for the Resource Manager service
|
|
||||||
- `scf_custom_endpoint` (String) Custom endpoint for the Cloud Foundry (SCF) service
|
|
||||||
- `secretsmanager_custom_endpoint` (String) Custom endpoint for the Secrets Manager service
|
|
||||||
- `server_backup_custom_endpoint` (String) Custom endpoint for the Server Backup service
|
|
||||||
- `server_update_custom_endpoint` (String) Custom endpoint for the Server Update service
|
|
||||||
- `service_account_custom_endpoint` (String) Custom endpoint for the Service Account service
|
|
||||||
- `service_account_email` (String, Deprecated) Service account email. It can also be set using the environment variable STACKIT_SERVICE_ACCOUNT_EMAIL. It is required if you want to use the resource manager project resource.
|
|
||||||
- `service_account_key` (String) Service account key used for authentication. If set, the key flow will be used to authenticate all operations.
|
|
||||||
- `service_account_key_path` (String) Path for the service account key used for authentication. If set, the key flow will be used to authenticate all operations.
|
|
||||||
- `service_account_token` (String, Deprecated) Token used for authentication. If set, the token flow will be used to authenticate all operations.
|
|
||||||
- `service_enablement_custom_endpoint` (String) Custom endpoint for the Service Enablement API
|
|
||||||
- `ske_custom_endpoint` (String) Custom endpoint for the Kubernetes Engine (SKE) service
|
|
||||||
- `sqlserverflex_custom_endpoint` (String) Custom endpoint for the SQL Server Flex service
|
|
||||||
- `token_custom_endpoint` (String) Custom endpoint for the token API, which is used to request access tokens when using the key flow
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_database Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_database (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_database" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "mydb"
|
|
||||||
owner = "myusername"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing postgresflex database
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_postgresflexalpha_database.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.postgres_database_id}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `database_id` (Number) The ID of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,131 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_instance Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_instance (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
backup_schedule = "0 0 * * *"
|
|
||||||
retention_days = 30
|
|
||||||
flavor_id = "flavor.id"
|
|
||||||
replicas = 1
|
|
||||||
storage = {
|
|
||||||
performance_class = "premium-perf2-stackit"
|
|
||||||
size = 10
|
|
||||||
}
|
|
||||||
encryption = {
|
|
||||||
kek_key_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
kek_key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
kek_key_version = 1
|
|
||||||
service_account = "service@account.email"
|
|
||||||
}
|
|
||||||
network = {
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
access_scope = "PUBLIC"
|
|
||||||
}
|
|
||||||
version = 17
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing postgresflex instance
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
|
||||||
identity = {
|
|
||||||
project_id = var.project_id
|
|
||||||
region = var.region
|
|
||||||
instance_id = var.postgres_instance_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `retention_days` (Number) How long backups are retained. The value can only be between 32 and 365 days.
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `version` (String) The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `encryption` (Attributes) The configuration for instance's volume and backup storage encryption.
|
|
||||||
|
|
||||||
⚠︝ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
- `connection_info` (Attributes) The DNS name and port in the instance overview (see [below for nested schema](#nestedatt--connection_info))
|
|
||||||
- `id` (String) The ID of the instance.
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `status` (String) The current status of the instance.
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
|
|
||||||
Optional:
|
|
||||||
|
|
||||||
- `access_scope` (String) The access scope of the instance. It defines if the instance is public or airgapped.
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `performance_class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The encryption-key key identifier
|
|
||||||
- `kek_key_ring_id` (String) The encryption-key keyring identifier
|
|
||||||
- `kek_key_version` (String) The encryption-key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--connection_info"></a>
|
|
||||||
### Nested Schema for `connection_info`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `host` (String) The host of the instance.
|
|
||||||
- `port` (Number) The port of the instance.
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_user Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_user (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_user" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
username = "username"
|
|
||||||
roles = ["role"]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing postgresflex user
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_postgresflexalpha_user.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.user_id}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `name` (String) The name of the user.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
- `roles` (List of String) A list containing the user roles for the instance.
|
|
||||||
- `user_id` (Number) The ID of the user.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `connection_string` (String) The connection string for the user to the instance.
|
|
||||||
- `id` (Number) The ID of the user.
|
|
||||||
- `password` (String) The password for the user.
|
|
||||||
- `status` (String) The current status of the user.
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_database Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_database (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `collation` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `database_name` (String) The name of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_instance (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackitprivatepreview_sqlserverflexalpha_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
backup_schedule = "00 00 * * *"
|
|
||||||
flavor = {
|
|
||||||
cpu = 4
|
|
||||||
ram = 16
|
|
||||||
}
|
|
||||||
storage = {
|
|
||||||
class = "class"
|
|
||||||
size = 5
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing sqlserverflex instance
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_sqlserverflexalpha_instance.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.sql_instance_id}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) the network configuration of the instance. (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `version` (String) The sqlserver version used for the instance.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
|
||||||
- `id` (String) The ID of the instance.
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `status` (String)
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
|
|
||||||
Optional:
|
|
||||||
|
|
||||||
- `access_scope` (String) The network access scope of the instance
|
|
||||||
|
|
||||||
⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
|
||||||
- `kek_key_version` (String) The key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_user Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_user (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
resource "stackitprivatepreview_sqlserverflexalpha_user" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
username = "username"
|
|
||||||
roles = ["role"]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing sqlserverflex user
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_sqlserverflexalpha_user.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `roles` (List of String) A list containing the user roles for the instance.
|
|
||||||
- `username` (String) The name of the user.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `default_database` (String) The default database for a user of the instance.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
- `user_id` (Number) The ID of the user.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `host` (String) The host of the instance in which the user belongs to.
|
|
||||||
- `id` (Number) The ID of the user.
|
|
||||||
- `password` (String) The password for the user.
|
|
||||||
- `port` (Number) The port of the instance in which the user belongs to.
|
|
||||||
- `status` (String) The current status of the user.
|
|
||||||
- `uri` (String) The connection string for the user to the instance.
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_database Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_database (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `name` (String) The name of the database.
|
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `collation` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `database_name` (String) The name of the database.
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
|
||||||
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
|
||||||
- `id` (Number) The id of the database.
|
|
||||||
|
|
@ -1,158 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_instance Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_instance (Resource)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
# without encryption and SNA
|
|
||||||
resource "stackitprivatepreview_sqlserverflexbeta_instance" "instance" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
backup_schedule = "0 3 * * *"
|
|
||||||
retention_days = 31
|
|
||||||
flavor_id = "flavor_id"
|
|
||||||
storage = {
|
|
||||||
class = "premium-perf2-stackit"
|
|
||||||
size = 50
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
network = {
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
access_scope = "SNA"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# without encryption and PUBLIC
|
|
||||||
resource "stackitprivatepreview_sqlserverflexbeta_instance" "instance" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
backup_schedule = "0 3 * * *"
|
|
||||||
retention_days = 31
|
|
||||||
flavor_id = "flavor_id"
|
|
||||||
storage = {
|
|
||||||
class = "premium-perf2-stackit"
|
|
||||||
size = 50
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
network = {
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
access_scope = "PUBLIC"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# with encryption and SNA
|
|
||||||
resource "stackitprivatepreview_sqlserverflexbeta_instance" "instance" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
name = "example-instance"
|
|
||||||
backup_schedule = "0 3 * * *"
|
|
||||||
retention_days = 31
|
|
||||||
flavor_id = "flavor_id"
|
|
||||||
storage = {
|
|
||||||
class = "premium-perf2-stackit"
|
|
||||||
size = 50
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
encryption = {
|
|
||||||
kek_key_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
kek_key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
kek_key_version = 1
|
|
||||||
service_account = "service_account@email"
|
|
||||||
}
|
|
||||||
network = {
|
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
access_scope = "SNA"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Only use the import statement, if you want to import an existing sqlserverflex instance
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_sqlserverflexalpha_instance.import-example
|
|
||||||
id = "${var.project_id},${var.region},${var.sql_instance_id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# import with identity
|
|
||||||
import {
|
|
||||||
to = stackitprivatepreview_sqlserverflexalpha_instance.import-example
|
|
||||||
identity = {
|
|
||||||
project_id = var.project_id
|
|
||||||
region = var.region
|
|
||||||
instance_id = var.sql_instance_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
|
||||||
## Schema
|
|
||||||
|
|
||||||
### Required
|
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
|
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
|
||||||
- `name` (String) The name of the instance.
|
|
||||||
- `network` (Attributes) the network configuration of the instance. (see [below for nested schema](#nestedatt--network))
|
|
||||||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
|
||||||
- `version` (String) The sqlserver version used for the instance.
|
|
||||||
|
|
||||||
### Optional
|
|
||||||
|
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
|
||||||
- `id` (String) The ID of the instance.
|
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
|
||||||
- `status` (String)
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
|
||||||
### Nested Schema for `network`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
|
||||||
|
|
||||||
Optional:
|
|
||||||
|
|
||||||
- `access_scope` (String) The network access scope of the instance
|
|
||||||
|
|
||||||
⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
|
||||||
### Nested Schema for `storage`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `class` (String) The storage class for the storage.
|
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
|
||||||
### Nested Schema for `encryption`
|
|
||||||
|
|
||||||
Required:
|
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
|
||||||
- `kek_key_version` (String) The key version
|
|
||||||
- `service_account` (String)
|
|
||||||
|
|
@ -9,4 +9,14 @@ resource "stackitprivatepreview_postgresflexalpha_database" "example" {
|
||||||
import {
|
import {
|
||||||
to = stackitprivatepreview_postgresflexalpha_database.import-example
|
to = stackitprivatepreview_postgresflexalpha_database.import-example
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.postgres_database_id}"
|
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.postgres_database_id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_postgresflexalpha_database.import-example
|
||||||
|
identity = {
|
||||||
|
project_id = "project_id"
|
||||||
|
region = "region"
|
||||||
|
instance_id = "instance_id"
|
||||||
|
database_id = "database_id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
resource "stackitprivatepreview_postgresflexalpha_instance" "example-instance" {
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
name = "example-instance"
|
name = "example-instance"
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
||||||
|
|
@ -17,7 +17,7 @@ resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only"
|
||||||
service_account = "service@account.email"
|
service_account = "service@account.email"
|
||||||
}
|
}
|
||||||
network = {
|
network = {
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
||||||
access_scope = "PUBLIC"
|
access_scope = "PUBLIC"
|
||||||
}
|
}
|
||||||
version = 17
|
version = 17
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
resource "stackitprivatepreview_postgresflexalpha_user" "example" {
|
resource "stackitprivatepreview_postgresflexalpha_user" "example" {
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
username = "username"
|
name = "username"
|
||||||
roles = ["role"]
|
roles = ["role"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -9,4 +9,14 @@ resource "stackitprivatepreview_postgresflexalpha_user" "example" {
|
||||||
import {
|
import {
|
||||||
to = stackitprivatepreview_postgresflexalpha_user.import-example
|
to = stackitprivatepreview_postgresflexalpha_user.import-example
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.user_id}"
|
id = "${var.project_id},${var.region},${var.postgres_instance_id},${var.user_id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_postgresflexalpha_user.import-example
|
||||||
|
identity = {
|
||||||
|
project_id = "project.id"
|
||||||
|
region = "region"
|
||||||
|
instance_id = "instance.id"
|
||||||
|
user_id = "user.id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
resource "stackitprivatepreview_sqlserverflexalpha_database" "example" {
|
||||||
|
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
collation = ""
|
||||||
|
compatibility = "160"
|
||||||
|
name = ""
|
||||||
|
owner = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Only use the import statement, if you want to import a existing sqlserverflex database
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_sqlserverflexalpha_database.import-example
|
||||||
|
id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_sqlserverflexalpha_database.import-example
|
||||||
|
identity = {
|
||||||
|
project_id = "project.id"
|
||||||
|
region = "region"
|
||||||
|
instance_id = "instance.id"
|
||||||
|
database_id = "database.id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
resource "stackitprivatepreview_sqlserverflexalpha_user" "example" {
|
||||||
|
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
username = "username"
|
||||||
|
roles = ["role"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Only use the import statement, if you want to import an existing sqlserverflex user
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_sqlserverflexalpha_user.import-example
|
||||||
|
id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
resource "stackitprivatepreview_sqlserverflexalpha_user" "example" {
|
||||||
|
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||||
|
username = "username"
|
||||||
|
roles = ["role"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Only use the import statement, if you want to import an existing sqlserverflex user
|
||||||
|
import {
|
||||||
|
to = stackitprivatepreview_sqlserverflexalpha_user.import-example
|
||||||
|
id = "${var.project_id},${var.region},${var.sql_instance_id},${var.sql_user_id}"
|
||||||
|
}
|
||||||
261
go.mod
261
go.mod
|
|
@ -2,10 +2,17 @@ module tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stac
|
||||||
|
|
||||||
go 1.25.6
|
go 1.25.6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/MatusOllah/slogcolor v1.7.0
|
github.com/SladkyCitron/slogcolor v1.8.0
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.3.1
|
||||||
|
github.com/golangci/golangci-lint/v2 v2.10.1
|
||||||
github.com/google/go-cmp v0.7.0
|
github.com/google/go-cmp v0.7.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/hashicorp/terraform-plugin-codegen-framework v0.4.1
|
||||||
|
github.com/hashicorp/terraform-plugin-codegen-openapi v0.3.0
|
||||||
|
github.com/hashicorp/terraform-plugin-docs v0.24.0
|
||||||
github.com/hashicorp/terraform-plugin-framework v1.17.0
|
github.com/hashicorp/terraform-plugin-framework v1.17.0
|
||||||
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
|
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
|
||||||
github.com/hashicorp/terraform-plugin-go v0.29.0
|
github.com/hashicorp/terraform-plugin-go v0.29.0
|
||||||
|
|
@ -13,75 +20,283 @@ require (
|
||||||
github.com/hashicorp/terraform-plugin-testing v1.14.0
|
github.com/hashicorp/terraform-plugin-testing v1.14.0
|
||||||
github.com/iancoleman/strcase v0.3.0
|
github.com/iancoleman/strcase v0.3.0
|
||||||
github.com/ivanpirog/coloredcobra v1.0.1
|
github.com/ivanpirog/coloredcobra v1.0.1
|
||||||
|
github.com/jarcoal/httpmock v1.4.1
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/ldez/go-git-cmd-wrapper/v2 v2.9.1
|
github.com/ldez/go-git-cmd-wrapper/v2 v2.9.1
|
||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/stackitcloud/stackit-sdk-go/core v0.21.0
|
github.com/stackitcloud/stackit-sdk-go/core v0.21.1
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.23-alpha
|
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.23-alpha
|
||||||
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.4.1
|
|
||||||
github.com/teambition/rrule-go v1.8.2
|
github.com/teambition/rrule-go v1.8.2
|
||||||
|
golang.org/x/tools v0.42.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
|
|
||||||
golang.org/x/telemetry v0.0.0-20260116145544-c6413dc483f5 // indirect
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
|
||||||
|
4d63.com/gochecknoglobals v0.2.2 // indirect
|
||||||
|
codeberg.org/chavacava/garif v0.2.0 // indirect
|
||||||
|
codeberg.org/polyfloyd/go-errorlint v1.9.0 // indirect
|
||||||
dario.cat/mergo v1.0.1 // indirect
|
dario.cat/mergo v1.0.1 // indirect
|
||||||
|
dev.gaijin.team/go/exhaustruct/v4 v4.0.0 // indirect
|
||||||
|
dev.gaijin.team/go/golib v0.6.0 // indirect
|
||||||
|
github.com/4meepo/tagalign v1.4.3 // indirect
|
||||||
|
github.com/Abirdcfly/dupword v0.1.7 // indirect
|
||||||
|
github.com/AdminBenni/iota-mixing v1.0.0 // indirect
|
||||||
|
github.com/AlwxSin/noinlineerr v1.0.5 // indirect
|
||||||
|
github.com/Antonboom/errname v1.1.1 // indirect
|
||||||
|
github.com/Antonboom/nilnil v1.1.1 // indirect
|
||||||
|
github.com/Antonboom/testifylint v1.6.4 // indirect
|
||||||
|
github.com/BurntSushi/toml v1.6.0 // indirect
|
||||||
|
github.com/Djarvur/go-err113 v0.1.1 // indirect
|
||||||
|
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
|
||||||
|
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||||
|
github.com/Masterminds/semver/v3 v3.4.0 // indirect
|
||||||
|
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||||
|
github.com/MirrexOne/unqueryvet v1.5.3 // indirect
|
||||||
|
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
|
||||||
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
||||||
github.com/agext/levenshtein v1.2.3 // indirect
|
github.com/agext/levenshtein v1.2.3 // indirect
|
||||||
|
github.com/alecthomas/chroma/v2 v2.23.1 // indirect
|
||||||
|
github.com/alecthomas/go-check-sumtype v0.3.1 // indirect
|
||||||
|
github.com/alexkohler/nakedret/v2 v2.0.6 // indirect
|
||||||
|
github.com/alexkohler/prealloc v1.0.2 // indirect
|
||||||
|
github.com/alfatraining/structtag v1.0.0 // indirect
|
||||||
|
github.com/alingse/asasalint v0.0.11 // indirect
|
||||||
|
github.com/alingse/nilnesserr v0.2.0 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||||
github.com/cloudflare/circl v1.6.2 // indirect
|
github.com/armon/go-radix v1.0.0 // indirect
|
||||||
|
github.com/ashanbrown/forbidigo/v2 v2.3.0 // indirect
|
||||||
|
github.com/ashanbrown/makezero/v2 v2.1.0 // indirect
|
||||||
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
|
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/bgentry/speakeasy v0.1.0 // indirect
|
||||||
|
github.com/bkielbasa/cyclop v1.2.3 // indirect
|
||||||
|
github.com/blizzy78/varnamelen v0.8.0 // indirect
|
||||||
|
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
|
||||||
|
github.com/bombsimon/wsl/v4 v4.7.0 // indirect
|
||||||
|
github.com/bombsimon/wsl/v5 v5.6.0 // indirect
|
||||||
|
github.com/breml/bidichk v0.3.3 // indirect
|
||||||
|
github.com/breml/errchkjson v0.4.1 // indirect
|
||||||
|
github.com/buger/jsonparser v1.1.1 // indirect
|
||||||
|
github.com/butuzov/ireturn v0.4.0 // indirect
|
||||||
|
github.com/butuzov/mirror v1.3.0 // indirect
|
||||||
|
github.com/catenacyber/perfsprint v0.10.1 // indirect
|
||||||
|
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/charithe/durationcheck v0.0.11 // indirect
|
||||||
|
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||||
|
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
||||||
|
github.com/charmbracelet/x/ansi v0.10.1 // indirect
|
||||||
|
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||||
|
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||||
|
github.com/ckaznocha/intrange v0.3.1 // indirect
|
||||||
|
github.com/cloudflare/circl v1.6.3 // indirect
|
||||||
|
github.com/curioswitch/go-reassign v0.3.0 // indirect
|
||||||
|
github.com/daixiang0/gci v0.13.7 // indirect
|
||||||
|
github.com/dave/dst v0.27.3 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/denis-tingaikin/go-header v0.5.0 // indirect
|
||||||
|
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||||
|
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
|
||||||
|
github.com/ettle/strcase v0.2.0 // indirect
|
||||||
github.com/fatih/color v1.18.0 // indirect
|
github.com/fatih/color v1.18.0 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
github.com/fatih/structtag v1.2.0 // indirect
|
||||||
|
github.com/firefart/nonamedreturns v1.0.6 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||||
|
github.com/fzipp/gocyclo v0.6.0 // indirect
|
||||||
|
github.com/ghostiam/protogetter v0.3.20 // indirect
|
||||||
|
github.com/go-critic/go-critic v0.14.3 // indirect
|
||||||
|
github.com/go-toolsmith/astcast v1.1.0 // indirect
|
||||||
|
github.com/go-toolsmith/astcopy v1.1.0 // indirect
|
||||||
|
github.com/go-toolsmith/astequal v1.2.0 // indirect
|
||||||
|
github.com/go-toolsmith/astfmt v1.1.0 // indirect
|
||||||
|
github.com/go-toolsmith/astp v1.1.0 // indirect
|
||||||
|
github.com/go-toolsmith/strparse v1.1.0 // indirect
|
||||||
|
github.com/go-toolsmith/typep v1.1.0 // indirect
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
||||||
|
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
|
||||||
|
github.com/gobwas/glob v0.2.3 // indirect
|
||||||
|
github.com/godoc-lint/godoc-lint v0.11.2 // indirect
|
||||||
|
github.com/gofrs/flock v0.13.0 // indirect
|
||||||
github.com/golang/protobuf v1.5.4 // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
|
github.com/golangci/asciicheck v0.5.0 // indirect
|
||||||
|
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect
|
||||||
|
github.com/golangci/go-printf-func-name v0.1.1 // indirect
|
||||||
|
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
|
||||||
|
github.com/golangci/golines v0.15.0 // indirect
|
||||||
|
github.com/golangci/misspell v0.8.0 // indirect
|
||||||
|
github.com/golangci/plugin-module-register v0.1.2 // indirect
|
||||||
|
github.com/golangci/revgrep v0.8.0 // indirect
|
||||||
|
github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect
|
||||||
|
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
|
||||||
|
github.com/gordonklaus/ineffassign v0.2.0 // indirect
|
||||||
|
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
|
||||||
|
github.com/gostaticanalysis/comment v1.5.0 // indirect
|
||||||
|
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
|
||||||
|
github.com/gostaticanalysis/nilerr v0.1.2 // indirect
|
||||||
|
github.com/hashicorp/cli v1.1.7 // indirect
|
||||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
|
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-cty v1.5.0 // indirect
|
github.com/hashicorp/go-cty v1.5.0 // indirect
|
||||||
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
||||||
|
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
|
||||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
github.com/hashicorp/go-plugin v1.7.0 // indirect
|
github.com/hashicorp/go-plugin v1.7.0 // indirect
|
||||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||||
github.com/hashicorp/go-version v1.8.0 // indirect
|
github.com/hashicorp/go-version v1.8.0 // indirect
|
||||||
github.com/hashicorp/hc-install v0.9.2 // indirect
|
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||||
|
github.com/hashicorp/hc-install v0.9.3 // indirect
|
||||||
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/hashicorp/hcl/v2 v2.24.0 // indirect
|
github.com/hashicorp/hcl/v2 v2.24.0 // indirect
|
||||||
github.com/hashicorp/logutils v1.0.0 // indirect
|
github.com/hashicorp/logutils v1.0.0 // indirect
|
||||||
github.com/hashicorp/terraform-exec v0.24.0 // indirect
|
github.com/hashicorp/terraform-exec v0.25.0 // indirect
|
||||||
github.com/hashicorp/terraform-json v0.27.2 // indirect
|
github.com/hashicorp/terraform-json v0.27.2 // indirect
|
||||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 // indirect
|
github.com/hashicorp/terraform-plugin-codegen-spec v0.2.0 // indirect
|
||||||
|
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.2 // indirect
|
||||||
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
|
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
|
||||||
github.com/hashicorp/terraform-svchost v0.2.0 // indirect
|
github.com/hashicorp/terraform-svchost v0.2.0 // indirect
|
||||||
github.com/hashicorp/yamux v0.1.2 // indirect
|
github.com/hashicorp/yamux v0.1.2 // indirect
|
||||||
|
github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||||
|
github.com/huandu/xstrings v1.4.0 // indirect
|
||||||
|
github.com/imdario/mergo v0.3.16 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/jgautheron/goconst v1.8.2 // indirect
|
||||||
|
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
|
||||||
|
github.com/jjti/go-spancheck v0.6.5 // indirect
|
||||||
|
github.com/julz/importas v0.2.0 // indirect
|
||||||
|
github.com/karamaru-alpha/copyloopvar v1.2.2 // indirect
|
||||||
|
github.com/kisielk/errcheck v1.9.0 // indirect
|
||||||
|
github.com/kkHAIKE/contextcheck v1.1.6 // indirect
|
||||||
|
github.com/kulti/thelper v0.7.1 // indirect
|
||||||
|
github.com/kunwardeep/paralleltest v1.0.15 // indirect
|
||||||
|
github.com/lasiar/canonicalheader v1.1.2 // indirect
|
||||||
|
github.com/ldez/exptostd v0.4.5 // indirect
|
||||||
|
github.com/ldez/gomoddirectives v0.8.0 // indirect
|
||||||
|
github.com/ldez/grignotin v0.10.1 // indirect
|
||||||
|
github.com/ldez/structtags v0.6.1 // indirect
|
||||||
|
github.com/ldez/tagliatelle v0.7.2 // indirect
|
||||||
|
github.com/ldez/usetesting v0.5.0 // indirect
|
||||||
|
github.com/leonklingele/grouper v1.1.2 // indirect
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
|
github.com/macabu/inamedparam v0.2.0 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
github.com/manuelarte/embeddedstructfieldcheck v0.4.0 // indirect
|
||||||
|
github.com/manuelarte/funcorder v0.5.0 // indirect
|
||||||
|
github.com/maratori/testableexamples v1.0.1 // indirect
|
||||||
|
github.com/maratori/testpackage v1.1.2 // indirect
|
||||||
|
github.com/matoous/godox v1.1.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/mgechev/revive v1.14.0 // indirect
|
||||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
|
github.com/moricho/tparallel v0.3.2 // indirect
|
||||||
|
github.com/muesli/termenv v0.16.0 // indirect
|
||||||
|
github.com/nakabonne/nestif v0.3.1 // indirect
|
||||||
|
github.com/nishanths/exhaustive v0.12.0 // indirect
|
||||||
|
github.com/nishanths/predeclared v0.2.2 // indirect
|
||||||
|
github.com/nunnatsa/ginkgolinter v0.23.0 // indirect
|
||||||
github.com/oklog/run v1.2.0 // indirect
|
github.com/oklog/run v1.2.0 // indirect
|
||||||
|
github.com/pb33f/libopenapi v0.15.0 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
|
github.com/posener/complete v1.2.3 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.12.1 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.32.1 // indirect
|
||||||
|
github.com/prometheus/procfs v0.7.3 // indirect
|
||||||
|
github.com/quasilyte/go-ruleguard v0.4.5 // indirect
|
||||||
|
github.com/quasilyte/go-ruleguard/dsl v0.3.23 // indirect
|
||||||
|
github.com/quasilyte/gogrep v0.5.0 // indirect
|
||||||
|
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
|
||||||
|
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
|
||||||
|
github.com/raeperd/recvcheck v0.2.0 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||||
|
github.com/ryancurrah/gomodguard v1.4.1 // indirect
|
||||||
|
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
|
||||||
|
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
|
||||||
|
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
|
||||||
|
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
|
||||||
|
github.com/sashamelentyev/usestdlibvars v1.29.0 // indirect
|
||||||
|
github.com/securego/gosec/v2 v2.23.0 // indirect
|
||||||
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.9.4 // indirect
|
||||||
|
github.com/sivchari/containedctx v1.0.3 // indirect
|
||||||
|
github.com/sonatard/noctx v0.4.0 // indirect
|
||||||
|
github.com/sourcegraph/go-diff v0.7.0 // indirect
|
||||||
|
github.com/spf13/afero v1.15.0 // indirect
|
||||||
|
github.com/spf13/cast v1.5.1 // indirect
|
||||||
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.10 // indirect
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
|
github.com/spf13/viper v1.12.0 // indirect
|
||||||
|
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
|
||||||
|
github.com/stbenjam/no-sprintf-host-port v0.3.1 // indirect
|
||||||
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
github.com/stretchr/testify v1.11.1 // indirect
|
github.com/stretchr/testify v1.11.1 // indirect
|
||||||
|
github.com/subosito/gotenv v1.4.1 // indirect
|
||||||
|
github.com/tetafro/godot v1.5.4 // indirect
|
||||||
|
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 // indirect
|
||||||
|
github.com/timonwong/loggercheck v0.11.0 // indirect
|
||||||
|
github.com/tomarrell/wrapcheck/v2 v2.12.0 // indirect
|
||||||
|
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
|
||||||
|
github.com/ultraware/funlen v0.2.0 // indirect
|
||||||
|
github.com/ultraware/whitespace v0.2.0 // indirect
|
||||||
|
github.com/uudashr/gocognit v1.2.0 // indirect
|
||||||
|
github.com/uudashr/iface v1.4.1 // indirect
|
||||||
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
|
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
|
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
|
||||||
|
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||||
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||||
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||||
|
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||||
|
github.com/xen0n/gosmopolitan v1.3.0 // indirect
|
||||||
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
|
github.com/yagipy/maintidx v1.0.0 // indirect
|
||||||
|
github.com/yeya24/promlinter v0.3.0 // indirect
|
||||||
|
github.com/ykadowak/zerologlint v0.1.5 // indirect
|
||||||
|
github.com/yuin/goldmark v1.7.7 // indirect
|
||||||
|
github.com/yuin/goldmark-meta v1.1.0 // indirect
|
||||||
github.com/zclconf/go-cty v1.17.0 // indirect
|
github.com/zclconf/go-cty v1.17.0 // indirect
|
||||||
golang.org/x/crypto v0.47.0 // indirect
|
gitlab.com/bosi/decorder v0.4.2 // indirect
|
||||||
golang.org/x/mod v0.32.0 // indirect
|
go-simpler.org/musttag v0.14.0 // indirect
|
||||||
golang.org/x/net v0.49.0 // indirect
|
go-simpler.org/sloglint v0.11.1 // indirect
|
||||||
|
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
|
||||||
|
go.augendre.info/arangolint v0.4.0 // indirect
|
||||||
|
go.augendre.info/fatcontext v0.9.0 // indirect
|
||||||
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
|
golang.org/x/crypto v0.48.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
||||||
|
golang.org/x/exp/typeparams v0.0.0-20260209203927-2842357ff358 // indirect
|
||||||
|
golang.org/x/mod v0.33.0 // indirect
|
||||||
|
golang.org/x/net v0.50.0 // indirect
|
||||||
golang.org/x/sync v0.19.0 // indirect
|
golang.org/x/sync v0.19.0 // indirect
|
||||||
golang.org/x/sys v0.40.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
golang.org/x/text v0.33.0 // indirect
|
golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4 // indirect
|
||||||
golang.org/x/tools v0.41.0 // indirect
|
golang.org/x/text v0.34.0 // indirect
|
||||||
google.golang.org/appengine v1.6.8 // indirect
|
google.golang.org/appengine v1.6.8 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 // indirect
|
||||||
google.golang.org/grpc v1.78.0 // indirect
|
google.golang.org/grpc v1.79.1 // indirect
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
honnef.co/go/tools v0.7.0 // indirect
|
||||||
|
mvdan.cc/gofumpt v0.9.2 // indirect
|
||||||
|
mvdan.cc/unparam v0.0.0-20251027182757-5beb8c8f8f15 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
tool golang.org/x/tools/cmd/goimports
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@
|
||||||
version: "2"
|
version: "2"
|
||||||
run:
|
run:
|
||||||
concurrency: 4
|
concurrency: 4
|
||||||
|
output:
|
||||||
|
formats:
|
||||||
|
text:
|
||||||
|
print-linter-name: true
|
||||||
|
print-issued-lines: true
|
||||||
|
colors: true
|
||||||
|
path: stdout
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
|
@ -24,6 +31,11 @@ linters:
|
||||||
rules:
|
rules:
|
||||||
main:
|
main:
|
||||||
list-mode: lax
|
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:
|
deny:
|
||||||
- pkg: github.com/stretchr/testify
|
- pkg: github.com/stretchr/testify
|
||||||
desc: Do not use a testing framework
|
desc: Do not use a testing framework
|
||||||
|
|
@ -63,13 +75,18 @@ linters:
|
||||||
- name: empty-lines
|
- name: empty-lines
|
||||||
- name: early-return
|
- name: early-return
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
|
||||||
paths:
|
paths:
|
||||||
- third_party$
|
- stackit-sdk-generator/
|
||||||
- builtin$
|
- generated/
|
||||||
- examples$
|
- pkg_gen/
|
||||||
- tools/copy.go
|
generated: lax
|
||||||
- tools/main.go
|
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
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
- gofmt
|
- gofmt
|
||||||
|
|
@ -77,10 +94,4 @@ formatters:
|
||||||
settings:
|
settings:
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes:
|
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$
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
// Copyright (c) STACKIT
|
|
||||||
|
|
||||||
package testutil
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
39
internal/testutils/activateMocks.go
Normal file
39
internal/testutils/activateMocks.go
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jarcoal/httpmock"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestName() string {
|
||||||
|
pc, _, _, _ := runtime.Caller(1)
|
||||||
|
nameFull := runtime.FuncForPC(pc).Name()
|
||||||
|
nameEnd := filepath.Ext(nameFull)
|
||||||
|
name := strings.TrimPrefix(nameEnd, ".")
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
func ActivateEnvironmentHttpMocks() {
|
||||||
|
httpmock.RegisterNoResponder(
|
||||||
|
func(req *http.Request) (*http.Response, error) {
|
||||||
|
return nil, fmt.Errorf("no responder found for %s %s, please check your http mocks", req.Method, req.URL)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
httpmock.RegisterRegexpResponder(
|
||||||
|
"GET",
|
||||||
|
regexp.MustCompile(`^https://api\.bap\.microsoft\.com/providers/Microsoft\.BusinessAppPlatform/locations/(europe|unitedstates)/environmentLanguages\?api-version=2023-06-01$`),
|
||||||
|
func(_ *http.Request) (*http.Response, error) {
|
||||||
|
return httpmock.NewStringResponse(
|
||||||
|
http.StatusOK,
|
||||||
|
httpmock.File("../../services/languages/tests/datasource/Validate_Read/get_languages.json").String(),
|
||||||
|
), nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
129
internal/testutils/functions.go
Normal file
129
internal/testutils/functions.go
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetHomeEnvVariableName Helper function to obtain the home directory on different systems.
|
||||||
|
// Based on os.UserHomeDir().
|
||||||
|
func GetHomeEnvVariableName() string {
|
||||||
|
env := "HOME"
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
env = "USERPROFILE"
|
||||||
|
case "plan9":
|
||||||
|
env = "home"
|
||||||
|
}
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTemporaryHome create temporary home and initialize the credentials file as well
|
||||||
|
func CreateTemporaryHome(createValidCredentialsFile bool, t *testing.T) string {
|
||||||
|
// create a temporary file
|
||||||
|
tempHome, err := os.MkdirTemp("", "tempHome")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create temporary home directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// create credentials file in temp directory
|
||||||
|
stackitFolder := path.Join(tempHome, ".stackit")
|
||||||
|
if err := os.Mkdir(stackitFolder, 0o750); err != nil {
|
||||||
|
t.Fatalf("Failed to create stackit folder: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := path.Join(stackitFolder, "credentials.json")
|
||||||
|
file, err := os.Create(filePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create credentials file: %v", err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := file.Close(); err != nil {
|
||||||
|
t.Fatalf("Error while closing the file: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Define content, default = invalid token
|
||||||
|
token := "foo_token"
|
||||||
|
if createValidCredentialsFile {
|
||||||
|
token = GetTestProjectServiceAccountJson("")
|
||||||
|
}
|
||||||
|
if _, err = file.WriteString(token); err != nil {
|
||||||
|
t.Fatalf("Error writing to file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempHome
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTemporaryHome Function to overwrite the home folder
|
||||||
|
func SetTemporaryHome(tempHomePath string) {
|
||||||
|
env := GetHomeEnvVariableName()
|
||||||
|
if err := os.Setenv(env, tempHomePath); err != nil {
|
||||||
|
fmt.Printf("Error setting temporary home directory %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanupTemporaryHome cleanup the temporary home and reset the environment variable
|
||||||
|
func CleanupTemporaryHome(tempHomePath string, t *testing.T) {
|
||||||
|
if err := os.RemoveAll(tempHomePath); err != nil {
|
||||||
|
t.Fatalf("Error cleaning up temporary folder: %v", err)
|
||||||
|
}
|
||||||
|
originalHomeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to restore home directory back to normal: %v", err)
|
||||||
|
}
|
||||||
|
// revert back to original home folder
|
||||||
|
env := GetHomeEnvVariableName()
|
||||||
|
if err := os.Setenv(env, originalHomeDir); err != nil {
|
||||||
|
fmt.Printf("Error resetting temporary home directory %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ucFirst(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.ToUpper(s[:1]) + s[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func StringFromTemplateMust(tplFile string, data any) string {
|
||||||
|
res, err := StringFromTemplate(tplFile, data)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func StringFromTemplate(tplFile string, data any) (string, error) {
|
||||||
|
fn := template.FuncMap{
|
||||||
|
"ucfirst": ucFirst,
|
||||||
|
}
|
||||||
|
|
||||||
|
file := filepath.Base(tplFile)
|
||||||
|
|
||||||
|
tmpl, err := template.New(file).Funcs(fn).ParseFiles(tplFile)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
tplBuf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
err = tmpl.Execute(tplBuf, data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tplBuf.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResStr(prefix, resource, name string) string {
|
||||||
|
return fmt.Sprintf("%s_%s.%s", prefix, resource, name)
|
||||||
|
}
|
||||||
465
internal/testutils/helpers.go
Normal file
465
internal/testutils/helpers.go
Normal file
|
|
@ -0,0 +1,465 @@
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
CdnCustomEndpoint = os.Getenv("TF_ACC_CDN_CUSTOM_ENDPOINT")
|
||||||
|
DnsCustomEndpoint = os.Getenv("TF_ACC_DNS_CUSTOM_ENDPOINT")
|
||||||
|
GitCustomEndpoint = os.Getenv("TF_ACC_GIT_CUSTOM_ENDPOINT")
|
||||||
|
IaaSCustomEndpoint = os.Getenv("TF_ACC_IAAS_CUSTOM_ENDPOINT")
|
||||||
|
KMSCustomEndpoint = os.Getenv("TF_ACC_KMS_CUSTOM_ENDPOINT")
|
||||||
|
LoadBalancerCustomEndpoint = os.Getenv("TF_ACC_LOADBALANCER_CUSTOM_ENDPOINT")
|
||||||
|
LogMeCustomEndpoint = os.Getenv("TF_ACC_LOGME_CUSTOM_ENDPOINT")
|
||||||
|
MariaDBCustomEndpoint = os.Getenv("TF_ACC_MARIADB_CUSTOM_ENDPOINT")
|
||||||
|
ModelServingCustomEndpoint = os.Getenv("TF_ACC_MODELSERVING_CUSTOM_ENDPOINT")
|
||||||
|
AuthorizationCustomEndpoint = os.Getenv("TF_ACC_authorization_custom_endpoint")
|
||||||
|
MongoDBFlexCustomEndpoint = os.Getenv("TF_ACC_MONGODBFLEX_CUSTOM_ENDPOINT")
|
||||||
|
OpenSearchCustomEndpoint = os.Getenv("TF_ACC_OPENSEARCH_CUSTOM_ENDPOINT")
|
||||||
|
ObservabilityCustomEndpoint = os.Getenv("TF_ACC_OBSERVABILITY_CUSTOM_ENDPOINT")
|
||||||
|
ObjectStorageCustomEndpoint = os.Getenv("TF_ACC_OBJECTSTORAGE_CUSTOM_ENDPOINT")
|
||||||
|
PostgresFlexCustomEndpoint = os.Getenv("TF_ACC_POSTGRESFLEX_CUSTOM_ENDPOINT")
|
||||||
|
RabbitMQCustomEndpoint = os.Getenv("TF_ACC_RABBITMQ_CUSTOM_ENDPOINT")
|
||||||
|
RedisCustomEndpoint = os.Getenv("TF_ACC_REDIS_CUSTOM_ENDPOINT")
|
||||||
|
ResourceManagerCustomEndpoint = os.Getenv("TF_ACC_RESOURCEMANAGER_CUSTOM_ENDPOINT")
|
||||||
|
ScfCustomEndpoint = os.Getenv("TF_ACC_SCF_CUSTOM_ENDPOINT")
|
||||||
|
SecretsManagerCustomEndpoint = os.Getenv("TF_ACC_SECRETSMANAGER_CUSTOM_ENDPOINT")
|
||||||
|
SQLServerFlexCustomEndpoint = os.Getenv("TF_ACC_SQLSERVERFLEX_CUSTOM_ENDPOINT")
|
||||||
|
ServerBackupCustomEndpoint = os.Getenv("TF_ACC_SERVER_BACKUP_CUSTOM_ENDPOINT")
|
||||||
|
ServerUpdateCustomEndpoint = os.Getenv("TF_ACC_SERVER_UPDATE_CUSTOM_ENDPOINT")
|
||||||
|
ServiceAccountCustomEndpoint = os.Getenv("TF_ACC_SERVICE_ACCOUNT_CUSTOM_ENDPOINT")
|
||||||
|
SKECustomEndpoint = os.Getenv("TF_ACC_SKE_CUSTOM_ENDPOINT")
|
||||||
|
)
|
||||||
|
|
||||||
|
func ObservabilityProviderConfig() string {
|
||||||
|
if ObservabilityCustomEndpoint == "" {
|
||||||
|
return `provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
observability_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
ObservabilityCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CdnProviderConfig() string {
|
||||||
|
if CdnCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
cdn_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`,
|
||||||
|
CdnCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DnsProviderConfig() string {
|
||||||
|
if DnsCustomEndpoint == "" {
|
||||||
|
return `provider "stackitprivatepreview" {}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
dns_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
DnsCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IaaSProviderConfig() string {
|
||||||
|
if IaaSCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
iaas_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
IaaSCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IaaSProviderConfigWithBetaResourcesEnabled() string {
|
||||||
|
if IaaSCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
enable_beta_resources = true
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
enable_beta_resources = true
|
||||||
|
iaas_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
IaaSCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IaaSProviderConfigWithExperiments() string {
|
||||||
|
if IaaSCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
experiments = [ "routing-tables", "network" ]
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
iaas_custom_endpoint = "%s"
|
||||||
|
experiments = [ "routing-tables", "network" ]
|
||||||
|
}`,
|
||||||
|
IaaSCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func KMSProviderConfig() string {
|
||||||
|
if KMSCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
kms_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
KMSCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadBalancerProviderConfig() string {
|
||||||
|
if LoadBalancerCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
loadbalancer_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
LoadBalancerCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LogMeProviderConfig() string {
|
||||||
|
if LogMeCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
logme_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
LogMeCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MariaDBProviderConfig() string {
|
||||||
|
if MariaDBCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
mariadb_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
MariaDBCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ModelServingProviderConfig() string {
|
||||||
|
if ModelServingCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
modelserving_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
ModelServingCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MongoDBFlexProviderConfig() string {
|
||||||
|
if MongoDBFlexCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
mongodbflex_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
MongoDBFlexCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ObjectStorageProviderConfig() string {
|
||||||
|
if ObjectStorageCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
objectstorage_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
ObjectStorageCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenSearchProviderConfig() string {
|
||||||
|
if OpenSearchCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
opensearch_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
OpenSearchCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostgresFlexProviderConfig(saFile string) string {
|
||||||
|
if PostgresFlexCustomEndpoint == "" {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
service_account_key_path = "%s"
|
||||||
|
}`, saFile)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
service_account_key_path = "%s"
|
||||||
|
postgresflex_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
saFile,
|
||||||
|
PostgresFlexCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RabbitMQProviderConfig() string {
|
||||||
|
if RabbitMQCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
rabbitmq_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
RabbitMQCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RedisProviderConfig() string {
|
||||||
|
if RedisCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
redis_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
RedisCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceManagerProviderConfig() string {
|
||||||
|
key := GetTestProjectServiceAccountJson("")
|
||||||
|
if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
service_account_key = "%s"
|
||||||
|
}`,
|
||||||
|
key,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
resourcemanager_custom_endpoint = "%s"
|
||||||
|
authorization_custom_endpoint = "%s"
|
||||||
|
service_account_token = "%s"
|
||||||
|
}`,
|
||||||
|
ResourceManagerCustomEndpoint,
|
||||||
|
AuthorizationCustomEndpoint,
|
||||||
|
key,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SecretsManagerProviderConfig() string {
|
||||||
|
if SecretsManagerCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
secretsmanager_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
SecretsManagerCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SQLServerFlexProviderConfig(saFile string) string {
|
||||||
|
if SQLServerFlexCustomEndpoint == "" {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
service_account_key_path = "%s"
|
||||||
|
}`, saFile)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
service_account_key_path = "%s"
|
||||||
|
sqlserverflex_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
saFile,
|
||||||
|
SQLServerFlexCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServerBackupProviderConfig() string {
|
||||||
|
if ServerBackupCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
server_backup_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`,
|
||||||
|
ServerBackupCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServerUpdateProviderConfig() string {
|
||||||
|
if ServerUpdateCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
server_update_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`,
|
||||||
|
ServerUpdateCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SKEProviderConfig() string {
|
||||||
|
if SKECustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
ske_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
SKECustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AuthorizationProviderConfig() string {
|
||||||
|
if AuthorizationCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
experiments = ["iam"]
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
authorization_custom_endpoint = "%s"
|
||||||
|
experiments = ["iam"]
|
||||||
|
}`,
|
||||||
|
AuthorizationCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServiceAccountProviderConfig() string {
|
||||||
|
if ServiceAccountCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
service_account_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`,
|
||||||
|
ServiceAccountCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GitProviderConfig() string {
|
||||||
|
if GitCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
git_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
|
}`,
|
||||||
|
GitCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ScfProviderConfig() string {
|
||||||
|
if ScfCustomEndpoint == "" {
|
||||||
|
return `
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
scf_custom_endpoint = "%s"
|
||||||
|
}`,
|
||||||
|
ScfCustomEndpoint,
|
||||||
|
)
|
||||||
|
}
|
||||||
219
internal/testutils/testutils.go
Normal file
219
internal/testutils/testutils.go
Normal file
|
|
@ -0,0 +1,219 @@
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||||
|
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
||||||
|
"github.com/hashicorp/terraform-plugin-testing/config"
|
||||||
|
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Default location of credentials JSON
|
||||||
|
// credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive
|
||||||
|
serviceAccountFilePath = ".stackit/service_account.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// TestAccProtoV6ProviderFactories is used to instantiate a provider during
|
||||||
|
// acceptance testing. The factory function will be invoked for every Terraform
|
||||||
|
// CLI command executed to create a provider server to which the CLI can
|
||||||
|
// reattach.
|
||||||
|
TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||||
|
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestEphemeralAccProtoV6ProviderFactories is used to instantiate a provider during
|
||||||
|
// acceptance testing. The factory function will be invoked for every Terraform
|
||||||
|
// CLI command executed to create a provider server to which the CLI can
|
||||||
|
// reattach.
|
||||||
|
//
|
||||||
|
// See the Terraform acceptance test documentation on ephemeral resources for more information:
|
||||||
|
// https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/ephemeral-resources
|
||||||
|
TestEphemeralAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||||
|
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||||
|
"echo": echoprovider.NewProviderServer(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// E2ETestsEnabled checks if end-to-end tests should be run.
|
||||||
|
// It is enabled when the TF_ACC environment variable is set to "1".
|
||||||
|
E2ETestsEnabled = os.Getenv("TF_ACC") == "1"
|
||||||
|
// OrganizationId is the id of organization used for tests
|
||||||
|
OrganizationId = os.Getenv("TF_ACC_ORGANIZATION_ID")
|
||||||
|
// ProjectId is the id of project used for tests
|
||||||
|
ProjectId = os.Getenv("TF_ACC_PROJECT_ID")
|
||||||
|
Region = os.Getenv("TF_ACC_REGION")
|
||||||
|
// ServiceAccountFile is the json file of the service account
|
||||||
|
ServiceAccountFile = os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE")
|
||||||
|
// ServerId is the id of a server used for some tests
|
||||||
|
ServerId = getenv("TF_ACC_SERVER_ID", "")
|
||||||
|
// TestProjectParentContainerID is the container id of the parent resource under which projects are created as part of the resource-manager acceptance tests
|
||||||
|
TestProjectParentContainerID = os.Getenv("TF_ACC_TEST_PROJECT_PARENT_CONTAINER_ID")
|
||||||
|
// TestProjectParentUUID is the uuid of the parent resource under which projects are created as part of the resource-manager acceptance tests
|
||||||
|
TestProjectParentUUID = os.Getenv("TF_ACC_TEST_PROJECT_PARENT_UUID")
|
||||||
|
// TestProjectServiceAccountEmail is the e-mail of a service account with admin permissions on the organization under which projects are created as part of the resource-manager acceptance tests
|
||||||
|
TestProjectServiceAccountEmail = os.Getenv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL")
|
||||||
|
// TestProjectUserEmail is the e-mail of a user for the project created as part of the resource-manager acceptance tests
|
||||||
|
// Default email: acc-test@sa.stackit.cloud
|
||||||
|
TestProjectUserEmail = getenv("TF_ACC_TEST_PROJECT_USER_EMAIL", "acc-test@sa.stackit.cloud")
|
||||||
|
// TestImageLocalFilePath is the local path to an image file used for image acceptance tests
|
||||||
|
TestImageLocalFilePath = getenv("TF_ACC_TEST_IMAGE_LOCAL_FILE_PATH", "default")
|
||||||
|
)
|
||||||
|
|
||||||
|
func Setup() {
|
||||||
|
root, err := getRoot()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
err = godotenv.Load(fmt.Sprintf("%s/.env", *root))
|
||||||
|
if err != nil {
|
||||||
|
slog.Info("could not find .env file - not loading .env")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
slog.Info("loaded .env file", "path", *root)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRoot() (*string, error) {
|
||||||
|
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lines := strings.Split(string(out), "\n")
|
||||||
|
return &lines[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceNameWithDateTime(name string) string {
|
||||||
|
dateTime := time.Now().Format(time.RFC3339)
|
||||||
|
// Remove timezone to have a smaller datetime
|
||||||
|
dateTimeTrimmed, _, _ := strings.Cut(dateTime, "+")
|
||||||
|
return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTestProjectServiceAccountJson(path string) string {
|
||||||
|
var err error
|
||||||
|
token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_JSON")
|
||||||
|
if !tokenSet || token == "" {
|
||||||
|
token, err = readTestServiceAccountJsonFromFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
// func GetTestProjectServiceAccountToken(path string) string {
|
||||||
|
// var err error
|
||||||
|
// token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||||
|
// if !tokenSet || token == "" {
|
||||||
|
// token, err = readTestTokenFromCredentialsFile(path)
|
||||||
|
// if err != nil {
|
||||||
|
// return ""
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return token
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||||
|
// if path == "" {
|
||||||
|
// customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||||
|
// if !customPathSet || customPath == "" {
|
||||||
|
// path = credentialsFilePath
|
||||||
|
// home, err := os.UserHomeDir()
|
||||||
|
// if err != nil {
|
||||||
|
// return "", fmt.Errorf("getting home directory: %w", err)
|
||||||
|
// }
|
||||||
|
// path = filepath.Join(home, path)
|
||||||
|
// } else {
|
||||||
|
// path = customPath
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// credentialsRaw, err := os.ReadFile(path)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", fmt.Errorf("opening file: %w", err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// var credentials struct {
|
||||||
|
// TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"`
|
||||||
|
// }
|
||||||
|
// err = json.Unmarshal(credentialsRaw, &credentials)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", fmt.Errorf("unmarshalling credentials: %w", err)
|
||||||
|
// }
|
||||||
|
// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||||
|
//}
|
||||||
|
|
||||||
|
func readTestServiceAccountJsonFromFile(path string) (string, error) {
|
||||||
|
if path == "" {
|
||||||
|
customPath, customPathSet := os.LookupEnv("STACKIT_SERVICE_ACCOUNT_PATH")
|
||||||
|
if !customPathSet || customPath == "" {
|
||||||
|
path = serviceAccountFilePath
|
||||||
|
home, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("getting home directory: %w", err)
|
||||||
|
}
|
||||||
|
path = filepath.Join(home, path)
|
||||||
|
} else {
|
||||||
|
path = customPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
credentialsRaw, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("opening file: %w", err)
|
||||||
|
}
|
||||||
|
return string(credentialsRaw), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getenv(key, defaultValue string) string {
|
||||||
|
val := os.Getenv(key)
|
||||||
|
if val == "" {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDefaultLocalFile is a helper for local_file_path. No real data is created
|
||||||
|
func CreateDefaultLocalFile() os.File {
|
||||||
|
// Define the file name and size
|
||||||
|
fileName := "test-512k.img"
|
||||||
|
size := 512 * 1024 // 512 KB
|
||||||
|
|
||||||
|
// Create the file
|
||||||
|
file, err := os.Create(fileName)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seek to the desired position (512 KB)
|
||||||
|
_, err = file.Seek(int64(size), 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return *file
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertConfigVariable(variable config.Variable) string {
|
||||||
|
tmpByteArray, _ := variable.MarshalJSON()
|
||||||
|
// In case the variable is a string, the quotes should be removed
|
||||||
|
if tmpByteArray[0] == '"' && tmpByteArray[len(tmpByteArray)-1] == '"' {
|
||||||
|
result := string(tmpByteArray[1 : len(tmpByteArray)-1])
|
||||||
|
// Replace escaped quotes which where added MarshalJSON
|
||||||
|
rawString := strings.ReplaceAll(result, `\"`, `"`)
|
||||||
|
return rawString
|
||||||
|
}
|
||||||
|
return string(tmpByteArray)
|
||||||
|
}
|
||||||
48
internal/testutils/testutils_test.go
Normal file
48
internal/testutils/testutils_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
package testutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-testing/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConvertConfigVariable(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
variable config.Variable
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "string",
|
||||||
|
variable: config.StringVariable("test"),
|
||||||
|
want: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bool: true",
|
||||||
|
variable: config.BoolVariable(true),
|
||||||
|
want: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bool: false",
|
||||||
|
variable: config.BoolVariable(false),
|
||||||
|
want: "false",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "integer",
|
||||||
|
variable: config.IntegerVariable(10),
|
||||||
|
want: "10",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "quoted string",
|
||||||
|
variable: config.StringVariable(`instance =~ ".*"`),
|
||||||
|
want: `instance =~ ".*"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := ConvertConfigVariable(tt.variable); got != tt.want {
|
||||||
|
t.Errorf("ConvertConfigVariable() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
1
main.go
1
main.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||||
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,15 @@ resource "stackitprivatepreview_postgresflexalpha_instance" "msh-sna-pe-example2
|
||||||
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbadminuser" {
|
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbadminuser" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example.instance_id
|
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example.instance_id
|
||||||
username = var.db_admin_username
|
name = var.db_admin_username
|
||||||
roles = ["createdb", "login"]
|
roles = ["createdb", "login", "login"]
|
||||||
# roles = ["createdb", "login", "createrole"]
|
# roles = ["createdb", "login", "createrole"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbadminuser2" {
|
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbadminuser2" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example2.instance_id
|
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example2.instance_id
|
||||||
username = var.db_admin_username
|
name = var.db_admin_username
|
||||||
roles = ["createdb", "login"]
|
roles = ["createdb", "login"]
|
||||||
# roles = ["createdb", "login", "createrole"]
|
# roles = ["createdb", "login", "createrole"]
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbadminuser2" {
|
||||||
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbuser" {
|
resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbuser" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example.instance_id
|
instance_id = stackitprivatepreview_postgresflexalpha_instance.msh-sna-pe-example.instance_id
|
||||||
username = var.db_username
|
name = var.db_name
|
||||||
roles = ["login"]
|
roles = ["login"]
|
||||||
# roles = ["createdb", "login", "createrole"]
|
# roles = ["createdb", "login", "createrole"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
data "stackitprivatepreview_sqlserverflexalpha_flavor" "sqlserver_flavor" {
|
data "stackitprivatepreview_sqlserverflexbeta_flavor" "sqlserver_flavor" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
region = "eu01"
|
region = "eu01"
|
||||||
cpu = 4
|
cpu = 4
|
||||||
|
|
@ -9,5 +9,5 @@ data "stackitprivatepreview_sqlserverflexalpha_flavor" "sqlserver_flavor" {
|
||||||
}
|
}
|
||||||
|
|
||||||
output "sqlserver_flavor" {
|
output "sqlserver_flavor" {
|
||||||
value = data.stackitprivatepreview_sqlserverflexalpha_flavor.sqlserver_flavor.flavor_id
|
value = data.stackitprivatepreview_sqlserverflexbeta_flavor.sqlserver_flavor.flavor_id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@
|
||||||
# value = stackit_kms_key.key.key_id
|
# value = stackit_kms_key.key.key_id
|
||||||
# }
|
# }
|
||||||
|
|
||||||
resource "stackitprivatepreview_sqlserverflexalpha_instance" "msh-sna-001" {
|
resource "stackitprivatepreview_sqlserverflexbeta_instance" "msh-beta-sna-001" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
name = "msh-sna-001"
|
name = "msh-beta-sna-001"
|
||||||
backup_schedule = "0 3 * * *"
|
backup_schedule = "0 3 * * *"
|
||||||
retention_days = 31
|
retention_days = 31
|
||||||
flavor_id = data.stackitprivatepreview_sqlserverflexalpha_flavor.sqlserver_flavor.flavor_id
|
flavor_id = data.stackitprivatepreview_sqlserverflexbeta_flavor.sqlserver_flavor.flavor_id
|
||||||
storage = {
|
storage = {
|
||||||
class = "premium-perf2-stackit"
|
class = "premium-perf2-stackit"
|
||||||
size = 50
|
size = 10
|
||||||
}
|
}
|
||||||
version = 2022
|
version = 2022
|
||||||
encryption = {
|
encryption = {
|
||||||
|
|
@ -34,9 +34,11 @@ resource "stackitprivatepreview_sqlserverflexalpha_instance" "msh-sna-001" {
|
||||||
#keyring_id = stackit_kms_keyring.keyring.keyring_id
|
#keyring_id = stackit_kms_keyring.keyring.keyring_id
|
||||||
#key_version = 1
|
#key_version = 1
|
||||||
# key with scope public
|
# key with scope public
|
||||||
kek_key_id = "fe039bcf-8d7b-431a-801d-9e81371a6b7b"
|
# kek_key_id = "fe039bcf-8d7b-431a-801d-9e81371a6b7b"
|
||||||
|
kek_key_id = "c6878f92-ce55-4b79-8236-ba9d001d7967" # msh-k-001
|
||||||
# key_id = var.key_id
|
# key_id = var.key_id
|
||||||
kek_key_ring_id = var.keyring_id
|
# kek_key_ring_id = var.keyring_id
|
||||||
|
kek_key_ring_id = "0dea3f5f-9947-4dda-a9d3-18418832cefe" # msh-kr-sna01
|
||||||
kek_key_version = var.key_version
|
kek_key_version = var.key_version
|
||||||
service_account = var.sa_email
|
service_account = var.sa_email
|
||||||
}
|
}
|
||||||
|
|
@ -46,83 +48,16 @@ resource "stackitprivatepreview_sqlserverflexalpha_instance" "msh-sna-001" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "stackitprivatepreview_sqlserverflexalpha_instance" "msh-sna-101" {
|
resource "stackitprivatepreview_sqlserverflexbeta_user" "betauser" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
name = "msh-sna-101"
|
instance_id = stackitprivatepreview_sqlserverflexbeta_instance.msh-beta-sna-001.instance_id
|
||||||
backup_schedule = "0 3 * * *"
|
username = "betauser"
|
||||||
retention_days = 31
|
roles = ["##STACKIT_DatabaseManager##", "##STACKIT_LoginManager##"]
|
||||||
flavor_id = data.stackitprivatepreview_sqlserverflexalpha_flavor.sqlserver_flavor.flavor_id
|
|
||||||
storage = {
|
|
||||||
class = "premium-perf2-stackit"
|
|
||||||
size = 50
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
encryption = {
|
|
||||||
#key_id = stackit_kms_key.key.key_id
|
|
||||||
#keyring_id = stackit_kms_keyring.keyring.keyring_id
|
|
||||||
#key_version = 1
|
|
||||||
# key with scope public
|
|
||||||
kek_key_id = "fe039bcf-8d7b-431a-801d-9e81371a6b7b"
|
|
||||||
# key_id = var.key_id
|
|
||||||
kek_key_ring_id = var.keyring_id
|
|
||||||
kek_key_version = var.key_version
|
|
||||||
service_account = var.sa_email
|
|
||||||
}
|
|
||||||
network = {
|
|
||||||
acl = ["0.0.0.0/0", "193.148.160.0/19"]
|
|
||||||
access_scope = "SNA"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "stackitprivatepreview_sqlserverflexalpha_instance" "msh-nosna-001" {
|
resource "stackitprivatepreview_sqlserverflexbeta_database" "betadb" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
name = "msh-nosna-001"
|
instance_id = stackitprivatepreview_sqlserverflexbeta_instance.msh-beta-sna-001.instance_id
|
||||||
backup_schedule = "0 3 * * *"
|
name = "mshtest002"
|
||||||
retention_days = 31
|
owner = stackitprivatepreview_sqlserverflexbeta_user.betauser.username
|
||||||
flavor_id = data.stackitprivatepreview_sqlserverflexalpha_flavor.sqlserver_flavor.flavor_id
|
|
||||||
storage = {
|
|
||||||
class = "premium-perf2-stackit"
|
|
||||||
size = 50
|
|
||||||
}
|
|
||||||
version = 2022
|
|
||||||
# encryption = {
|
|
||||||
# #key_id = stackit_kms_key.key.key_id
|
|
||||||
# #keyring_id = stackit_kms_keyring.keyring.keyring_id
|
|
||||||
# #key_version = 1
|
|
||||||
# #key_id = var.key_id
|
|
||||||
# # key with scope public
|
|
||||||
# key_id = "fe039bcf-8d7b-431a-801d-9e81371a6b7b"
|
|
||||||
# keyring_id = var.keyring_id
|
|
||||||
# key_version = var.key_version
|
|
||||||
# service_account = var.sa_email
|
|
||||||
# }
|
|
||||||
network = {
|
|
||||||
acl = ["0.0.0.0/0", "193.148.160.0/19"]
|
|
||||||
access_scope = "PUBLIC"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# data "stackitprivatepreview_sqlserverflexalpha_instance" "test" {
|
|
||||||
# project_id = var.project_id
|
|
||||||
# instance_id = var.instance_id
|
|
||||||
# region = "eu01"
|
|
||||||
# }
|
|
||||||
|
|
||||||
# output "test" {
|
|
||||||
# value = data.stackitprivatepreview_sqlserverflexalpha_instance.test
|
|
||||||
# }
|
|
||||||
|
|
||||||
# resource "stackitprivatepreview_sqlserverflexalpha_user" "ptlsdbadminuser" {
|
|
||||||
# project_id = var.project_id
|
|
||||||
# instance_id = stackitprivatepreview_sqlserverflexalpha_instance.sqlsrv.instance_id
|
|
||||||
# username = var.db_admin_username
|
|
||||||
# roles = ["##STACKIT_LoginManager##", "##STACKIT_DatabaseManager##"]
|
|
||||||
# }
|
|
||||||
|
|
||||||
# resource "stackitprivatepreview_sqlserverflexalpha_user" "ptlsdbuser" {
|
|
||||||
# project_id = var.project_id
|
|
||||||
# instance_id = stackitprivatepreview_sqlserverflexalpha_instance.sqlsrv.instance_id
|
|
||||||
# username = var.db_username
|
|
||||||
# roles = ["##STACKIT_LoginManager##"]
|
|
||||||
# }
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# This script lints the SDK modules and the internal examples
|
|
||||||
# Pre-requisites: golangci-lint
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
||||||
GOLANG_CI_YAML_PATH="${ROOT_DIR}/golang-ci.yaml"
|
|
||||||
GOLANG_CI_ARGS="--allow-parallel-runners --timeout=5m --config=${GOLANG_CI_YAML_PATH}"
|
|
||||||
|
|
||||||
if type -p golangci-lint >/dev/null; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
echo "golangci-lint not installed, unable to proceed."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd ${ROOT_DIR}
|
|
||||||
golangci-lint run ${GOLANG_CI_ARGS}
|
|
||||||
|
|
@ -17,11 +17,7 @@ elif [ "$action" = "tools" ]; then
|
||||||
|
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
# go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0
|
go install golang.org/x/tools/cmd/goimports@v0.42.0
|
||||||
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2
|
|
||||||
|
|
||||||
# go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.21.0
|
|
||||||
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.24.0
|
|
||||||
else
|
else
|
||||||
echo "Invalid action: '$action', please use $0 help for help"
|
echo "Invalid action: '$action', please use $0 help for help"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,5 @@ fi
|
||||||
mkdir -p ${ROOT_DIR}/docs
|
mkdir -p ${ROOT_DIR}/docs
|
||||||
|
|
||||||
echo ">> Generating documentation"
|
echo ">> Generating documentation"
|
||||||
tfplugindocs generate \
|
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate \
|
||||||
--provider-name "stackitprivatepreview"
|
--provider-name "stackitprivatepreview"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||||
|
|
||||||
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
|
|
||||||
"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/core"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ const (
|
||||||
type EphemeralProviderData struct {
|
type EphemeralProviderData struct {
|
||||||
ProviderData
|
ProviderData
|
||||||
|
|
||||||
PrivateKey string
|
PrivateKey string //nolint:gosec //this is a placeholder and not used in this code
|
||||||
PrivateKeyPath string
|
PrivateKeyPath string
|
||||||
ServiceAccountKey string
|
ServiceAccountKey string
|
||||||
ServiceAccountKeyPath string
|
ServiceAccountKeyPath string
|
||||||
|
|
@ -105,11 +105,13 @@ func DiagsToError(diags diag.Diagnostics) error {
|
||||||
diagsError := diags.Errors()
|
diagsError := diags.Errors()
|
||||||
diagsStrings := make([]string, 0)
|
diagsStrings := make([]string, 0)
|
||||||
for _, diagnostic := range diagsError {
|
for _, diagnostic := range diagsError {
|
||||||
diagsStrings = append(diagsStrings, fmt.Sprintf(
|
diagsStrings = append(
|
||||||
"(%s) %s",
|
diagsStrings, fmt.Sprintf(
|
||||||
diagnostic.Summary(),
|
"(%s) %s",
|
||||||
diagnostic.Detail(),
|
diagnostic.Summary(),
|
||||||
))
|
diagnostic.Detail(),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s", strings.Join(diagsStrings, ";"))
|
return fmt.Errorf("%s", strings.Join(diagsStrings, ";"))
|
||||||
}
|
}
|
||||||
|
|
@ -136,14 +138,22 @@ func LogAndAddWarning(ctx context.Context, diags *diag.Diagnostics, summary, det
|
||||||
|
|
||||||
func LogAndAddWarningBeta(ctx context.Context, diags *diag.Diagnostics, name string, resourceType ResourceType) {
|
func LogAndAddWarningBeta(ctx context.Context, diags *diag.Diagnostics, name string, resourceType ResourceType) {
|
||||||
warnTitle := fmt.Sprintf("The %s %q is in beta", resourceType, name)
|
warnTitle := fmt.Sprintf("The %s %q is in beta", resourceType, name)
|
||||||
warnContent := fmt.Sprintf("The %s %q is in beta and may be subject to breaking changes in the future. Use with caution.", resourceType, name)
|
warnContent := fmt.Sprintf(
|
||||||
|
"The %s %q is in beta and may be subject to breaking changes in the future. Use with caution.",
|
||||||
|
resourceType,
|
||||||
|
name,
|
||||||
|
)
|
||||||
tflog.Warn(ctx, fmt.Sprintf("%s | %s", warnTitle, warnContent))
|
tflog.Warn(ctx, fmt.Sprintf("%s | %s", warnTitle, warnContent))
|
||||||
diags.AddWarning(warnTitle, warnContent)
|
diags.AddWarning(warnTitle, warnContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogAndAddErrorBeta(ctx context.Context, diags *diag.Diagnostics, name string, resourceType ResourceType) {
|
func LogAndAddErrorBeta(ctx context.Context, diags *diag.Diagnostics, name string, resourceType ResourceType) {
|
||||||
errTitle := fmt.Sprintf("The %s %q is in beta and beta is not enabled", resourceType, name)
|
errTitle := fmt.Sprintf("The %s %q is in beta and beta is not enabled", resourceType, name)
|
||||||
errContent := fmt.Sprintf(`The %s %q is in beta and the beta functionality is currently not enabled. To enable it, set the environment variable STACKIT_TF_ENABLE_BETA_RESOURCES to "true" or set the "enable_beta_resources" provider field to true.`, resourceType, name)
|
errContent := fmt.Sprintf(
|
||||||
|
`The %s %q is in beta and the beta functionality is currently not enabled. To enable it, set the environment variable STACKIT_TF_ENABLE_BETA_RESOURCES to "true" or set the "enable_beta_resources" provider field to true.`,
|
||||||
|
resourceType,
|
||||||
|
name,
|
||||||
|
)
|
||||||
tflog.Error(ctx, fmt.Sprintf("%s | %s", errTitle, errContent))
|
tflog.Error(ctx, fmt.Sprintf("%s | %s", errTitle, errContent))
|
||||||
diags.AddError(errTitle, errContent)
|
diags.AddError(errTitle, errContent)
|
||||||
}
|
}
|
||||||
|
|
@ -161,8 +171,10 @@ func LogResponse(ctx context.Context) context.Context {
|
||||||
traceId := runtime.GetTraceId(ctx)
|
traceId := runtime.GetTraceId(ctx)
|
||||||
ctx = tflog.SetField(ctx, "x-trace-id", traceId)
|
ctx = tflog.SetField(ctx, "x-trace-id", traceId)
|
||||||
|
|
||||||
tflog.Info(ctx, "response data", map[string]interface{}{
|
tflog.Info(
|
||||||
"x-trace-id": traceId,
|
ctx, "response data", map[string]interface{}{
|
||||||
})
|
"x-trace-id": traceId,
|
||||||
|
},
|
||||||
|
)
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
237
stackit/internal/core/retry_round_tripper.go
Normal file
237
stackit/internal/core/retry_round_tripper.go
Normal file
|
|
@ -0,0 +1,237 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// backoffMultiplier is the factor by which the delay is multiplied for exponential backoff.
|
||||||
|
backoffMultiplier = 2
|
||||||
|
// jitterFactor is the divisor used to calculate jitter (e.g., half of the base delay).
|
||||||
|
jitterFactor = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrRequestFailedAfterRetries is returned when a request fails after all retry attempts.
|
||||||
|
ErrRequestFailedAfterRetries = errors.New("request failed after all retry attempts")
|
||||||
|
)
|
||||||
|
|
||||||
|
// RetryRoundTripper implements an http.RoundTripper that adds automatic retry logic for failed requests.
|
||||||
|
type RetryRoundTripper struct {
|
||||||
|
next http.RoundTripper
|
||||||
|
maxRetries int
|
||||||
|
initialDelay time.Duration
|
||||||
|
maxDelay time.Duration
|
||||||
|
perTryTimeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRetryRoundTripper creates a new instance of the RetryRoundTripper with the specified configuration.
|
||||||
|
func NewRetryRoundTripper(
|
||||||
|
next http.RoundTripper,
|
||||||
|
maxRetries int,
|
||||||
|
initialDelay, maxDelay, perTryTimeout time.Duration,
|
||||||
|
) *RetryRoundTripper {
|
||||||
|
return &RetryRoundTripper{
|
||||||
|
next: next,
|
||||||
|
maxRetries: maxRetries,
|
||||||
|
initialDelay: initialDelay,
|
||||||
|
maxDelay: maxDelay,
|
||||||
|
perTryTimeout: perTryTimeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoundTrip executes the request and retries on failure.
|
||||||
|
func (rrt *RetryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
resp, err := rrt.executeRequest(req)
|
||||||
|
if !rrt.shouldRetry(resp, err) {
|
||||||
|
if err != nil {
|
||||||
|
return resp, fmt.Errorf("initial request failed, not retrying: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return rrt.retryLoop(req, resp, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// executeRequest performs a single HTTP request with a per-try timeout.
|
||||||
|
func (rrt *RetryRoundTripper) executeRequest(req *http.Request) (*http.Response, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(req.Context(), rrt.perTryTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
resp, err := rrt.next.RoundTrip(req.WithContext(ctx))
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
return resp, fmt.Errorf("per-try timeout of %v exceeded: %w", rrt.perTryTimeout, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, fmt.Errorf("http roundtrip failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// retryLoop handles the retry logic for a failed request.
|
||||||
|
func (rrt *RetryRoundTripper) retryLoop(
|
||||||
|
req *http.Request,
|
||||||
|
initialResp *http.Response,
|
||||||
|
initialErr error,
|
||||||
|
) (*http.Response, error) {
|
||||||
|
var (
|
||||||
|
lastErr = initialErr
|
||||||
|
resp = initialResp
|
||||||
|
currentDelay = rrt.initialDelay
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx := req.Context()
|
||||||
|
|
||||||
|
for attempt := 1; attempt <= rrt.maxRetries; attempt++ {
|
||||||
|
rrt.logRetryAttempt(ctx, attempt, currentDelay, lastErr)
|
||||||
|
|
||||||
|
waitDuration := rrt.calculateWaitDurationWithJitter(ctx, currentDelay)
|
||||||
|
if err := rrt.waitForDelay(ctx, waitDuration); err != nil {
|
||||||
|
return nil, err // Context was canceled during wait.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exponential backoff for the next potential retry.
|
||||||
|
currentDelay = rrt.updateCurrentDelay(currentDelay)
|
||||||
|
|
||||||
|
// Retry attempt.
|
||||||
|
resp, lastErr = rrt.executeRequest(req)
|
||||||
|
if !rrt.shouldRetry(resp, lastErr) {
|
||||||
|
if lastErr != nil {
|
||||||
|
return resp, fmt.Errorf("request failed on retry attempt %d: %w", attempt, lastErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, rrt.handleFinalError(ctx, resp, lastErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// logRetryAttempt logs the details of a retry attempt.
|
||||||
|
func (rrt *RetryRoundTripper) logRetryAttempt(
|
||||||
|
ctx context.Context,
|
||||||
|
attempt int,
|
||||||
|
delay time.Duration,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
tflog.Info(
|
||||||
|
ctx, "Request failed, retrying...", map[string]interface{}{
|
||||||
|
"attempt": attempt,
|
||||||
|
"max_attempts": rrt.maxRetries,
|
||||||
|
"delay": delay,
|
||||||
|
"error": err,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateCurrentDelay calculates the next delay for exponential backoff.
|
||||||
|
func (rrt *RetryRoundTripper) updateCurrentDelay(currentDelay time.Duration) time.Duration {
|
||||||
|
currentDelay *= backoffMultiplier
|
||||||
|
if currentDelay > rrt.maxDelay {
|
||||||
|
return rrt.maxDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleFinalError constructs and returns the final error after all retries have been exhausted.
|
||||||
|
func (rrt *RetryRoundTripper) handleFinalError(
|
||||||
|
ctx context.Context,
|
||||||
|
resp *http.Response,
|
||||||
|
lastErr error,
|
||||||
|
) error {
|
||||||
|
if resp != nil {
|
||||||
|
if err := resp.Body.Close(); err != nil {
|
||||||
|
tflog.Warn(
|
||||||
|
ctx, "Failed to close response body", map[string]interface{}{
|
||||||
|
"error": err.Error(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if lastErr != nil {
|
||||||
|
return fmt.Errorf("%w: %w", ErrRequestFailedAfterRetries, lastErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This case occurs if shouldRetry was true due to a retryable status code,
|
||||||
|
// but all retries failed with similar status codes.
|
||||||
|
if resp != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"%w: last retry attempt failed with status code %d",
|
||||||
|
ErrRequestFailedAfterRetries,
|
||||||
|
resp.StatusCode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("%w: no response received", ErrRequestFailedAfterRetries)
|
||||||
|
}
|
||||||
|
|
||||||
|
// shouldRetry determines if a request should be retried based on the response or an error.
|
||||||
|
func (rrt *RetryRoundTripper) shouldRetry(resp *http.Response, err error) bool {
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp != nil {
|
||||||
|
if resp.StatusCode == http.StatusBadGateway ||
|
||||||
|
resp.StatusCode == http.StatusServiceUnavailable ||
|
||||||
|
resp.StatusCode == http.StatusGatewayTimeout {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculateWaitDurationWithJitter calculates the backoff duration for the next retry,
|
||||||
|
// adding a random jitter to prevent thundering herd issues.
|
||||||
|
func (rrt *RetryRoundTripper) calculateWaitDurationWithJitter(
|
||||||
|
ctx context.Context,
|
||||||
|
baseDelay time.Duration,
|
||||||
|
) time.Duration {
|
||||||
|
if baseDelay <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
maxJitter := int64(baseDelay / jitterFactor)
|
||||||
|
if maxJitter <= 0 {
|
||||||
|
return baseDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
random, err := rand.Int(rand.Reader, big.NewInt(maxJitter))
|
||||||
|
if err != nil {
|
||||||
|
tflog.Warn(
|
||||||
|
ctx, "Failed to generate random jitter, proceeding without it.", map[string]interface{}{
|
||||||
|
"error": err.Error(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return baseDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
jitter := time.Duration(random.Int64())
|
||||||
|
|
||||||
|
return baseDelay + jitter
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitForDelay pauses execution for a given duration or until the context is canceled.
|
||||||
|
func (rrt *RetryRoundTripper) waitForDelay(ctx context.Context, delay time.Duration) error {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return fmt.Errorf("context canceled during backoff wait: %w", ctx.Err())
|
||||||
|
case <-time.After(delay):
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
252
stackit/internal/core/retry_round_tripper_test.go
Normal file
252
stackit/internal/core/retry_round_tripper_test.go
Normal file
|
|
@ -0,0 +1,252 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mockRoundTripper struct {
|
||||||
|
roundTripFunc func(req *http.Request) (*http.Response, error)
|
||||||
|
callCount int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
atomic.AddInt32(&m.callCount, 1)
|
||||||
|
|
||||||
|
return m.roundTripFunc(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockRoundTripper) CallCount() int32 {
|
||||||
|
return atomic.LoadInt32(&m.callCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRetryRoundTripper_RoundTrip(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testRetryConfig := func(next http.RoundTripper) *RetryRoundTripper {
|
||||||
|
return NewRetryRoundTripper(
|
||||||
|
next,
|
||||||
|
3,
|
||||||
|
1*time.Millisecond,
|
||||||
|
10*time.Millisecond,
|
||||||
|
50*time.Millisecond,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
noRetryTests := []struct {
|
||||||
|
name string
|
||||||
|
mockStatusCode int
|
||||||
|
expectedStatusCode int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "should succeed on the first try",
|
||||||
|
mockStatusCode: http.StatusOK,
|
||||||
|
expectedStatusCode: http.StatusOK,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "should not retry on a non-retryable status code like 400",
|
||||||
|
mockStatusCode: http.StatusBadRequest,
|
||||||
|
expectedStatusCode: http.StatusBadRequest,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range noRetryTests {
|
||||||
|
t.Run(
|
||||||
|
testCase.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mock := &mockRoundTripper{
|
||||||
|
roundTripFunc: func(req *http.Request) (*http.Response, error) {
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: testCase.mockStatusCode,
|
||||||
|
Body: io.NopCloser(nil),
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
tripper := testRetryConfig(mock)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
|
||||||
|
|
||||||
|
resp, err := tripper.RoundTrip(req)
|
||||||
|
if resp != nil {
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
t.Errorf("failed to close response body: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != testCase.expectedStatusCode {
|
||||||
|
t.Fatalf("expected status code %d, got %d", testCase.expectedStatusCode, resp.StatusCode)
|
||||||
|
}
|
||||||
|
if mock.CallCount() != 1 {
|
||||||
|
t.Fatalf("expected 1 call, got %d", mock.CallCount())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run(
|
||||||
|
"should retry on retryable status code (503) and eventually fail", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mock := &mockRoundTripper{
|
||||||
|
roundTripFunc: func(req *http.Request) (*http.Response, error) {
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusServiceUnavailable,
|
||||||
|
Body: io.NopCloser(nil),
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
tripper := testRetryConfig(mock)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
|
||||||
|
|
||||||
|
resp, err := tripper.RoundTrip(req)
|
||||||
|
if resp != nil {
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
t.Errorf("failed to close response body: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error, but got nil")
|
||||||
|
}
|
||||||
|
expectedErrorMsg := "last retry attempt failed with status code 503"
|
||||||
|
if !strings.Contains(err.Error(), expectedErrorMsg) {
|
||||||
|
t.Fatalf("expected error to contain %q, got %q", expectedErrorMsg, err.Error())
|
||||||
|
}
|
||||||
|
if mock.CallCount() != 4 { // 1 initial + 3 retries
|
||||||
|
t.Fatalf("expected 4 calls, got %d", mock.CallCount())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Run(
|
||||||
|
"should succeed after one retry", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mock := &mockRoundTripper{}
|
||||||
|
mock.roundTripFunc = func(req *http.Request) (*http.Response, error) {
|
||||||
|
if mock.CallCount() < 2 {
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusServiceUnavailable,
|
||||||
|
Body: io.NopCloser(nil),
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
Body: io.NopCloser(nil),
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
tripper := testRetryConfig(mock)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
|
||||||
|
|
||||||
|
resp, err := tripper.RoundTrip(req)
|
||||||
|
if resp != nil {
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
t.Errorf("failed to close response body: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
t.Fatalf("expected status code %d, got %d", http.StatusOK, resp.StatusCode)
|
||||||
|
}
|
||||||
|
if mock.CallCount() != 2 {
|
||||||
|
t.Fatalf("expected 2 calls, got %d", mock.CallCount())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Run(
|
||||||
|
"should retry on network error", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mockErr := errors.New("simulated network error")
|
||||||
|
|
||||||
|
mock := &mockRoundTripper{
|
||||||
|
roundTripFunc: func(_ *http.Request) (*http.Response, error) {
|
||||||
|
return nil, mockErr
|
||||||
|
},
|
||||||
|
}
|
||||||
|
tripper := testRetryConfig(mock)
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
|
||||||
|
|
||||||
|
resp, err := tripper.RoundTrip(req)
|
||||||
|
if resp != nil {
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
t.Errorf("failed to close response body: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !errors.Is(err, mockErr) {
|
||||||
|
t.Fatalf("expected error to be %v, got %v", mockErr, err)
|
||||||
|
}
|
||||||
|
if mock.CallCount() != 4 { // 1 initial + 3 retries
|
||||||
|
t.Fatalf("expected 4 calls, got %d", mock.CallCount())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Run(
|
||||||
|
"should abort retries if the main context is canceled", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mock := &mockRoundTripper{
|
||||||
|
roundTripFunc: func(req *http.Request) (*http.Response, error) {
|
||||||
|
select {
|
||||||
|
case <-time.After(100 * time.Millisecond):
|
||||||
|
return nil, errors.New("this should not be returned")
|
||||||
|
case <-req.Context().Done():
|
||||||
|
return nil, req.Context().Err()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
tripper := testRetryConfig(mock)
|
||||||
|
baseCtx := context.Background()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(baseCtx, 20*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", http.NoBody).WithContext(ctx)
|
||||||
|
|
||||||
|
resp, err := tripper.RoundTrip(req)
|
||||||
|
if resp != nil {
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
t.Errorf("failed to close response body: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
t.Fatalf("expected error to be context.DeadlineExceeded, got %v", err)
|
||||||
|
}
|
||||||
|
if mock.CallCount() != 1 {
|
||||||
|
t.Fatalf("expected 1 call, got %d", mock.CallCount())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
|
|
||||||
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
|
|
||||||
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
|
|
||||||
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/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/core"
|
||||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
||||||
|
|
@ -72,7 +73,6 @@ func (r *databaseDataSource) Configure(
|
||||||
|
|
||||||
// Schema defines the schema for the data source.
|
// Schema defines the schema for the data source.
|
||||||
func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
|
||||||
s := postgresflexalpha2.DatabaseDataSourceSchema(ctx)
|
s := postgresflexalpha2.DatabaseDataSourceSchema(ctx)
|
||||||
s.Attributes["id"] = schema.StringAttribute{
|
s.Attributes["id"] = schema.StringAttribute{
|
||||||
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
|
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,6 @@ func DatabasesDataSourceSchema(ctx context.Context) schema.Schema {
|
||||||
"databases": schema.ListNestedAttribute{
|
"databases": schema.ListNestedAttribute{
|
||||||
NestedObject: schema.NestedAttributeObject{
|
NestedObject: schema.NestedAttributeObject{
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
"created": schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Description: "The data when the database was created in RFC3339 format.",
|
|
||||||
MarkdownDescription: "The data when the database was created in RFC3339 format.",
|
|
||||||
},
|
|
||||||
"id": schema.Int64Attribute{
|
"id": schema.Int64Attribute{
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "The id of the database.",
|
Description: "The id of the database.",
|
||||||
|
|
@ -169,24 +164,6 @@ func (t DatabasesType) ValueFromObject(ctx context.Context, in basetypes.ObjectV
|
||||||
|
|
||||||
attributes := in.Attributes()
|
attributes := in.Attributes()
|
||||||
|
|
||||||
createdAttribute, ok := attributes["created"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`created is missing from object`)
|
|
||||||
|
|
||||||
return nil, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
createdVal, ok := createdAttribute.(basetypes.StringValue)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute))
|
|
||||||
}
|
|
||||||
|
|
||||||
idAttribute, ok := attributes["id"]
|
idAttribute, ok := attributes["id"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -246,11 +223,10 @@ func (t DatabasesType) ValueFromObject(ctx context.Context, in basetypes.ObjectV
|
||||||
}
|
}
|
||||||
|
|
||||||
return DatabasesValue{
|
return DatabasesValue{
|
||||||
Created: createdVal,
|
Id: idVal,
|
||||||
Id: idVal,
|
Name: nameVal,
|
||||||
Name: nameVal,
|
Owner: ownerVal,
|
||||||
Owner: ownerVal,
|
state: attr.ValueStateKnown,
|
||||||
state: attr.ValueStateKnown,
|
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,24 +293,6 @@ func NewDatabasesValue(attributeTypes map[string]attr.Type, attributes map[strin
|
||||||
return NewDatabasesValueUnknown(), diags
|
return NewDatabasesValueUnknown(), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
createdAttribute, ok := attributes["created"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`created is missing from object`)
|
|
||||||
|
|
||||||
return NewDatabasesValueUnknown(), diags
|
|
||||||
}
|
|
||||||
|
|
||||||
createdVal, ok := createdAttribute.(basetypes.StringValue)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute))
|
|
||||||
}
|
|
||||||
|
|
||||||
idAttribute, ok := attributes["id"]
|
idAttribute, ok := attributes["id"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -394,11 +352,10 @@ func NewDatabasesValue(attributeTypes map[string]attr.Type, attributes map[strin
|
||||||
}
|
}
|
||||||
|
|
||||||
return DatabasesValue{
|
return DatabasesValue{
|
||||||
Created: createdVal,
|
Id: idVal,
|
||||||
Id: idVal,
|
Name: nameVal,
|
||||||
Name: nameVal,
|
Owner: ownerVal,
|
||||||
Owner: ownerVal,
|
state: attr.ValueStateKnown,
|
||||||
state: attr.ValueStateKnown,
|
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,20 +427,18 @@ func (t DatabasesType) ValueType(ctx context.Context) attr.Value {
|
||||||
var _ basetypes.ObjectValuable = DatabasesValue{}
|
var _ basetypes.ObjectValuable = DatabasesValue{}
|
||||||
|
|
||||||
type DatabasesValue struct {
|
type DatabasesValue struct {
|
||||||
Created basetypes.StringValue `tfsdk:"created"`
|
Id basetypes.Int64Value `tfsdk:"id"`
|
||||||
Id basetypes.Int64Value `tfsdk:"id"`
|
Name basetypes.StringValue `tfsdk:"name"`
|
||||||
Name basetypes.StringValue `tfsdk:"name"`
|
Owner basetypes.StringValue `tfsdk:"owner"`
|
||||||
Owner basetypes.StringValue `tfsdk:"owner"`
|
state attr.ValueState
|
||||||
state attr.ValueState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||||
attrTypes := make(map[string]tftypes.Type, 4)
|
attrTypes := make(map[string]tftypes.Type, 3)
|
||||||
|
|
||||||
var val tftypes.Value
|
var val tftypes.Value
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
attrTypes["created"] = basetypes.StringType{}.TerraformType(ctx)
|
|
||||||
attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx)
|
attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx)
|
||||||
attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx)
|
attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx)
|
||||||
attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx)
|
attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx)
|
||||||
|
|
@ -492,15 +447,7 @@ func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, er
|
||||||
|
|
||||||
switch v.state {
|
switch v.state {
|
||||||
case attr.ValueStateKnown:
|
case attr.ValueStateKnown:
|
||||||
vals := make(map[string]tftypes.Value, 4)
|
vals := make(map[string]tftypes.Value, 3)
|
||||||
|
|
||||||
val, err = v.Created.ToTerraformValue(ctx)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
|
||||||
}
|
|
||||||
|
|
||||||
vals["created"] = val
|
|
||||||
|
|
||||||
val, err = v.Id.ToTerraformValue(ctx)
|
val, err = v.Id.ToTerraformValue(ctx)
|
||||||
|
|
||||||
|
|
@ -556,10 +503,9 @@ func (v DatabasesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValu
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
attributeTypes := map[string]attr.Type{
|
attributeTypes := map[string]attr.Type{
|
||||||
"created": basetypes.StringType{},
|
"id": basetypes.Int64Type{},
|
||||||
"id": basetypes.Int64Type{},
|
"name": basetypes.StringType{},
|
||||||
"name": basetypes.StringType{},
|
"owner": basetypes.StringType{},
|
||||||
"owner": basetypes.StringType{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.IsNull() {
|
if v.IsNull() {
|
||||||
|
|
@ -573,10 +519,9 @@ func (v DatabasesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValu
|
||||||
objVal, diags := types.ObjectValue(
|
objVal, diags := types.ObjectValue(
|
||||||
attributeTypes,
|
attributeTypes,
|
||||||
map[string]attr.Value{
|
map[string]attr.Value{
|
||||||
"created": v.Created,
|
"id": v.Id,
|
||||||
"id": v.Id,
|
"name": v.Name,
|
||||||
"name": v.Name,
|
"owner": v.Owner,
|
||||||
"owner": v.Owner,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return objVal, diags
|
return objVal, diags
|
||||||
|
|
@ -597,10 +542,6 @@ func (v DatabasesValue) Equal(o attr.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !v.Created.Equal(other.Created) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if !v.Id.Equal(other.Id) {
|
if !v.Id.Equal(other.Id) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -626,10 +567,9 @@ func (v DatabasesValue) Type(ctx context.Context) attr.Type {
|
||||||
|
|
||||||
func (v DatabasesValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
func (v DatabasesValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||||
return map[string]attr.Type{
|
return map[string]attr.Type{
|
||||||
"created": basetypes.StringType{},
|
"id": basetypes.Int64Type{},
|
||||||
"id": basetypes.Int64Type{},
|
"name": basetypes.StringType{},
|
||||||
"name": basetypes.StringType{},
|
"owner": basetypes.StringType{},
|
||||||
"owner": basetypes.StringType{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"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/pkg_gen/postgresflexalpha"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -51,8 +52,8 @@ func mapFields(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapResourceFields maps fields from a ListDatabase API response to a resourceModel for the resource.
|
// mapResourceFields maps fields from a GetDatabase API response to a resourceModel for the resource.
|
||||||
func mapResourceFields(source *postgresflexalpha.ListDatabase, model *resourceModel) error {
|
func mapResourceFields(source *postgresflexalpha.GetDatabaseResponse, model *resourceModel) error {
|
||||||
if source == nil {
|
if source == nil {
|
||||||
return fmt.Errorf("response is nil")
|
return fmt.Errorf("response is nil")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
|
|
||||||
"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/pkg_gen/postgresflexalpha"
|
||||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
|
||||||
)
|
)
|
||||||
|
|
@ -34,7 +35,12 @@ func TestMapFields(t *testing.T) {
|
||||||
Name: utils.Ptr("my-db"),
|
Name: utils.Ptr("my-db"),
|
||||||
Owner: utils.Ptr("\"my-owner\""),
|
Owner: utils.Ptr("\"my-owner\""),
|
||||||
},
|
},
|
||||||
model: &dataSourceModel{},
|
model: &dataSourceModel{
|
||||||
|
DatabaseModel: datasource.DatabaseModel{
|
||||||
|
ProjectId: types.StringValue("my-project"),
|
||||||
|
InstanceId: types.StringValue("my-instance"),
|
||||||
|
},
|
||||||
|
},
|
||||||
region: "eu01",
|
region: "eu01",
|
||||||
},
|
},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
|
|
@ -127,7 +133,7 @@ func TestMapFields(t *testing.T) {
|
||||||
|
|
||||||
func TestMapResourceFields(t *testing.T) {
|
func TestMapResourceFields(t *testing.T) {
|
||||||
type given struct {
|
type given struct {
|
||||||
source *postgresflexalpha.ListDatabase
|
source *postgresflexalpha.GetDatabaseResponse
|
||||||
model *resourceModel
|
model *resourceModel
|
||||||
}
|
}
|
||||||
type expected struct {
|
type expected struct {
|
||||||
|
|
@ -143,10 +149,10 @@ func TestMapResourceFields(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "should map fields correctly",
|
name: "should map fields correctly",
|
||||||
given: given{
|
given: given{
|
||||||
source: &postgresflexalpha.ListDatabase{
|
source: &postgresflexalpha.GetDatabaseResponse{
|
||||||
Id: utils.Ptr(int64(1)),
|
Id: utils.Ptr(int64(1)),
|
||||||
Name: utils.Ptr("my-db"),
|
Name: utils.Ptr("my-db"),
|
||||||
Owner: utils.Ptr("\"my-owner\""),
|
Owner: utils.Ptr("my-owner"),
|
||||||
},
|
},
|
||||||
model: &resourceModel{},
|
model: &resourceModel{},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,25 @@ package postgresflexalpha
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/postgresflexalpha"
|
"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/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/core"
|
||||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/resources_gen"
|
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/resources_gen"
|
||||||
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
|
postgresflexalpha3 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/postgresflexalpha"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -32,9 +32,6 @@ var (
|
||||||
_ resource.ResourceWithModifyPlan = &databaseResource{}
|
_ resource.ResourceWithModifyPlan = &databaseResource{}
|
||||||
_ resource.ResourceWithIdentity = &databaseResource{}
|
_ resource.ResourceWithIdentity = &databaseResource{}
|
||||||
|
|
||||||
// Define errors
|
|
||||||
errDatabaseNotFound = errors.New("database not found")
|
|
||||||
|
|
||||||
// Error message constants
|
// Error message constants
|
||||||
extractErrorSummary = "extracting failed"
|
extractErrorSummary = "extracting failed"
|
||||||
extractErrorMessage = "Extracting identity data: %v"
|
extractErrorMessage = "Extracting identity data: %v"
|
||||||
|
|
@ -171,6 +168,7 @@ func (r *databaseResource) Create(
|
||||||
req resource.CreateRequest,
|
req resource.CreateRequest,
|
||||||
resp *resource.CreateResponse,
|
resp *resource.CreateResponse,
|
||||||
) { // nolint:gocritic // function signature required by Terraform
|
) { // nolint:gocritic // function signature required by Terraform
|
||||||
|
const funcErrorSummary = "[database CREATE] error"
|
||||||
var model resourceModel
|
var model resourceModel
|
||||||
diags := req.Plan.Get(ctx, &model)
|
diags := req.Plan.Get(ctx, &model)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
@ -178,18 +176,11 @@ func (r *databaseResource) Create(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData DatabaseResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := identityData.ProjectID.ValueString()
|
projectId := model.ProjectId.ValueString()
|
||||||
region := identityData.ProjectID.ValueString()
|
region := model.Region.ValueString()
|
||||||
instanceId := identityData.InstanceID.ValueString()
|
instanceId := model.InstanceId.ValueString()
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
@ -201,7 +192,7 @@ func (r *databaseResource) Create(
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
"Error creating database",
|
funcErrorSummary,
|
||||||
fmt.Sprintf("Creating API payload: %v", err),
|
fmt.Sprintf("Creating API payload: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
@ -214,30 +205,44 @@ func (r *databaseResource) Create(
|
||||||
instanceId,
|
instanceId,
|
||||||
).CreateDatabaseRequestPayload(*payload).Execute()
|
).CreateDatabaseRequestPayload(*payload).Execute()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
|
||||||
|
|
||||||
if databaseResp == nil || databaseResp.Id == nil {
|
if databaseResp == nil || databaseResp.Id == nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
"Error creating database",
|
funcErrorSummary,
|
||||||
"API didn't return database Id. A database might have been created",
|
"API didn't return database Id. A database might have been created",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
databaseId := *databaseResp.Id
|
databaseId := *databaseResp.Id
|
||||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||||
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
database, err := getDatabaseById(ctx, r.client, projectId, region, instanceId, databaseId)
|
// Save identity into Terraform state
|
||||||
|
identity := DatabaseResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(projectId),
|
||||||
|
Region: types.StringValue(region),
|
||||||
|
InstanceID: types.StringValue(instanceId),
|
||||||
|
DatabaseID: types.Int64Value(databaseId),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
database, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId).
|
||||||
|
SetTimeout(15 * time.Minute).
|
||||||
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
|
WaitWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
"Error creating database",
|
funcErrorSummary,
|
||||||
fmt.Sprintf("Getting database details after creation: %v", err),
|
fmt.Sprintf("Getting database details after creation: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
@ -249,24 +254,12 @@ func (r *databaseResource) Create(
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
"Error creating database",
|
funcErrorSummary,
|
||||||
fmt.Sprintf("Processing API payload: %v", err),
|
fmt.Sprintf("map resource fields: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set data returned by API in identity
|
|
||||||
identity := DatabaseResourceIdentityModel{
|
|
||||||
ProjectID: types.StringValue(projectId),
|
|
||||||
Region: types.StringValue(region),
|
|
||||||
InstanceID: types.StringValue(instanceId),
|
|
||||||
DatabaseID: types.Int64Value(databaseId),
|
|
||||||
}
|
|
||||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set state to fully populated data
|
// Set state to fully populated data
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, model)...)
|
resp.Diagnostics.Append(resp.State.Set(ctx, model)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
|
|
@ -288,38 +281,29 @@ func (r *databaseResource) Read(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData DatabaseResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, instanceId, region, databaseId, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
instanceId := model.InstanceId.ValueString()
|
||||||
core.LogAndAddError(
|
region := model.Region.ValueString()
|
||||||
ctx,
|
databaseId := model.DatabaseId.ValueInt64()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||||
|
|
||||||
databaseResp, err := getDatabaseById(ctx, r.client, projectId, region, instanceId, databaseId)
|
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId).
|
||||||
|
SetTimeout(15 * time.Minute).
|
||||||
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
|
WaitWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
core.LogAndAddError(
|
||||||
if (ok && oapiErr.StatusCode == http.StatusNotFound) || errors.Is(err, errDatabaseNotFound) {
|
ctx,
|
||||||
resp.State.RemoveResource(ctx)
|
&resp.Diagnostics,
|
||||||
return
|
"Error creating database",
|
||||||
}
|
fmt.Sprintf("Getting database details after creation: %v", err),
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading database", fmt.Sprintf("Calling API: %v", err))
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,6 +321,19 @@ func (r *databaseResource) Read(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: use values from api to identify drift
|
||||||
|
// Save identity into Terraform state
|
||||||
|
identity := DatabaseResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(projectId),
|
||||||
|
Region: types.StringValue(region),
|
||||||
|
InstanceID: types.StringValue(instanceId),
|
||||||
|
DatabaseID: types.Int64Value(databaseId),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set refreshed state
|
// Set refreshed state
|
||||||
diags = resp.State.Set(ctx, model)
|
diags = resp.State.Set(ctx, model)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
@ -359,30 +356,18 @@ func (r *databaseResource) Update(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData DatabaseResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, instanceId, region, databaseId64, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
instanceId := model.InstanceId.ValueString()
|
||||||
core.LogAndAddError(
|
region := model.Region.ValueString()
|
||||||
ctx,
|
databaseId64 := model.DatabaseId.ValueInt64()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if databaseId64 > math.MaxInt32 {
|
if databaseId64 > math.MaxInt32 {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
databaseId := int32(databaseId64)
|
databaseId := int32(databaseId64) // nolint:gosec // check is performed above
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
@ -415,7 +400,7 @@ func (r *databaseResource) Update(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update existing database
|
// Update existing database
|
||||||
res, err := r.client.UpdateDatabasePartiallyRequest(
|
err := r.client.UpdateDatabasePartiallyRequest(
|
||||||
ctx,
|
ctx,
|
||||||
projectId,
|
projectId,
|
||||||
region,
|
region,
|
||||||
|
|
@ -429,20 +414,43 @@ func (r *databaseResource) Update(
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
|
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId64).
|
||||||
|
SetTimeout(15 * time.Minute).
|
||||||
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
|
WaitWithContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
core.LogAndAddError(ctx, &resp.Diagnostics, "error updating database", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
// Map response body to schema
|
// Map response body to schema
|
||||||
err = mapResourceFields(res.Database, &model)
|
err = mapResourceFields(databaseResp, &model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
"Error updating database",
|
"Error reading database",
|
||||||
fmt.Sprintf("Processing API payload: %v", err),
|
fmt.Sprintf("Processing API payload: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save identity into Terraform state
|
||||||
|
identity := DatabaseResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(projectId),
|
||||||
|
Region: types.StringValue(region),
|
||||||
|
InstanceID: types.StringValue(instanceId),
|
||||||
|
DatabaseID: types.Int64Value(databaseId64),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set state to fully populated data
|
// Set state to fully populated data
|
||||||
diags = resp.State.Set(ctx, model)
|
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...)
|
||||||
resp.Diagnostics.Append(diags...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -471,7 +479,7 @@ func (r *databaseResource) Delete(
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, instanceId, region, databaseId64, errExt := r.extractIdentityData(model, identityData)
|
projectId, region, instanceId, databaseId64, errExt := r.extractIdentityData(model, identityData)
|
||||||
if errExt != nil {
|
if errExt != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -485,7 +493,7 @@ func (r *databaseResource) Delete(
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
databaseId := int32(databaseId64)
|
databaseId := int32(databaseId64) // nolint:gosec // check is performed above
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
@ -509,11 +517,9 @@ func (r *databaseResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
"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/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/conversion"
|
||||||
postgresflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors/datasources_gen"
|
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-framework/datasource"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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-framework/datasource"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/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/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/core"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"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/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/conversion"
|
||||||
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
|
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-framework/datasource"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/core"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -33,15 +33,27 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
|
||||||
},
|
},
|
||||||
"connection_info": schema.SingleNestedAttribute{
|
"connection_info": schema.SingleNestedAttribute{
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
"host": schema.StringAttribute{
|
"write": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"host": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
Description: "The host of the instance.",
|
||||||
|
MarkdownDescription: "The host of the instance.",
|
||||||
|
},
|
||||||
|
"port": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
Description: "The port of the instance.",
|
||||||
|
MarkdownDescription: "The port of the instance.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CustomType: WriteType{
|
||||||
|
ObjectType: types.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
},
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "The host of the instance.",
|
Description: "The DNS name and port in the instance overview",
|
||||||
MarkdownDescription: "The host of the instance.",
|
MarkdownDescription: "The DNS name and port in the instance overview",
|
||||||
},
|
|
||||||
"port": schema.Int64Attribute{
|
|
||||||
Computed: true,
|
|
||||||
Description: "The port of the instance.",
|
|
||||||
MarkdownDescription: "The port of the instance.",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CustomType: ConnectionInfoType{
|
CustomType: ConnectionInfoType{
|
||||||
|
|
@ -50,8 +62,8 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "The DNS name and port in the instance overview",
|
Description: "The connection information of the instance",
|
||||||
MarkdownDescription: "The DNS name and port in the instance overview",
|
MarkdownDescription: "The connection information of the instance",
|
||||||
},
|
},
|
||||||
"encryption": schema.SingleNestedAttribute{
|
"encryption": schema.SingleNestedAttribute{
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
|
|
@ -243,40 +255,22 @@ func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.Ob
|
||||||
|
|
||||||
attributes := in.Attributes()
|
attributes := in.Attributes()
|
||||||
|
|
||||||
hostAttribute, ok := attributes["host"]
|
writeAttribute, ok := attributes["write"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Missing",
|
"Attribute Missing",
|
||||||
`host is missing from object`)
|
`write is missing from object`)
|
||||||
|
|
||||||
return nil, diags
|
return nil, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
writeVal, ok := writeAttribute.(basetypes.ObjectValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Wrong Type",
|
"Attribute Wrong Type",
|
||||||
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
fmt.Sprintf(`write expected to be basetypes.ObjectValue, was: %T`, writeAttribute))
|
||||||
}
|
|
||||||
|
|
||||||
portAttribute, ok := attributes["port"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`port is missing from object`)
|
|
||||||
|
|
||||||
return nil, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
portVal, ok := portAttribute.(basetypes.Int64Value)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
@ -284,8 +278,7 @@ func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.Ob
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConnectionInfoValue{
|
return ConnectionInfoValue{
|
||||||
Host: hostVal,
|
Write: writeVal,
|
||||||
Port: portVal,
|
|
||||||
state: attr.ValueStateKnown,
|
state: attr.ValueStateKnown,
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
@ -353,40 +346,22 @@ func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
return NewConnectionInfoValueUnknown(), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostAttribute, ok := attributes["host"]
|
writeAttribute, ok := attributes["write"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Missing",
|
"Attribute Missing",
|
||||||
`host is missing from object`)
|
`write is missing from object`)
|
||||||
|
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
return NewConnectionInfoValueUnknown(), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
writeVal, ok := writeAttribute.(basetypes.ObjectValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Wrong Type",
|
"Attribute Wrong Type",
|
||||||
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
fmt.Sprintf(`write expected to be basetypes.ObjectValue, was: %T`, writeAttribute))
|
||||||
}
|
|
||||||
|
|
||||||
portAttribute, ok := attributes["port"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`port is missing from object`)
|
|
||||||
|
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
|
||||||
}
|
|
||||||
|
|
||||||
portVal, ok := portAttribute.(basetypes.Int64Value)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
@ -394,8 +369,7 @@ func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConnectionInfoValue{
|
return ConnectionInfoValue{
|
||||||
Host: hostVal,
|
Write: writeVal,
|
||||||
Port: portVal,
|
|
||||||
state: attr.ValueStateKnown,
|
state: attr.ValueStateKnown,
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
@ -468,12 +442,401 @@ func (t ConnectionInfoType) ValueType(ctx context.Context) attr.Value {
|
||||||
var _ basetypes.ObjectValuable = ConnectionInfoValue{}
|
var _ basetypes.ObjectValuable = ConnectionInfoValue{}
|
||||||
|
|
||||||
type ConnectionInfoValue struct {
|
type ConnectionInfoValue struct {
|
||||||
|
Write basetypes.ObjectValue `tfsdk:"write"`
|
||||||
|
state attr.ValueState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||||
|
attrTypes := make(map[string]tftypes.Type, 1)
|
||||||
|
|
||||||
|
var val tftypes.Value
|
||||||
|
var err error
|
||||||
|
|
||||||
|
attrTypes["write"] = basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
}.TerraformType(ctx)
|
||||||
|
|
||||||
|
objectType := tftypes.Object{AttributeTypes: attrTypes}
|
||||||
|
|
||||||
|
switch v.state {
|
||||||
|
case attr.ValueStateKnown:
|
||||||
|
vals := make(map[string]tftypes.Value, 1)
|
||||||
|
|
||||||
|
val, err = v.Write.ToTerraformValue(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||||
|
}
|
||||||
|
|
||||||
|
vals["write"] = val
|
||||||
|
|
||||||
|
if err := tftypes.ValidateValue(objectType, vals); err != nil {
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tftypes.NewValue(objectType, vals), nil
|
||||||
|
case attr.ValueStateNull:
|
||||||
|
return tftypes.NewValue(objectType, nil), nil
|
||||||
|
case attr.ValueStateUnknown:
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), nil
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) IsNull() bool {
|
||||||
|
return v.state == attr.ValueStateNull
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) IsUnknown() bool {
|
||||||
|
return v.state == attr.ValueStateUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) String() string {
|
||||||
|
return "ConnectionInfoValue"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
var write basetypes.ObjectValue
|
||||||
|
|
||||||
|
if v.Write.IsNull() {
|
||||||
|
write = types.ObjectNull(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Write.IsUnknown() {
|
||||||
|
write = types.ObjectUnknown(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !v.Write.IsNull() && !v.Write.IsUnknown() {
|
||||||
|
write = types.ObjectValueMust(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
v.Write.Attributes(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeTypes := map[string]attr.Type{
|
||||||
|
"write": basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsNull() {
|
||||||
|
return types.ObjectNull(attributeTypes), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsUnknown() {
|
||||||
|
return types.ObjectUnknown(attributeTypes), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
objVal, diags := types.ObjectValue(
|
||||||
|
attributeTypes,
|
||||||
|
map[string]attr.Value{
|
||||||
|
"write": write,
|
||||||
|
})
|
||||||
|
|
||||||
|
return objVal, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
||||||
|
other, ok := o.(ConnectionInfoValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.state != other.state {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.state != attr.ValueStateKnown {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !v.Write.Equal(other.Write) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type {
|
||||||
|
return ConnectionInfoType{
|
||||||
|
basetypes.ObjectType{
|
||||||
|
AttrTypes: v.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||||
|
return map[string]attr.Type{
|
||||||
|
"write": basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ basetypes.ObjectTypable = WriteType{}
|
||||||
|
|
||||||
|
type WriteType struct {
|
||||||
|
basetypes.ObjectType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) Equal(o attr.Type) bool {
|
||||||
|
other, ok := o.(WriteType)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.ObjectType.Equal(other.ObjectType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) String() string {
|
||||||
|
return "WriteType"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
attributes := in.Attributes()
|
||||||
|
|
||||||
|
hostAttribute, ok := attributes["host"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`host is missing from object`)
|
||||||
|
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
portAttribute, ok := attributes["port"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`port is missing from object`)
|
||||||
|
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
portVal, ok := portAttribute.(basetypes.Int64Value)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteValue{
|
||||||
|
Host: hostVal,
|
||||||
|
Port: portVal,
|
||||||
|
state: attr.ValueStateKnown,
|
||||||
|
}, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueNull() WriteValue {
|
||||||
|
return WriteValue{
|
||||||
|
state: attr.ValueStateNull,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueUnknown() WriteValue {
|
||||||
|
return WriteValue{
|
||||||
|
state: attr.ValueStateUnknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (WriteValue, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
for name, attributeType := range attributeTypes {
|
||||||
|
attribute, ok := attributes[name]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Missing WriteValue Attribute Value",
|
||||||
|
"While creating a WriteValue value, a missing attribute value was detected. "+
|
||||||
|
"A WriteValue must contain values for all attributes, even if null or unknown. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()),
|
||||||
|
)
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !attributeType.Equal(attribute.Type(ctx)) {
|
||||||
|
diags.AddError(
|
||||||
|
"Invalid WriteValue Attribute Type",
|
||||||
|
"While creating a WriteValue value, an invalid attribute value was detected. "+
|
||||||
|
"A WriteValue must use a matching attribute type for the value. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for name := range attributes {
|
||||||
|
_, ok := attributeTypes[name]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Extra WriteValue Attribute Value",
|
||||||
|
"While creating a WriteValue value, an extra attribute value was detected. "+
|
||||||
|
"A WriteValue must not contain values beyond the expected attribute types. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("Extra WriteValue Attribute Name: %s", name),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostAttribute, ok := attributes["host"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`host is missing from object`)
|
||||||
|
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
portAttribute, ok := attributes["port"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`port is missing from object`)
|
||||||
|
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
portVal, ok := portAttribute.(basetypes.Int64Value)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteValue{
|
||||||
|
Host: hostVal,
|
||||||
|
Port: portVal,
|
||||||
|
state: attr.ValueStateKnown,
|
||||||
|
}, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) WriteValue {
|
||||||
|
object, diags := NewWriteValue(attributeTypes, attributes)
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
// This could potentially be added to the diag package.
|
||||||
|
diagsStrings := make([]string, 0, len(diags))
|
||||||
|
|
||||||
|
for _, diagnostic := range diags {
|
||||||
|
diagsStrings = append(diagsStrings, fmt.Sprintf(
|
||||||
|
"%s | %s | %s",
|
||||||
|
diagnostic.Severity(),
|
||||||
|
diagnostic.Summary(),
|
||||||
|
diagnostic.Detail()))
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("NewWriteValueMust received error(s): " + strings.Join(diagsStrings, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return object
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
|
||||||
|
if in.Type() == nil {
|
||||||
|
return NewWriteValueNull(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.Type().Equal(t.TerraformType(ctx)) {
|
||||||
|
return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.IsKnown() {
|
||||||
|
return NewWriteValueUnknown(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.IsNull() {
|
||||||
|
return NewWriteValueNull(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes := map[string]attr.Value{}
|
||||||
|
|
||||||
|
val := map[string]tftypes.Value{}
|
||||||
|
|
||||||
|
err := in.As(&val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range val {
|
||||||
|
a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes[k] = a
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewWriteValueMust(WriteValue{}.AttributeTypes(ctx), attributes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueType(ctx context.Context) attr.Value {
|
||||||
|
return WriteValue{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ basetypes.ObjectValuable = WriteValue{}
|
||||||
|
|
||||||
|
type WriteValue struct {
|
||||||
Host basetypes.StringValue `tfsdk:"host"`
|
Host basetypes.StringValue `tfsdk:"host"`
|
||||||
Port basetypes.Int64Value `tfsdk:"port"`
|
Port basetypes.Int64Value `tfsdk:"port"`
|
||||||
state attr.ValueState
|
state attr.ValueState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
func (v WriteValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||||
attrTypes := make(map[string]tftypes.Type, 2)
|
attrTypes := make(map[string]tftypes.Type, 2)
|
||||||
|
|
||||||
var val tftypes.Value
|
var val tftypes.Value
|
||||||
|
|
@ -518,19 +881,19 @@ func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Valu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) IsNull() bool {
|
func (v WriteValue) IsNull() bool {
|
||||||
return v.state == attr.ValueStateNull
|
return v.state == attr.ValueStateNull
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) IsUnknown() bool {
|
func (v WriteValue) IsUnknown() bool {
|
||||||
return v.state == attr.ValueStateUnknown
|
return v.state == attr.ValueStateUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) String() string {
|
func (v WriteValue) String() string {
|
||||||
return "ConnectionInfoValue"
|
return "WriteValue"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
func (v WriteValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
attributeTypes := map[string]attr.Type{
|
attributeTypes := map[string]attr.Type{
|
||||||
|
|
@ -556,8 +919,8 @@ func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.Objec
|
||||||
return objVal, diags
|
return objVal, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
func (v WriteValue) Equal(o attr.Value) bool {
|
||||||
other, ok := o.(ConnectionInfoValue)
|
other, ok := o.(WriteValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
|
|
@ -582,15 +945,15 @@ func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type {
|
func (v WriteValue) Type(ctx context.Context) attr.Type {
|
||||||
return ConnectionInfoType{
|
return WriteType{
|
||||||
basetypes.ObjectType{
|
basetypes.ObjectType{
|
||||||
AttrTypes: v.AttributeTypes(ctx),
|
AttrTypes: v.AttributeTypes(ctx),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
func (v WriteValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||||
return map[string]attr.Type{
|
return map[string]attr.Type{
|
||||||
"host": basetypes.StringType{},
|
"host": basetypes.StringType{},
|
||||||
"port": basetypes.Int64Type{},
|
"port": basetypes.Int64Type{},
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
"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"
|
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"
|
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"
|
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
|
||||||
|
|
@ -19,28 +19,6 @@ func mapGetInstanceResponseToModel(
|
||||||
m *postgresflexalpharesource.InstanceModel,
|
m *postgresflexalpharesource.InstanceModel,
|
||||||
resp *postgresflex.GetInstanceResponse,
|
resp *postgresflex.GetInstanceResponse,
|
||||||
) error {
|
) error {
|
||||||
tflog.Debug(
|
|
||||||
ctx, ">>>> MSH DEBUG <<<<", map[string]interface{}{
|
|
||||||
"id": m.Id.ValueString(),
|
|
||||||
"instance_id": m.InstanceId.ValueString(),
|
|
||||||
"backup_schedule": m.BackupSchedule.ValueString(),
|
|
||||||
"flavor_id": m.FlavorId.ValueString(),
|
|
||||||
"encryption.kek_key_id": m.Encryption.KekKeyId.ValueString(),
|
|
||||||
"encryption.kek_key_ring_id": m.Encryption.KekKeyRingId.ValueString(),
|
|
||||||
"encryption.kek_key_version": m.Encryption.KekKeyVersion.ValueString(),
|
|
||||||
"encryption.service_account": m.Encryption.ServiceAccount.ValueString(),
|
|
||||||
"is_deletable": m.IsDeletable.ValueBool(),
|
|
||||||
"name": m.Name.ValueString(),
|
|
||||||
"status": m.Status.ValueString(),
|
|
||||||
"retention_days": m.RetentionDays.ValueInt64(),
|
|
||||||
"replicas": m.Replicas.ValueInt64(),
|
|
||||||
"network.instance_address": m.Network.InstanceAddress.ValueString(),
|
|
||||||
"network.router_address": m.Network.RouterAddress.ValueString(),
|
|
||||||
"version": m.Version.ValueString(),
|
|
||||||
"network.acl": m.Network.Acl.String(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||||
m.Encryption = postgresflexalpharesource.NewEncryptionValueNull()
|
m.Encryption = postgresflexalpharesource.NewEncryptionValueNull()
|
||||||
if resp.HasEncryption() {
|
if resp.HasEncryption() {
|
||||||
|
|
@ -55,14 +33,25 @@ func mapGetInstanceResponseToModel(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.ConnectionInfo.Host = types.StringValue("")
|
isConnectionInfoIncomplete := resp.ConnectionInfo == nil || resp.ConnectionInfo.Write == nil ||
|
||||||
if host, ok := resp.ConnectionInfo.GetHostOk(); ok {
|
resp.ConnectionInfo.Write.Host == nil || *resp.ConnectionInfo.Write.Host == "" ||
|
||||||
m.ConnectionInfo.Host = types.StringValue(host)
|
resp.ConnectionInfo.Write.Port == nil || *resp.ConnectionInfo.Write.Port == 0
|
||||||
}
|
|
||||||
|
|
||||||
m.ConnectionInfo.Port = types.Int64Value(0)
|
if isConnectionInfoIncomplete {
|
||||||
if port, ok := resp.ConnectionInfo.GetPortOk(); ok {
|
m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueNull()
|
||||||
m.ConnectionInfo.Port = types.Int64Value(port)
|
} else {
|
||||||
|
m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueMust(
|
||||||
|
postgresflexalpharesource.ConnectionInfoValue{}.AttributeTypes(ctx),
|
||||||
|
map[string]attr.Value{
|
||||||
|
"write": postgresflexalpharesource.NewWriteValueMust(
|
||||||
|
postgresflexalpharesource.WriteValue{}.AttributeTypes(ctx),
|
||||||
|
map[string]attr.Value{
|
||||||
|
"host": types.StringPointerValue(resp.ConnectionInfo.Write.Host),
|
||||||
|
"port": types.Int64PointerValue(resp.ConnectionInfo.Write.Port),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||||
|
|
@ -138,8 +127,8 @@ func mapGetDataInstanceResponseToModel(
|
||||||
) error {
|
) error {
|
||||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||||
handleEncryption(m, resp)
|
handleEncryption(m, resp)
|
||||||
m.ConnectionInfo.Host = types.StringValue(resp.ConnectionInfo.GetHost())
|
handleConnectionInfo(ctx, m, resp)
|
||||||
m.ConnectionInfo.Port = types.Int64Value(resp.ConnectionInfo.GetPort())
|
|
||||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
||||||
m.InstanceId = types.StringPointerValue(resp.Id)
|
m.InstanceId = types.StringPointerValue(resp.Id)
|
||||||
|
|
@ -169,6 +158,29 @@ func mapGetDataInstanceResponseToModel(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) {
|
||||||
|
isConnectionInfoIncomplete := resp.ConnectionInfo == nil || resp.ConnectionInfo.Write == nil ||
|
||||||
|
resp.ConnectionInfo.Write.Host == nil || *resp.ConnectionInfo.Write.Host == "" ||
|
||||||
|
resp.ConnectionInfo.Write.Port == nil || *resp.ConnectionInfo.Write.Port == 0
|
||||||
|
|
||||||
|
if isConnectionInfoIncomplete {
|
||||||
|
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueNull()
|
||||||
|
} else {
|
||||||
|
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueMust(
|
||||||
|
postgresflexalphadatasource.ConnectionInfoValue{}.AttributeTypes(ctx),
|
||||||
|
map[string]attr.Value{
|
||||||
|
"write": postgresflexalphadatasource.NewWriteValueMust(
|
||||||
|
postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx),
|
||||||
|
map[string]attr.Value{
|
||||||
|
"host": types.StringPointerValue(resp.ConnectionInfo.Write.Host),
|
||||||
|
"port": types.Int64PointerValue(resp.ConnectionInfo.Write.Port),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error {
|
func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error {
|
||||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package postgresflexalpha
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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/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/core"
|
||||||
|
|
@ -242,7 +243,8 @@ func (r *instanceResource) Create(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).WaitWithContext(ctx)
|
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).
|
||||||
|
WaitWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -324,50 +326,21 @@ func (r *instanceResource) Read(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData InstanceResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
// projectId := model.ProjectId.ValueString()
|
|
||||||
// region := r.providerData.GetRegionWithOverride(model.Region)
|
|
||||||
// instanceId := model.InstanceId.ValueString()
|
|
||||||
|
|
||||||
var projectId string
|
var projectId string
|
||||||
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {
|
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {
|
||||||
projectId = model.ProjectId.ValueString()
|
projectId = model.ProjectId.ValueString()
|
||||||
} else {
|
|
||||||
if identityData.ProjectID.IsNull() || identityData.ProjectID.IsUnknown() {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, functionErrorSummary, "project_id not found in config")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
projectId = identityData.ProjectID.ValueString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var region string
|
var region string
|
||||||
if !model.Region.IsNull() && !model.Region.IsUnknown() {
|
if !model.Region.IsNull() && !model.Region.IsUnknown() {
|
||||||
region = r.providerData.GetRegionWithOverride(model.Region)
|
region = r.providerData.GetRegionWithOverride(model.Region)
|
||||||
} else {
|
|
||||||
if identityData.Region.IsNull() || identityData.Region.IsUnknown() {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, functionErrorSummary, "region not found in config")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
region = r.providerData.GetRegionWithOverride(identityData.Region)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var instanceId string
|
var instanceId string
|
||||||
if !model.InstanceId.IsNull() && !model.InstanceId.IsUnknown() {
|
if !model.InstanceId.IsNull() && !model.InstanceId.IsUnknown() {
|
||||||
instanceId = model.InstanceId.ValueString()
|
instanceId = model.InstanceId.ValueString()
|
||||||
} else {
|
|
||||||
if identityData.InstanceID.IsNull() || identityData.InstanceID.IsUnknown() {
|
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, functionErrorSummary, "instance_id not found in config")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
instanceId = identityData.InstanceID.ValueString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
|
|
@ -458,18 +431,6 @@ func (r *instanceResource) Update(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//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() {
|
|
||||||
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "projectId is null or unknown")
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
//projectId := model.ProjectId.ValueString()
|
|
||||||
//instanceId := model.InstanceId.ValueString()
|
|
||||||
projectId := identityData.ProjectID.ValueString()
|
projectId := identityData.ProjectID.ValueString()
|
||||||
instanceId := identityData.InstanceID.ValueString()
|
instanceId := identityData.InstanceID.ValueString()
|
||||||
region := model.Region.ValueString()
|
region := model.Region.ValueString()
|
||||||
|
|
@ -617,7 +578,7 @@ func (r *instanceResource) ImportState(
|
||||||
ctx, &resp.Diagnostics,
|
ctx, &resp.Diagnostics,
|
||||||
"Error importing instance",
|
"Error importing instance",
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"Expected import identifier with format: [project_id],[region],[instance_id] Got: %q",
|
"Expected import identifier with format [project_id],[region],[instance_id] Got: %q",
|
||||||
req.ID,
|
req.ID,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,280 +0,0 @@
|
||||||
package postgresflexalpha
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/testutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
validFlavor = "2.4"
|
|
||||||
kekKeyRingId = ""
|
|
||||||
kekKeyVersion = ""
|
|
||||||
kekKeySA = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
func testAccPreCheck(t *testing.T) {
|
|
||||||
// TODO: if needed ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//func TestAccResourceExample_parallel(t *testing.T) {
|
|
||||||
// t.Parallel()
|
|
||||||
//
|
|
||||||
// exData := resData{
|
|
||||||
// Region: "eu01",
|
|
||||||
// ServiceAccountFilePath: sa_file,
|
|
||||||
// ProjectID: project_id,
|
|
||||||
// Name: acctest.RandomWithPrefix("tf-acc"),
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
|
||||||
// ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
|
||||||
// Steps: []resource.TestStep{
|
|
||||||
// {
|
|
||||||
// Config: testAccResourceEncryptionExampleConfig(exData),
|
|
||||||
// Check: resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
//}
|
|
||||||
|
|
||||||
type resData struct {
|
|
||||||
ServiceAccountFilePath string
|
|
||||||
ProjectID string
|
|
||||||
Region string
|
|
||||||
Name string
|
|
||||||
Flavor string
|
|
||||||
BackupSchedule string
|
|
||||||
RetentionDays uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func getExample() resData {
|
|
||||||
return resData{
|
|
||||||
Region: testutil.Region,
|
|
||||||
ServiceAccountFilePath: testutil.ServiceAccountFile,
|
|
||||||
ProjectID: testutil.ProjectId,
|
|
||||||
Name: acctest.RandomWithPrefix("tf-acc"),
|
|
||||||
Flavor: "2.4",
|
|
||||||
BackupSchedule: "0 0 * * *",
|
|
||||||
RetentionDays: 33,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccResourceExample_basic(t *testing.T) {
|
|
||||||
exData := getExample()
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccResourceNoEncryptionExampleConfig(exData),
|
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
|
||||||
resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
|
||||||
resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
//// Create and verify
|
|
||||||
//{
|
|
||||||
// Config: testAccResourceNoEncryptionExampleConfig(exData),
|
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
|
||||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
|
||||||
// ),
|
|
||||||
//},
|
|
||||||
//// Update and verify
|
|
||||||
//{
|
|
||||||
// Config: testAccResourceNoEncryptionExampleConfig(exData),
|
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
|
||||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
|
||||||
// ),
|
|
||||||
//},
|
|
||||||
// Import test
|
|
||||||
{
|
|
||||||
ResourceName: "example_resource.test",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccResourceNoEncryptionExampleConfig(data resData) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
|
|
||||||
%[1]s
|
|
||||||
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "test" {
|
|
||||||
project_id = %[2]q
|
|
||||||
name = %[3]q
|
|
||||||
backup_schedule = %[4]q
|
|
||||||
retention_days = %[5]d
|
|
||||||
flavor_id = %[6]q
|
|
||||||
replicas = 1
|
|
||||||
storage = {
|
|
||||||
performance_class = "premium-perf2-stackit"
|
|
||||||
size = 10
|
|
||||||
}
|
|
||||||
network = {
|
|
||||||
acl = ["0.0.0.0/0"]
|
|
||||||
access_scope = "PUBLIC"
|
|
||||||
}
|
|
||||||
version = 17
|
|
||||||
}
|
|
||||||
|
|
||||||
`,
|
|
||||||
testutil.PostgresFlexProviderConfig(data.ServiceAccountFilePath),
|
|
||||||
data.ProjectID,
|
|
||||||
data.Name,
|
|
||||||
data.BackupSchedule,
|
|
||||||
data.RetentionDays,
|
|
||||||
data.Flavor,
|
|
||||||
data.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccResourceEncryptionExampleConfig(data resData) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
|
|
||||||
%[1]s
|
|
||||||
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "test" {
|
|
||||||
project_id = %[2]q
|
|
||||||
name = %[3]q
|
|
||||||
backup_schedule = "0 0 * * *"
|
|
||||||
retention_days = 45
|
|
||||||
flavor_id = "2.1"
|
|
||||||
replicas = 1
|
|
||||||
storage = {
|
|
||||||
performance_class = "premium-perf2-stackit"
|
|
||||||
size = 10
|
|
||||||
}
|
|
||||||
encryption = {
|
|
||||||
kek_key_id = "key01"
|
|
||||||
kek_key_ring_id = "key_ring_01"
|
|
||||||
kek_key_version = 1
|
|
||||||
service_account = "service@account.email"
|
|
||||||
}
|
|
||||||
network = {
|
|
||||||
acl = ["0.0.0.0/0"]
|
|
||||||
access_scope = "PUBLIC"
|
|
||||||
}
|
|
||||||
version = 14
|
|
||||||
}
|
|
||||||
|
|
||||||
`,
|
|
||||||
testutil.PostgresFlexProviderConfig(data.ServiceAccountFilePath),
|
|
||||||
data.ProjectID,
|
|
||||||
data.Name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCheckResourceExists(resourceName string) resource.TestCheckFunc {
|
|
||||||
return func(s *terraform.State) error {
|
|
||||||
rs, ok := s.RootModule().Resources[resourceName]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("resource not found: %s", resourceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rs.Primary.ID == "" {
|
|
||||||
return fmt.Errorf("resource ID not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify resource exists in the API
|
|
||||||
//client := testAccProvider.Meta().(*APIClient)
|
|
||||||
//_, err := client.GetResource(rs.Primary.ID)
|
|
||||||
//if err != nil {
|
|
||||||
// return fmt.Errorf("error fetching resource: %w", err)
|
|
||||||
//}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupMockServer() *httptest.Server {
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
|
|
||||||
mux.HandleFunc("/api/resources", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.Method {
|
|
||||||
case http.MethodPost:
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
|
||||||
"id": "mock-id-123",
|
|
||||||
"name": "test-resource",
|
|
||||||
})
|
|
||||||
case http.MethodGet:
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
json.NewEncoder(w).Encode([]map[string]string{})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return httptest.NewServer(mux)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUnitResourceCreate(t *testing.T) {
|
|
||||||
server := setupMockServer()
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
// Configure provider to use mock server URL
|
|
||||||
os.Setenv("API_ENDPOINT", server.URL)
|
|
||||||
|
|
||||||
// Run unit tests against mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// type postgresFlexClientMocked struct {
|
|
||||||
// returnError bool
|
|
||||||
// getFlavorsResp *postgresflex.GetFlavorsResponse
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func (c *postgresFlexClientMocked) ListFlavorsExecute(_ context.Context, _, _ string) (*postgresflex.GetFlavorsResponse, error) {
|
|
||||||
// if c.returnError {
|
|
||||||
// return nil, fmt.Errorf("get flavors failed")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return c.getFlavorsResp, nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
//func TestNewInstanceResource(t *testing.T) {
|
|
||||||
// exData := resData{
|
|
||||||
// Region: "eu01",
|
|
||||||
// ServiceAccountFilePath: sa_file,
|
|
||||||
// ProjectID: project_id,
|
|
||||||
// Name: "testRes",
|
|
||||||
// }
|
|
||||||
// resource.Test(t, resource.TestCase{
|
|
||||||
// ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
|
||||||
// Steps: []resource.TestStep{
|
|
||||||
// {
|
|
||||||
// Config: testAccResourceEncryptionExampleConfig(exData),
|
|
||||||
// Check: resource.ComposeAggregateTestCheckFunc(
|
|
||||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
|
||||||
// resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
|
||||||
// ),
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// //tests := []struct {
|
|
||||||
// // name string
|
|
||||||
// // want resource.Resource
|
|
||||||
// //}{
|
|
||||||
// // {
|
|
||||||
// // name: "create empty instance resource",
|
|
||||||
// // want: &instanceResource{},
|
|
||||||
// // },
|
|
||||||
// //}
|
|
||||||
// //for _, tt := range tests {
|
|
||||||
// // t.Run(tt.name, func(t *testing.T) {
|
|
||||||
// // if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
|
|
||||||
// // t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
|
|
||||||
// // }
|
|
||||||
// // })
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
|
|
@ -35,15 +35,27 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema {
|
||||||
},
|
},
|
||||||
"connection_info": schema.SingleNestedAttribute{
|
"connection_info": schema.SingleNestedAttribute{
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
"host": schema.StringAttribute{
|
"write": schema.SingleNestedAttribute{
|
||||||
|
Attributes: map[string]schema.Attribute{
|
||||||
|
"host": schema.StringAttribute{
|
||||||
|
Computed: true,
|
||||||
|
Description: "The host of the instance.",
|
||||||
|
MarkdownDescription: "The host of the instance.",
|
||||||
|
},
|
||||||
|
"port": schema.Int64Attribute{
|
||||||
|
Computed: true,
|
||||||
|
Description: "The port of the instance.",
|
||||||
|
MarkdownDescription: "The port of the instance.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CustomType: WriteType{
|
||||||
|
ObjectType: types.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
},
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "The host of the instance.",
|
Description: "The DNS name and port in the instance overview",
|
||||||
MarkdownDescription: "The host of the instance.",
|
MarkdownDescription: "The DNS name and port in the instance overview",
|
||||||
},
|
|
||||||
"port": schema.Int64Attribute{
|
|
||||||
Computed: true,
|
|
||||||
Description: "The port of the instance.",
|
|
||||||
MarkdownDescription: "The port of the instance.",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CustomType: ConnectionInfoType{
|
CustomType: ConnectionInfoType{
|
||||||
|
|
@ -52,8 +64,8 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "The DNS name and port in the instance overview",
|
Description: "The connection information of the instance",
|
||||||
MarkdownDescription: "The DNS name and port in the instance overview",
|
MarkdownDescription: "The connection information of the instance",
|
||||||
},
|
},
|
||||||
"encryption": schema.SingleNestedAttribute{
|
"encryption": schema.SingleNestedAttribute{
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
|
|
@ -263,40 +275,22 @@ func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.Ob
|
||||||
|
|
||||||
attributes := in.Attributes()
|
attributes := in.Attributes()
|
||||||
|
|
||||||
hostAttribute, ok := attributes["host"]
|
writeAttribute, ok := attributes["write"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Missing",
|
"Attribute Missing",
|
||||||
`host is missing from object`)
|
`write is missing from object`)
|
||||||
|
|
||||||
return nil, diags
|
return nil, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
writeVal, ok := writeAttribute.(basetypes.ObjectValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Wrong Type",
|
"Attribute Wrong Type",
|
||||||
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
fmt.Sprintf(`write expected to be basetypes.ObjectValue, was: %T`, writeAttribute))
|
||||||
}
|
|
||||||
|
|
||||||
portAttribute, ok := attributes["port"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`port is missing from object`)
|
|
||||||
|
|
||||||
return nil, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
portVal, ok := portAttribute.(basetypes.Int64Value)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
@ -304,8 +298,7 @@ func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.Ob
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConnectionInfoValue{
|
return ConnectionInfoValue{
|
||||||
Host: hostVal,
|
Write: writeVal,
|
||||||
Port: portVal,
|
|
||||||
state: attr.ValueStateKnown,
|
state: attr.ValueStateKnown,
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
@ -373,40 +366,22 @@ func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
return NewConnectionInfoValueUnknown(), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostAttribute, ok := attributes["host"]
|
writeAttribute, ok := attributes["write"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Missing",
|
"Attribute Missing",
|
||||||
`host is missing from object`)
|
`write is missing from object`)
|
||||||
|
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
return NewConnectionInfoValueUnknown(), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
writeVal, ok := writeAttribute.(basetypes.ObjectValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
diags.AddError(
|
diags.AddError(
|
||||||
"Attribute Wrong Type",
|
"Attribute Wrong Type",
|
||||||
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
fmt.Sprintf(`write expected to be basetypes.ObjectValue, was: %T`, writeAttribute))
|
||||||
}
|
|
||||||
|
|
||||||
portAttribute, ok := attributes["port"]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Missing",
|
|
||||||
`port is missing from object`)
|
|
||||||
|
|
||||||
return NewConnectionInfoValueUnknown(), diags
|
|
||||||
}
|
|
||||||
|
|
||||||
portVal, ok := portAttribute.(basetypes.Int64Value)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
diags.AddError(
|
|
||||||
"Attribute Wrong Type",
|
|
||||||
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
|
|
@ -414,8 +389,7 @@ func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConnectionInfoValue{
|
return ConnectionInfoValue{
|
||||||
Host: hostVal,
|
Write: writeVal,
|
||||||
Port: portVal,
|
|
||||||
state: attr.ValueStateKnown,
|
state: attr.ValueStateKnown,
|
||||||
}, diags
|
}, diags
|
||||||
}
|
}
|
||||||
|
|
@ -488,12 +462,401 @@ func (t ConnectionInfoType) ValueType(ctx context.Context) attr.Value {
|
||||||
var _ basetypes.ObjectValuable = ConnectionInfoValue{}
|
var _ basetypes.ObjectValuable = ConnectionInfoValue{}
|
||||||
|
|
||||||
type ConnectionInfoValue struct {
|
type ConnectionInfoValue struct {
|
||||||
|
Write basetypes.ObjectValue `tfsdk:"write"`
|
||||||
|
state attr.ValueState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||||
|
attrTypes := make(map[string]tftypes.Type, 1)
|
||||||
|
|
||||||
|
var val tftypes.Value
|
||||||
|
var err error
|
||||||
|
|
||||||
|
attrTypes["write"] = basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
}.TerraformType(ctx)
|
||||||
|
|
||||||
|
objectType := tftypes.Object{AttributeTypes: attrTypes}
|
||||||
|
|
||||||
|
switch v.state {
|
||||||
|
case attr.ValueStateKnown:
|
||||||
|
vals := make(map[string]tftypes.Value, 1)
|
||||||
|
|
||||||
|
val, err = v.Write.ToTerraformValue(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||||
|
}
|
||||||
|
|
||||||
|
vals["write"] = val
|
||||||
|
|
||||||
|
if err := tftypes.ValidateValue(objectType, vals); err != nil {
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tftypes.NewValue(objectType, vals), nil
|
||||||
|
case attr.ValueStateNull:
|
||||||
|
return tftypes.NewValue(objectType, nil), nil
|
||||||
|
case attr.ValueStateUnknown:
|
||||||
|
return tftypes.NewValue(objectType, tftypes.UnknownValue), nil
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) IsNull() bool {
|
||||||
|
return v.state == attr.ValueStateNull
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) IsUnknown() bool {
|
||||||
|
return v.state == attr.ValueStateUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) String() string {
|
||||||
|
return "ConnectionInfoValue"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
var write basetypes.ObjectValue
|
||||||
|
|
||||||
|
if v.Write.IsNull() {
|
||||||
|
write = types.ObjectNull(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Write.IsUnknown() {
|
||||||
|
write = types.ObjectUnknown(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !v.Write.IsNull() && !v.Write.IsUnknown() {
|
||||||
|
write = types.ObjectValueMust(
|
||||||
|
WriteValue{}.AttributeTypes(ctx),
|
||||||
|
v.Write.Attributes(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeTypes := map[string]attr.Type{
|
||||||
|
"write": basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsNull() {
|
||||||
|
return types.ObjectNull(attributeTypes), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsUnknown() {
|
||||||
|
return types.ObjectUnknown(attributeTypes), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
objVal, diags := types.ObjectValue(
|
||||||
|
attributeTypes,
|
||||||
|
map[string]attr.Value{
|
||||||
|
"write": write,
|
||||||
|
})
|
||||||
|
|
||||||
|
return objVal, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
||||||
|
other, ok := o.(ConnectionInfoValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.state != other.state {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.state != attr.ValueStateKnown {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !v.Write.Equal(other.Write) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type {
|
||||||
|
return ConnectionInfoType{
|
||||||
|
basetypes.ObjectType{
|
||||||
|
AttrTypes: v.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||||
|
return map[string]attr.Type{
|
||||||
|
"write": basetypes.ObjectType{
|
||||||
|
AttrTypes: WriteValue{}.AttributeTypes(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ basetypes.ObjectTypable = WriteType{}
|
||||||
|
|
||||||
|
type WriteType struct {
|
||||||
|
basetypes.ObjectType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) Equal(o attr.Type) bool {
|
||||||
|
other, ok := o.(WriteType)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.ObjectType.Equal(other.ObjectType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) String() string {
|
||||||
|
return "WriteType"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
attributes := in.Attributes()
|
||||||
|
|
||||||
|
hostAttribute, ok := attributes["host"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`host is missing from object`)
|
||||||
|
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
portAttribute, ok := attributes["port"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`port is missing from object`)
|
||||||
|
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
portVal, ok := portAttribute.(basetypes.Int64Value)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteValue{
|
||||||
|
Host: hostVal,
|
||||||
|
Port: portVal,
|
||||||
|
state: attr.ValueStateKnown,
|
||||||
|
}, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueNull() WriteValue {
|
||||||
|
return WriteValue{
|
||||||
|
state: attr.ValueStateNull,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueUnknown() WriteValue {
|
||||||
|
return WriteValue{
|
||||||
|
state: attr.ValueStateUnknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (WriteValue, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
for name, attributeType := range attributeTypes {
|
||||||
|
attribute, ok := attributes[name]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Missing WriteValue Attribute Value",
|
||||||
|
"While creating a WriteValue value, a missing attribute value was detected. "+
|
||||||
|
"A WriteValue must contain values for all attributes, even if null or unknown. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()),
|
||||||
|
)
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !attributeType.Equal(attribute.Type(ctx)) {
|
||||||
|
diags.AddError(
|
||||||
|
"Invalid WriteValue Attribute Type",
|
||||||
|
"While creating a WriteValue value, an invalid attribute value was detected. "+
|
||||||
|
"A WriteValue must use a matching attribute type for the value. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+
|
||||||
|
fmt.Sprintf("WriteValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for name := range attributes {
|
||||||
|
_, ok := attributeTypes[name]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Extra WriteValue Attribute Value",
|
||||||
|
"While creating a WriteValue value, an extra attribute value was detected. "+
|
||||||
|
"A WriteValue must not contain values beyond the expected attribute types. "+
|
||||||
|
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||||
|
fmt.Sprintf("Extra WriteValue Attribute Name: %s", name),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostAttribute, ok := attributes["host"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`host is missing from object`)
|
||||||
|
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
hostVal, ok := hostAttribute.(basetypes.StringValue)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
portAttribute, ok := attributes["port"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Missing",
|
||||||
|
`port is missing from object`)
|
||||||
|
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
portVal, ok := portAttribute.(basetypes.Int64Value)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
diags.AddError(
|
||||||
|
"Attribute Wrong Type",
|
||||||
|
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
|
||||||
|
}
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
return NewWriteValueUnknown(), diags
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteValue{
|
||||||
|
Host: hostVal,
|
||||||
|
Port: portVal,
|
||||||
|
state: attr.ValueStateKnown,
|
||||||
|
}, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriteValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) WriteValue {
|
||||||
|
object, diags := NewWriteValue(attributeTypes, attributes)
|
||||||
|
|
||||||
|
if diags.HasError() {
|
||||||
|
// This could potentially be added to the diag package.
|
||||||
|
diagsStrings := make([]string, 0, len(diags))
|
||||||
|
|
||||||
|
for _, diagnostic := range diags {
|
||||||
|
diagsStrings = append(diagsStrings, fmt.Sprintf(
|
||||||
|
"%s | %s | %s",
|
||||||
|
diagnostic.Severity(),
|
||||||
|
diagnostic.Summary(),
|
||||||
|
diagnostic.Detail()))
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("NewWriteValueMust received error(s): " + strings.Join(diagsStrings, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return object
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
|
||||||
|
if in.Type() == nil {
|
||||||
|
return NewWriteValueNull(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.Type().Equal(t.TerraformType(ctx)) {
|
||||||
|
return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !in.IsKnown() {
|
||||||
|
return NewWriteValueUnknown(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if in.IsNull() {
|
||||||
|
return NewWriteValueNull(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes := map[string]attr.Value{}
|
||||||
|
|
||||||
|
val := map[string]tftypes.Value{}
|
||||||
|
|
||||||
|
err := in.As(&val)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range val {
|
||||||
|
a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes[k] = a
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewWriteValueMust(WriteValue{}.AttributeTypes(ctx), attributes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t WriteType) ValueType(ctx context.Context) attr.Value {
|
||||||
|
return WriteValue{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ basetypes.ObjectValuable = WriteValue{}
|
||||||
|
|
||||||
|
type WriteValue struct {
|
||||||
Host basetypes.StringValue `tfsdk:"host"`
|
Host basetypes.StringValue `tfsdk:"host"`
|
||||||
Port basetypes.Int64Value `tfsdk:"port"`
|
Port basetypes.Int64Value `tfsdk:"port"`
|
||||||
state attr.ValueState
|
state attr.ValueState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
func (v WriteValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||||
attrTypes := make(map[string]tftypes.Type, 2)
|
attrTypes := make(map[string]tftypes.Type, 2)
|
||||||
|
|
||||||
var val tftypes.Value
|
var val tftypes.Value
|
||||||
|
|
@ -538,19 +901,19 @@ func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Valu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) IsNull() bool {
|
func (v WriteValue) IsNull() bool {
|
||||||
return v.state == attr.ValueStateNull
|
return v.state == attr.ValueStateNull
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) IsUnknown() bool {
|
func (v WriteValue) IsUnknown() bool {
|
||||||
return v.state == attr.ValueStateUnknown
|
return v.state == attr.ValueStateUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) String() string {
|
func (v WriteValue) String() string {
|
||||||
return "ConnectionInfoValue"
|
return "WriteValue"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
func (v WriteValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
attributeTypes := map[string]attr.Type{
|
attributeTypes := map[string]attr.Type{
|
||||||
|
|
@ -576,8 +939,8 @@ func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.Objec
|
||||||
return objVal, diags
|
return objVal, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
func (v WriteValue) Equal(o attr.Value) bool {
|
||||||
other, ok := o.(ConnectionInfoValue)
|
other, ok := o.(WriteValue)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
|
|
@ -602,15 +965,15 @@ func (v ConnectionInfoValue) Equal(o attr.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type {
|
func (v WriteValue) Type(ctx context.Context) attr.Type {
|
||||||
return ConnectionInfoType{
|
return WriteType{
|
||||||
basetypes.ObjectType{
|
basetypes.ObjectType{
|
||||||
AttrTypes: v.AttributeTypes(ctx),
|
AttrTypes: v.AttributeTypes(ctx),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
func (v WriteValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||||
return map[string]attr.Type{
|
return map[string]attr.Type{
|
||||||
"host": basetypes.StringType{},
|
"host": basetypes.StringType{},
|
||||||
"port": basetypes.Int64Type{},
|
"port": basetypes.Int64Type{},
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package postgresflexalpha
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
// 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"
|
|
||||||
fwresource "github.com/hashicorp/terraform-plugin-framework/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestInstanceResourceSchema(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
schemaRequest := fwresource.SchemaRequest{}
|
|
||||||
schemaResponse := &fwresource.SchemaResponse{}
|
|
||||||
|
|
||||||
// Instantiate the resource.Resource and call its Schema method
|
|
||||||
NewInstanceResource().Schema(ctx, schemaRequest, schemaResponse)
|
|
||||||
|
|
||||||
if schemaResponse.Diagnostics.HasError() {
|
|
||||||
t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the schema
|
|
||||||
diagnostics := schemaResponse.Schema.ValidateImplementation(ctx)
|
|
||||||
|
|
||||||
if diagnostics.HasError() {
|
|
||||||
t.Fatalf("Schema validation diagnostics: %+v", diagnostics)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
package postgresflexalpha
|
|
||||||
File diff suppressed because it is too large
Load diff
54
stackit/internal/services/postgresflexalpha/testdata/instance_template.gompl
vendored
Normal file
54
stackit/internal/services/postgresflexalpha/testdata/instance_template.gompl
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "{{ .Region }}"
|
||||||
|
service_account_key_path = "{{ .ServiceAccountFilePath }}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "stackitprivatepreview_postgresflexalpha_instance" "{{ .TfName }}" {
|
||||||
|
project_id = "{{ .ProjectId }}"
|
||||||
|
name = "{{ .Name }}"
|
||||||
|
backup_schedule = "{{ .BackupSchedule }}"
|
||||||
|
retention_days = {{ .RetentionDays }}
|
||||||
|
flavor_id = "{{ .FlavorId }}"
|
||||||
|
replicas = {{ .Replicas }}
|
||||||
|
storage = {
|
||||||
|
performance_class = "{{ .PerformanceClass }}"
|
||||||
|
size = {{ .Size }}
|
||||||
|
}
|
||||||
|
{{ if .UseEncryption }}
|
||||||
|
encryption = {
|
||||||
|
kek_key_id = {{ .KekKeyId }}
|
||||||
|
kek_key_ring_id = {{ .KekKeyRingId }}
|
||||||
|
kek_key_version = {{ .KekKeyVersion }}
|
||||||
|
service_account = "{{ .KekServiceAccount }}"
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
|
network = {
|
||||||
|
acl = ["{{ .AclString }}"]
|
||||||
|
access_scope = "{{ .AccessScope }}"
|
||||||
|
}
|
||||||
|
version = {{ .Version }}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{ if .Users }}
|
||||||
|
{{ $tfName := .TfName }}
|
||||||
|
{{ range $user := .Users }}
|
||||||
|
resource "stackitprivatepreview_postgresflexalpha_user" "{{ $user.Name }}" {
|
||||||
|
project_id = "{{ $user.ProjectId }}"
|
||||||
|
instance_id = stackitprivatepreview_postgresflexalpha_instance.{{ $tfName }}.instance_id
|
||||||
|
name = "{{ $user.Name }}"
|
||||||
|
roles = [{{ range $i, $v := $user.Roles }}{{if $i}},{{end}}"{{$v}}"{{end}}]
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if .Databases }}
|
||||||
|
{{ $tfName := .TfName }}
|
||||||
|
{{ range $db := .Databases }}
|
||||||
|
resource "stackitprivatepreview_postgresflexalpha_database" "{{ $db.Name }}" {
|
||||||
|
project_id = "{{ $db.ProjectId }}"
|
||||||
|
instance_id = stackitprivatepreview_postgresflexalpha_instance.{{ $tfName }}.instance_id
|
||||||
|
name = "{{ $db.Name }}"
|
||||||
|
owner = stackitprivatepreview_postgresflexalpha_user.{{ $db.Owner }}.name
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
@ -1,23 +1,26 @@
|
||||||
|
variable "project_id" {}
|
||||||
|
variable "kek_key_id" {}
|
||||||
|
variable "kek_key_ring_id" {}
|
||||||
|
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
project_id = var.project_id
|
||||||
name = "example-instance"
|
name = "example-instance"
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
|
||||||
backup_schedule = "0 0 * * *"
|
backup_schedule = "0 0 * * *"
|
||||||
retention_days = 30
|
retention_days = 30
|
||||||
flavor_id = "flavor.id"
|
flavor_id = "2.4"
|
||||||
replicas = 1
|
replicas = 1
|
||||||
storage = {
|
storage = {
|
||||||
performance_class = "premium-perf2-stackit"
|
performance_class = "premium-perf2-stackit"
|
||||||
size = 10
|
size = 10
|
||||||
}
|
}
|
||||||
encryption = {
|
encryption = {
|
||||||
kek_key_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
kek_key_id = var.kek_key_id
|
||||||
kek_key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
kek_key_ring_id = var.kek_key_ring_id
|
||||||
kek_key_version = 1
|
kek_key_version = 1
|
||||||
service_account = "service@account.email"
|
service_account = "service@account.email"
|
||||||
}
|
}
|
||||||
network = {
|
network = {
|
||||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
acl = ["0.0.0.0/0"]
|
||||||
access_scope = "PUBLIC"
|
access_scope = "PUBLIC"
|
||||||
}
|
}
|
||||||
version = 17
|
version = 17
|
||||||
19
stackit/internal/services/postgresflexalpha/testdata/resource-no-enc.tf
vendored
Normal file
19
stackit/internal/services/postgresflexalpha/testdata/resource-no-enc.tf
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
variable "project_id" {}
|
||||||
|
|
||||||
|
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
||||||
|
project_id = var.project_id
|
||||||
|
name = "example-instance"
|
||||||
|
backup_schedule = "0 0 * * *"
|
||||||
|
retention_days = 30
|
||||||
|
flavor_id = "2.4"
|
||||||
|
replicas = 1
|
||||||
|
storage = {
|
||||||
|
performance_class = "premium-perf2-stackit"
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
network = {
|
||||||
|
acl = ["0.0.0.0/0"]
|
||||||
|
access_scope = "PUBLIC"
|
||||||
|
}
|
||||||
|
version = 17
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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/conversion"
|
||||||
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/datasources_gen"
|
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/datasource"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/core"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"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)")
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userId := int32(userId64)
|
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||||
|
|
||||||
region := r.providerData.GetRegionWithOverride(model.Region)
|
region := r.providerData.GetRegionWithOverride(model.Region)
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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"
|
"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"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -80,7 +80,7 @@ func toUpdatePayload(model *resourceModel, roles *[]string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
return &postgresflex.UpdateUserRequestPayload{
|
return &postgresflex.UpdateUserRequestPayload{
|
||||||
Name: conversion.StringValueToPointer(model.Name),
|
Name: model.Name.ValueStringPointer(),
|
||||||
Roles: toPayloadRoles(roles),
|
Roles: toPayloadRoles(roles),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ func toCreatePayload(model *resourceModel, roles *[]string) (*postgresflex.Creat
|
||||||
|
|
||||||
return &postgresflex.CreateUserRequestPayload{
|
return &postgresflex.CreateUserRequestPayload{
|
||||||
Roles: toPayloadRoles(roles),
|
Roles: toPayloadRoles(roles),
|
||||||
Name: conversion.StringValueToPointer(model.Name),
|
Name: model.Name.ValueStringPointer(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ func mapResourceFields(userResp *postgresflex.GetUserResponse, model *resourceMo
|
||||||
user := userResp
|
user := userResp
|
||||||
|
|
||||||
var userId int64
|
var userId int64
|
||||||
if model.UserId.ValueInt64() != 0 {
|
if !model.UserId.IsNull() && !model.UserId.IsUnknown() && model.UserId.ValueInt64() != 0 {
|
||||||
userId = model.UserId.ValueInt64()
|
userId = model.UserId.ValueInt64()
|
||||||
} else if user.Id != nil {
|
} else if user.Id != nil {
|
||||||
userId = *user.Id
|
userId = *user.Id
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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"
|
data "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user/datasources_gen"
|
||||||
)
|
)
|
||||||
|
|
@ -51,7 +52,6 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
dataSourceModel{
|
dataSourceModel{
|
||||||
|
|
||||||
UserModel: data.UserModel{
|
UserModel: data.UserModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
|
|
@ -164,15 +164,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
UserId: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
UserId: types.Int64Value(1),
|
||||||
ProjectId: types.StringValue("pid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
Name: types.StringNull(),
|
ProjectId: types.StringValue("pid"),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Name: types.StringNull(),
|
||||||
Password: types.StringNull(),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Password: types.StringNull(),
|
||||||
Status: types.StringNull(),
|
Region: types.StringValue(testRegion),
|
||||||
ConnectionString: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -185,15 +186,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
UserId: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
UserId: types.Int64Value(1),
|
||||||
ProjectId: types.StringValue("pid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
Name: types.StringValue("username"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Name: types.StringValue("username"),
|
||||||
Password: types.StringNull(),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Password: types.StringNull(),
|
||||||
Status: types.StringValue("status"),
|
Region: types.StringValue(testRegion),
|
||||||
ConnectionString: types.StringValue("connection_string"),
|
Status: types.StringValue("status"),
|
||||||
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -206,15 +208,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
UserId: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
UserId: types.Int64Value(1),
|
||||||
ProjectId: types.StringValue("pid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
Name: types.StringNull(),
|
ProjectId: types.StringValue("pid"),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Name: types.StringNull(),
|
||||||
Password: types.StringNull(),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Password: types.StringNull(),
|
||||||
Status: types.StringNull(),
|
Region: types.StringValue(testRegion),
|
||||||
ConnectionString: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -282,15 +285,15 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(int64(1)),
|
UserId: types.Int64Value(int64(1)),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -321,9 +324,9 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -335,15 +338,15 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,12 @@ fields:
|
||||||
- name: 'id'
|
- name: 'id'
|
||||||
modifiers:
|
modifiers:
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
- 'RequiresReplace'
|
||||||
|
|
||||||
- name: 'user_id'
|
- name: 'user_id'
|
||||||
modifiers:
|
modifiers:
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
- 'RequiresReplace'
|
||||||
|
|
||||||
- name: 'instance_id'
|
- name: 'instance_id'
|
||||||
validators:
|
validators:
|
||||||
|
|
@ -13,6 +15,7 @@ fields:
|
||||||
- validate.UUID
|
- validate.UUID
|
||||||
modifiers:
|
modifiers:
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
- 'RequiresReplace'
|
||||||
|
|
||||||
- name: 'project_id'
|
- name: 'project_id'
|
||||||
validators:
|
validators:
|
||||||
|
|
@ -32,24 +35,30 @@ fields:
|
||||||
|
|
||||||
- name: 'password'
|
- name: 'password'
|
||||||
modifiers:
|
modifiers:
|
||||||
|
- 'RequiresReplace'
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
|
||||||
- name: 'host'
|
- name: 'host'
|
||||||
modifiers:
|
modifiers:
|
||||||
|
- 'RequiresReplace'
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
|
||||||
- name: 'port'
|
- name: 'port'
|
||||||
modifiers:
|
modifiers:
|
||||||
|
- 'RequiresReplace'
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
|
||||||
- name: 'region'
|
- name: 'region'
|
||||||
modifiers:
|
modifiers:
|
||||||
- 'RequiresReplace'
|
- 'RequiresReplace'
|
||||||
|
- 'RequiresReplace'
|
||||||
|
|
||||||
- name: 'status'
|
- name: 'status'
|
||||||
modifiers:
|
modifiers:
|
||||||
|
- 'RequiresReplace'
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
|
||||||
- name: 'connection_string'
|
- name: 'connection_string'
|
||||||
modifiers:
|
modifiers:
|
||||||
|
- 'RequiresReplace'
|
||||||
- 'UseStateForUnknown'
|
- 'UseStateForUnknown'
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,26 @@ package postgresflexalpha
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||||
|
|
||||||
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
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"
|
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"
|
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
||||||
|
postgresflexalphaWait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/postgresflexalpha"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"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/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/core"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
|
|
@ -29,11 +30,12 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Ensure the implementation satisfies the expected interfaces.
|
// Ensure the implementation satisfies the expected interfaces.
|
||||||
_ resource.Resource = &userResource{}
|
_ resource.Resource = &userResource{}
|
||||||
_ resource.ResourceWithConfigure = &userResource{}
|
_ resource.ResourceWithConfigure = &userResource{}
|
||||||
_ resource.ResourceWithImportState = &userResource{}
|
_ resource.ResourceWithImportState = &userResource{}
|
||||||
_ resource.ResourceWithModifyPlan = &userResource{}
|
_ resource.ResourceWithModifyPlan = &userResource{}
|
||||||
_ resource.ResourceWithIdentity = &userResource{}
|
_ resource.ResourceWithIdentity = &userResource{}
|
||||||
|
_ resource.ResourceWithValidateConfig = &userResource{}
|
||||||
|
|
||||||
// Error message constants
|
// Error message constants
|
||||||
extractErrorSummary = "extracting failed"
|
extractErrorSummary = "extracting failed"
|
||||||
|
|
@ -53,7 +55,7 @@ type UserResourceIdentityModel struct {
|
||||||
ProjectID types.String `tfsdk:"project_id"`
|
ProjectID types.String `tfsdk:"project_id"`
|
||||||
Region types.String `tfsdk:"region"`
|
Region types.String `tfsdk:"region"`
|
||||||
InstanceID types.String `tfsdk:"instance_id"`
|
InstanceID types.String `tfsdk:"instance_id"`
|
||||||
UserID types.Int64 `tfsdk:"database_id"`
|
UserID types.Int64 `tfsdk:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// userResource implements the resource handling for a PostgreSQL Flex user.
|
// userResource implements the resource handling for a PostgreSQL Flex user.
|
||||||
|
|
@ -138,6 +140,39 @@ func (r *userResource) Schema(ctx context.Context, _ resource.SchemaRequest, res
|
||||||
resp.Schema = s
|
resp.Schema = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *userResource) ValidateConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
req resource.ValidateConfigRequest,
|
||||||
|
resp *resource.ValidateConfigResponse,
|
||||||
|
) {
|
||||||
|
var data resourceModel
|
||||||
|
|
||||||
|
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var roles []string
|
||||||
|
diags := data.Roles.ElementsAs(ctx, &roles, false)
|
||||||
|
resp.Diagnostics.Append(diags...)
|
||||||
|
if diags.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var resRoles []string
|
||||||
|
for _, role := range roles {
|
||||||
|
if slices.Contains(resRoles, role) {
|
||||||
|
resp.Diagnostics.AddAttributeError(
|
||||||
|
path.Root("roles"),
|
||||||
|
"Attribute Configuration Error",
|
||||||
|
"defined roles MUST NOT contain duplicates",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resRoles = append(resRoles, role)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create creates the resource and sets the initial Terraform state.
|
// Create creates the resource and sets the initial Terraform state.
|
||||||
func (r *userResource) Create(
|
func (r *userResource) Create(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|
@ -151,23 +186,12 @@ func (r *userResource) Create(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData UserResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
arg, errExt := r.extractIdentityData(model, identityData)
|
arg := &clientArg{
|
||||||
if errExt != nil {
|
projectId: model.ProjectId.ValueString(),
|
||||||
core.LogAndAddError(
|
instanceId: model.InstanceId.ValueString(),
|
||||||
ctx,
|
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = r.setTFLogFields(ctx, arg)
|
ctx = r.setTFLogFields(ctx, arg)
|
||||||
|
|
@ -183,6 +207,7 @@ func (r *userResource) Create(
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Creating API payload: %v", err))
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Creating API payload: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new user
|
// Create new user
|
||||||
userResp, err := r.client.CreateUserRequest(
|
userResp, err := r.client.CreateUserRequest(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -190,13 +215,13 @@ func (r *userResource) Create(
|
||||||
arg.region,
|
arg.region,
|
||||||
arg.instanceId,
|
arg.instanceId,
|
||||||
).CreateUserRequestPayload(*payload).Execute()
|
).CreateUserRequestPayload(*payload).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if userResp.Id == nil || *userResp.Id == 0 {
|
id, ok := userResp.GetIdOk()
|
||||||
|
if !ok || id == 0 {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
|
|
@ -205,11 +230,9 @@ func (r *userResource) Create(
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
model.Id = types.Int64PointerValue(userResp.Id)
|
arg.userId = id
|
||||||
model.UserId = types.Int64PointerValue(userResp.Id)
|
|
||||||
model.Password = types.StringPointerValue(userResp.Password)
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "user_id", *userResp.Id)
|
ctx = tflog.SetField(ctx, "user_id", id)
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
|
|
@ -218,28 +241,64 @@ func (r *userResource) Create(
|
||||||
ProjectID: types.StringValue(arg.projectId),
|
ProjectID: types.StringValue(arg.projectId),
|
||||||
Region: types.StringValue(arg.region),
|
Region: types.StringValue(arg.region),
|
||||||
InstanceID: types.StringValue(arg.instanceId),
|
InstanceID: types.StringValue(arg.instanceId),
|
||||||
UserID: types.Int64PointerValue(userResp.Id),
|
UserID: types.Int64Value(id),
|
||||||
}
|
}
|
||||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify creation
|
model.Id = types.Int64Value(id)
|
||||||
exists, err := r.getUserResource(ctx, &model, arg)
|
model.UserId = types.Int64Value(id)
|
||||||
|
model.Password = types.StringValue(userResp.GetPassword())
|
||||||
|
model.Status = types.StringValue(userResp.GetStatus())
|
||||||
|
|
||||||
|
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||||
|
ctx,
|
||||||
|
r.client,
|
||||||
|
arg.projectId,
|
||||||
|
arg.instanceId,
|
||||||
|
arg.region,
|
||||||
|
id,
|
||||||
|
).SetSleepBeforeWait(
|
||||||
|
10 * time.Second,
|
||||||
|
).SetTimeout(
|
||||||
|
15 * time.Minute,
|
||||||
|
).WaitWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !exists {
|
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx, &resp.Diagnostics, "Error creating user",
|
ctx,
|
||||||
fmt.Sprintf("User ID '%v' resource not found after creation", model.UserId.ValueInt64()),
|
&resp.Diagnostics,
|
||||||
|
"create user",
|
||||||
|
fmt.Sprintf("Instance creation waiting: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if waitResp.Id == nil {
|
||||||
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"create user",
|
||||||
|
"Instance creation waiting: returned id is nil",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if waitResp.Id == nil || *waitResp.Id != id {
|
||||||
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"create user",
|
||||||
|
fmt.Sprintf(
|
||||||
|
"Instance creation waiting: returned id is wrong: %+v - %+v",
|
||||||
|
waitResp.Id,
|
||||||
|
id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set state to fully populated data
|
// Set state to fully populated data
|
||||||
diags = resp.State.Set(ctx, model)
|
diags = resp.State.Set(ctx, model)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
@ -262,23 +321,12 @@ func (r *userResource) Read(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData UserResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
arg, errExt := r.extractIdentityData(model, identityData)
|
arg := &clientArg{
|
||||||
if errExt != nil {
|
projectId: model.ProjectId.ValueString(),
|
||||||
core.LogAndAddError(
|
instanceId: model.InstanceId.ValueString(),
|
||||||
ctx,
|
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = r.setTFLogFields(ctx, arg)
|
ctx = r.setTFLogFields(ctx, arg)
|
||||||
|
|
@ -286,20 +334,54 @@ func (r *userResource) Read(
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
// Read resource state
|
// Read resource state
|
||||||
exists, err := r.getUserResource(ctx, &model, arg)
|
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||||
|
ctx,
|
||||||
|
r.client,
|
||||||
|
arg.projectId,
|
||||||
|
arg.instanceId,
|
||||||
|
arg.region,
|
||||||
|
model.UserId.ValueInt64(),
|
||||||
|
).SetSleepBeforeWait(
|
||||||
|
10 * time.Second,
|
||||||
|
).SetTimeout(
|
||||||
|
15 * time.Minute,
|
||||||
|
).WaitWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading user", fmt.Sprintf("Calling API: %v", err))
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"read user",
|
||||||
|
fmt.Sprintf("Instance creation waiting: %v", err),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if waitResp.Id == nil || *waitResp.Id != model.UserId.ValueInt64() {
|
||||||
resp.State.RemoveResource(ctx)
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"read user",
|
||||||
|
"Instance creation waiting: returned id is nil or wrong",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
arg.userId = *waitResp.Id
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
|
// Set data returned by API in identity
|
||||||
|
identity := UserResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(arg.projectId),
|
||||||
|
Region: types.StringValue(arg.region),
|
||||||
|
InstanceID: types.StringValue(arg.instanceId),
|
||||||
|
UserID: types.Int64Value(arg.userId),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set refreshed state
|
// Set refreshed state
|
||||||
diags = resp.State.Set(ctx, model)
|
diags = resp.State.Set(ctx, model)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
@ -322,23 +404,12 @@ func (r *userResource) Update(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData UserResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
arg, errExt := r.extractIdentityData(model, identityData)
|
arg := &clientArg{
|
||||||
if errExt != nil {
|
projectId: model.ProjectId.ValueString(),
|
||||||
core.LogAndAddError(
|
instanceId: model.InstanceId.ValueString(),
|
||||||
ctx,
|
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = r.setTFLogFields(ctx, arg)
|
ctx = r.setTFLogFields(ctx, arg)
|
||||||
|
|
@ -369,7 +440,7 @@ func (r *userResource) Update(
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userId := int32(userId64)
|
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||||
|
|
||||||
// Update existing instance
|
// Update existing instance
|
||||||
err = r.client.UpdateUserRequest(
|
err = r.client.UpdateUserRequest(
|
||||||
|
|
@ -386,22 +457,53 @@ func (r *userResource) Update(
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
// Verify update
|
// Set data returned by API in identity
|
||||||
exists, err := r.getUserResource(ctx, &stateModel, arg)
|
identity := UserResourceIdentityModel{
|
||||||
|
ProjectID: types.StringValue(arg.projectId),
|
||||||
if err != nil {
|
Region: types.StringValue(arg.region),
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Calling API: %v", err))
|
InstanceID: types.StringValue(arg.instanceId),
|
||||||
|
UserID: types.Int64Value(userId64),
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
// Verify update
|
||||||
|
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||||
|
ctx,
|
||||||
|
r.client,
|
||||||
|
arg.projectId,
|
||||||
|
arg.instanceId,
|
||||||
|
arg.region,
|
||||||
|
model.UserId.ValueInt64(),
|
||||||
|
).SetSleepBeforeWait(
|
||||||
|
10 * time.Second,
|
||||||
|
).SetTimeout(
|
||||||
|
15 * time.Minute,
|
||||||
|
).WaitWithContext(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx, &resp.Diagnostics, "Error updating user",
|
ctx,
|
||||||
fmt.Sprintf("User ID '%v' resource not found after update", stateModel.UserId.ValueInt64()),
|
&resp.Diagnostics,
|
||||||
|
"read user",
|
||||||
|
fmt.Sprintf("user update waiting: %v", err),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if waitResp.Id == nil || *waitResp.Id != model.UserId.ValueInt64() {
|
||||||
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"update user",
|
||||||
|
"User creation waiting: returned id is nil or wrong",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
arg.userId = *waitResp.Id
|
||||||
|
|
||||||
// Set state to fully populated data
|
// Set state to fully populated data
|
||||||
diags = resp.State.Set(ctx, stateModel)
|
diags = resp.State.Set(ctx, stateModel)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
@ -450,7 +552,7 @@ func (r *userResource) Delete(
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userId := int32(userId64)
|
userId := int32(userId64) // nolint:gosec // check is performed above
|
||||||
|
|
||||||
// Delete existing record set
|
// Delete existing record set
|
||||||
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()
|
||||||
|
|
@ -460,19 +562,19 @@ func (r *userResource) Delete(
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
// Verify deletion
|
// TODO: Verify deletion
|
||||||
exists, err := r.getUserResource(ctx, &model, arg)
|
// exists, err := r.getUserResource(ctx, &model, arg)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
|
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
if exists {
|
// if exists {
|
||||||
core.LogAndAddError(
|
// core.LogAndAddError(
|
||||||
ctx, &resp.Diagnostics, "Error deleting user",
|
// ctx, &resp.Diagnostics, "Error deleting user",
|
||||||
fmt.Sprintf("User ID '%v' resource still exists after deletion", model.UserId.ValueInt64()),
|
// fmt.Sprintf("User ID '%v' resource still exists after deletion", model.UserId.ValueInt64()),
|
||||||
)
|
// )
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
|
||||||
resp.State.RemoveResource(ctx)
|
resp.State.RemoveResource(ctx)
|
||||||
|
|
||||||
|
|
@ -503,73 +605,6 @@ func (r *userResource) IdentitySchema(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapFields(userResp *postgresflex.GetUserResponse, model *resourceModel, region string) error {
|
|
||||||
if userResp == nil {
|
|
||||||
return fmt.Errorf("response is nil")
|
|
||||||
}
|
|
||||||
if model == nil {
|
|
||||||
return fmt.Errorf("model input is nil")
|
|
||||||
}
|
|
||||||
user := userResp
|
|
||||||
|
|
||||||
var userId int64
|
|
||||||
if model.UserId.ValueInt64() != 0 {
|
|
||||||
userId = model.UserId.ValueInt64()
|
|
||||||
} else if user.Id != nil {
|
|
||||||
userId = *user.Id
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("user id not present")
|
|
||||||
}
|
|
||||||
|
|
||||||
model.UserId = types.Int64Value(userId)
|
|
||||||
model.Name = types.StringPointerValue(user.Name)
|
|
||||||
|
|
||||||
if user.Roles == nil {
|
|
||||||
model.Roles = types.List(types.SetNull(types.StringType))
|
|
||||||
} else {
|
|
||||||
var roles []attr.Value
|
|
||||||
for _, role := range *user.Roles {
|
|
||||||
roles = append(roles, types.StringValue(string(role)))
|
|
||||||
}
|
|
||||||
rolesSet, diags := types.SetValue(types.StringType, roles)
|
|
||||||
if diags.HasError() {
|
|
||||||
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
|
||||||
}
|
|
||||||
model.Roles = types.List(rolesSet)
|
|
||||||
}
|
|
||||||
model.Region = types.StringValue(region)
|
|
||||||
model.Status = types.StringPointerValue(user.Status)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getUserResource refreshes the resource state by calling the API and mapping the response to the model.
|
|
||||||
// Returns true if the resource state was successfully refreshed, false if the resource does not exist.
|
|
||||||
func (r *userResource) getUserResource(ctx context.Context, model *resourceModel, arg *clientArg) (bool, error) {
|
|
||||||
|
|
||||||
if arg.userId > math.MaxInt32 {
|
|
||||||
return false, errors.New("error in type conversion: int value too large (userId)")
|
|
||||||
}
|
|
||||||
userId := int32(arg.userId)
|
|
||||||
|
|
||||||
// API Call
|
|
||||||
userResp, err := r.client.GetUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
var oapiErr *oapierror.GenericOpenAPIError
|
|
||||||
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, fmt.Errorf("error fetching user resource: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mapResourceFields(userResp, model, arg.region); err != nil {
|
|
||||||
return false, fmt.Errorf("error mapping user resource: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// clientArg holds the arguments for API calls.
|
// clientArg holds the arguments for API calls.
|
||||||
type clientArg struct {
|
type clientArg struct {
|
||||||
projectId string
|
projectId string
|
||||||
|
|
@ -585,11 +620,9 @@ func (r *userResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
@ -650,7 +683,6 @@ func (r *userResource) extractIdentityData(
|
||||||
model resourceModel,
|
model resourceModel,
|
||||||
identity UserResourceIdentityModel,
|
identity UserResourceIdentityModel,
|
||||||
) (*clientArg, error) {
|
) (*clientArg, error) {
|
||||||
|
|
||||||
var projectId, region, instanceId string
|
var projectId, region, instanceId string
|
||||||
var userId int64
|
var userId int64
|
||||||
|
|
||||||
|
|
@ -714,5 +746,6 @@ func (r *userResource) expandRoles(ctx context.Context, rolesSet types.List, dia
|
||||||
}
|
}
|
||||||
var roles []string
|
var roles []string
|
||||||
diags.Append(rolesSet.ElementsAs(ctx, &roles, false)...)
|
diags.Append(rolesSet.ElementsAs(ctx, &roles, false)...)
|
||||||
|
slices.Sort(roles)
|
||||||
return roles
|
return roles
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue