Compare commits
No commits in common. "alpha" and "v0.0.2-alpha" have entirely different histories.
alpha
...
v0.0.2-alp
263 changed files with 10112 additions and 36770 deletions
1
.github/actions/acc_test/README.md
vendored
1
.github/actions/acc_test/README.md
vendored
|
|
@ -1 +0,0 @@
|
||||||
# acceptance test action
|
|
||||||
262
.github/actions/acc_test/action.yaml
vendored
262
.github/actions/acc_test/action.yaml
vendored
|
|
@ -1,262 +0,0 @@
|
||||||
name: Acceptance Testing
|
|
||||||
description: "Acceptance Testing pipeline"
|
|
||||||
|
|
||||||
inputs:
|
|
||||||
test_timeout_string:
|
|
||||||
description: "string that determines the timeout (default: 45m)"
|
|
||||||
default: '45m'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
go-version:
|
|
||||||
description: "go version to install"
|
|
||||||
default: '1.25'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
project_id:
|
|
||||||
description: "STACKIT project ID for tests"
|
|
||||||
required: true
|
|
||||||
|
|
||||||
project_user_email:
|
|
||||||
required: true
|
|
||||||
description: "project user email for acc testing"
|
|
||||||
|
|
||||||
tf_acc_kek_key_id:
|
|
||||||
description: "KEK key ID"
|
|
||||||
required: true
|
|
||||||
|
|
||||||
tf_acc_kek_key_ring_id:
|
|
||||||
description: "KEK key ring ID"
|
|
||||||
required: true
|
|
||||||
|
|
||||||
tf_acc_kek_key_version:
|
|
||||||
description: "KEK key version"
|
|
||||||
required: true
|
|
||||||
|
|
||||||
tf_acc_kek_service_account:
|
|
||||||
description: "KEK service account email"
|
|
||||||
required: true
|
|
||||||
|
|
||||||
region:
|
|
||||||
description: "STACKIT region for tests"
|
|
||||||
default: 'eu01'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
service_account_json_content:
|
|
||||||
description: "STACKIT service account JSON file contents"
|
|
||||||
required: true
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
service_account_json_content_b64:
|
|
||||||
description: "STACKIT service account JSON file contents"
|
|
||||||
required: true
|
|
||||||
default: ""
|
|
||||||
|
|
||||||
service_account_json_file_path:
|
|
||||||
description: "STACKIT service account JSON file contents"
|
|
||||||
required: true
|
|
||||||
default: 'service_account.json'
|
|
||||||
|
|
||||||
test_file:
|
|
||||||
description: "testfile to run"
|
|
||||||
default: ''
|
|
||||||
|
|
||||||
|
|
||||||
#outputs:
|
|
||||||
# random-number:
|
|
||||||
# description: "Random number"
|
|
||||||
# value: ${{ steps.random-number-generator.outputs.random-number }}
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
# - name: Random Number Generator
|
|
||||||
# id: random-number-generator
|
|
||||||
# run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
|
|
||||||
# shell: bash
|
|
||||||
|
|
||||||
- name: Install needed tools
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::apt install"
|
|
||||||
set -e
|
|
||||||
apt-get -y -qq update >apt_update.log 2>apt_update_err.log
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
cat apt_update.log apt_update_err.log
|
|
||||||
fi
|
|
||||||
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget >apt_get.log 2>apt_get_err.log
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
cat apt_get.log apt_get_err.log
|
|
||||||
fi
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
||||||
- name: Setup JAVA
|
|
||||||
uses: actions/setup-java@v5
|
|
||||||
with:
|
|
||||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
|
||||||
java-version: '21'
|
|
||||||
|
|
||||||
- name: Install Go ${{ inputs.go-version }}
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
# go-version: ${{ inputs.go-version }}
|
|
||||||
check-latest: true
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- name: Determine GOMODCACHE
|
|
||||||
shell: bash
|
|
||||||
id: goenv
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
echo "gomodcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Restore cached GO pkg
|
|
||||||
id: cache-gopkg
|
|
||||||
uses: actions/cache/restore@v5
|
|
||||||
with:
|
|
||||||
path: "${{ steps.goenv.outputs.gomodcache }}"
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
- name: Install go tools
|
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::go install"
|
|
||||||
set -e
|
|
||||||
go mod download
|
|
||||||
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
|
|
||||||
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
|
|
||||||
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
|
|
||||||
echo "::endgroup::"
|
|
||||||
- name: Run go mod tidy
|
|
||||||
shell: bash
|
|
||||||
run: go mod tidy
|
|
||||||
|
|
||||||
- name: Save GO package Cache
|
|
||||||
id: cache-gopkg-save
|
|
||||||
uses: actions/cache/save@v5
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
${{ steps.goenv.outputs.gomodcache }}
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
- name: Creating service_account file from json input
|
|
||||||
if: inputs.service_account_json_content != ''
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::create service account file"
|
|
||||||
set -e
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
jsonFile="${{ inputs.service_account_json_file_path }}"
|
|
||||||
jsonFile="${jsonFile:-x}"
|
|
||||||
if [ "${jsonFile}" == "x" ]; then
|
|
||||||
echo "no service account file path provided"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "${jsonFile}" ]; then
|
|
||||||
echo "creating service account file '${{ inputs.service_account_json_file_path }}'"
|
|
||||||
echo "${{ inputs.service_account_json_content }}" > stackit/"${{ inputs.service_account_json_file_path }}"
|
|
||||||
fi
|
|
||||||
ls -l stackit/"${{ inputs.service_account_json_file_path }}"
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
||||||
- name: Creating service_account file from base64 json input
|
|
||||||
if: inputs.service_account_json_content_b64 != ''
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::create service account file"
|
|
||||||
set -e
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
jsonFile="${{ inputs.service_account_json_file_path }}"
|
|
||||||
jsonFile="${jsonFile:-x}"
|
|
||||||
if [ "${jsonFile}" == "x" ]; then
|
|
||||||
echo "no service account file path provided"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "${jsonFile}" ]; then
|
|
||||||
echo "creating service account file '${{ inputs.service_account_json_file_path }}'"
|
|
||||||
echo "${{ inputs.service_account_json_content_b64 }}" | base64 -d > stackit/"${{ inputs.service_account_json_file_path }}"
|
|
||||||
fi
|
|
||||||
ls -l stackit/"${{ inputs.service_account_json_file_path }}"
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
||||||
- name: Run acceptance test file
|
|
||||||
if: ${{ inputs.test_file != '' }}
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::go test file"
|
|
||||||
set -e
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
echo "Running acceptance tests for the terraform provider"
|
|
||||||
cd stackit || exit 1
|
|
||||||
TF_ACC=1 \
|
|
||||||
TF_ACC_PROJECT_ID=${TF_ACC_PROJECT_ID} \
|
|
||||||
TF_ACC_REGION=${TF_ACC_REGION} \
|
|
||||||
TF_ACC_TEST_PROJECT_USER_EMAIL=${TF_ACC_TEST_PROJECT_USER_EMAIL} \
|
|
||||||
TF_ACC_SERVICE_ACCOUNT_FILE="${PWD}/${{ inputs.service_account_json_file_path }}" \
|
|
||||||
TF_ACC_KEK_KEY_ID=${TF_ACC_KEK_KEY_ID} \
|
|
||||||
TF_ACC_KEK_KEY_RING_ID=${TF_ACC_KEK_KEY_RING_ID} \
|
|
||||||
TF_ACC_KEK_KEY_VERSION=${TF_ACC_KEK_KEY_VERSION} \
|
|
||||||
TF_ACC_KEK_SERVICE_ACCOUNT=${TF_ACC_KEK_SERVICE_ACCOUNT} \
|
|
||||||
go test ${{ inputs.test_file }} -count=1 -timeout=${{ inputs.test_timeout_string }}
|
|
||||||
echo "::endgroup::"
|
|
||||||
env:
|
|
||||||
TF_ACC_PROJECT_ID: ${{ inputs.project_id }}
|
|
||||||
TF_ACC_REGION: ${{ inputs.region }}
|
|
||||||
TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ inputs.project_user_email }}
|
|
||||||
TF_ACC_KEK_KEY_ID: ${{ inputs.tf_acc_kek_key_id }}
|
|
||||||
TF_ACC_KEK_KEY_RING_ID: ${{ inputs.tf_acc_kek_key_ring_id }}
|
|
||||||
TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }}
|
|
||||||
TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }}
|
|
||||||
|
|
||||||
# - name: Run test action
|
|
||||||
# if: ${{ inputs.test_file == '' }}
|
|
||||||
# env:
|
|
||||||
# TF_ACC: 1
|
|
||||||
# TF_ACC_PROJECT_ID: ${{ inputs.project_id }}
|
|
||||||
# TF_ACC_REGION: ${{ inputs.region }}
|
|
||||||
# TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ inputs.project_user_email }}
|
|
||||||
# TF_ACC_KEK_KEY_ID: ${{ inputs.tf_acc_kek_key_id }}
|
|
||||||
# TF_ACC_KEK_KEY_RING_ID: ${{ inputs.tf_acc_kek_key_ring_id }}
|
|
||||||
# TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }}
|
|
||||||
# TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }}
|
|
||||||
# TF_ACC_SERVICE_ACCOUNT_FILE: "${PWD}/${{ inputs.service_account_json_file_path }}"
|
|
||||||
# uses: robherley/go-test-action@v0.1.0
|
|
||||||
# with:
|
|
||||||
# testArguments: "./... -timeout 45m"
|
|
||||||
|
|
||||||
- name: Run acceptance tests
|
|
||||||
if: ${{ inputs.test_file == '' }}
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "::group::go test all"
|
|
||||||
set -e
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
echo "Running acceptance tests for the terraform provider"
|
|
||||||
cd stackit || exit 1
|
|
||||||
TF_ACC=1 \
|
|
||||||
TF_ACC_PROJECT_ID=${TF_ACC_PROJECT_ID} \
|
|
||||||
TF_ACC_REGION=${TF_ACC_REGION} \
|
|
||||||
TF_ACC_TEST_PROJECT_USER_EMAIL=${TF_ACC_TEST_PROJECT_USER_EMAIL} \
|
|
||||||
TF_ACC_SERVICE_ACCOUNT_FILE="${PWD}/${{ inputs.service_account_json_file_path }}" \
|
|
||||||
TF_ACC_KEK_KEY_ID=${TF_ACC_KEK_KEY_ID} \
|
|
||||||
TF_ACC_KEK_KEY_RING_ID=${TF_ACC_KEK_KEY_RING_ID} \
|
|
||||||
TF_ACC_KEK_KEY_VERSION=${TF_ACC_KEK_KEY_VERSION} \
|
|
||||||
TF_ACC_KEK_SERVICE_ACCOUNT=${TF_ACC_KEK_SERVICE_ACCOUNT} \
|
|
||||||
go test ./... -count=1 -timeout=${{ inputs.test_timeout_string }}
|
|
||||||
echo "::endgroup::"
|
|
||||||
env:
|
|
||||||
TF_ACC_PROJECT_ID: ${{ inputs.project_id }}
|
|
||||||
TF_ACC_REGION: ${{ inputs.region }}
|
|
||||||
TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ inputs.project_user_email }}
|
|
||||||
TF_ACC_KEK_KEY_ID: ${{ inputs.tf_acc_kek_key_id }}
|
|
||||||
TF_ACC_KEK_KEY_RING_ID: ${{ inputs.tf_acc_kek_key_ring_id }}
|
|
||||||
TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }}
|
|
||||||
TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }}
|
|
||||||
55
.github/actions/build/action.yaml
vendored
55
.github/actions/build/action.yaml
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
name: Build
|
name: Build
|
||||||
description: "Build pipeline"
|
description: "Build pipeline"
|
||||||
inputs:
|
inputs:
|
||||||
|
|
@ -20,63 +21,25 @@ runs:
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
apt-get -y -qq update
|
apt-get -y -qq update
|
||||||
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget unzip bc
|
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Install Go ${{ inputs.go-version }}
|
- name: Install Go ${{ inputs.go-version }}
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
# go-version: ${{ inputs.go-version }}
|
go-version: ${{ inputs.go-version }}
|
||||||
check-latest: true
|
check-latest: true
|
||||||
go-version-file: 'go.mod'
|
go-version-file: 'go.mod'
|
||||||
|
|
||||||
- name: Determine GOMODCACHE
|
|
||||||
shell: bash
|
|
||||||
id: goenv
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
# echo "::set-output name=gomodcache::$(go env GOMODCACHE)"
|
|
||||||
echo "gomodcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Restore cached GO pkg
|
|
||||||
id: cache-gopkg
|
|
||||||
uses: actions/cache/restore@v5
|
|
||||||
with:
|
|
||||||
path: "${{ steps.goenv.outputs.gomodcache }}"
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
- name: Install go tools
|
- name: Install go tools
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
go install golang.org/x/tools/cmd/goimports@latest
|
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-framework/cmd/tfplugingen-framework@latest
|
||||||
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest
|
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest
|
||||||
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
|
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.24.0
|
||||||
|
|
||||||
# - name: Run build pkg directory
|
|
||||||
# shell: bash
|
|
||||||
# run: |
|
|
||||||
# set -e
|
|
||||||
# go run generator/main.go build
|
|
||||||
|
|
||||||
- name: Get all go packages
|
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
go get ./...
|
|
||||||
|
|
||||||
- name: Save Cache
|
|
||||||
id: cache-gopkg-save
|
|
||||||
uses: actions/cache/save@v5
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
${{ steps.goenv.outputs.gomodcache }}
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
- name: Setup JAVA ${{ inputs.java-distribution }} ${{ inputs.go-version }}
|
- name: Setup JAVA ${{ inputs.java-distribution }} ${{ inputs.go-version }}
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
|
|
@ -84,6 +47,16 @@ runs:
|
||||||
distribution: ${{ inputs.java-distribution }} # See 'Supported distributions' for available options
|
distribution: ${{ inputs.java-distribution }} # See 'Supported distributions' for available options
|
||||||
java-version: ${{ inputs.java-version }}
|
java-version: ${{ inputs.java-version }}
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Run build pkg directory
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
go run cmd/main.go build
|
||||||
|
|
||||||
|
|
||||||
- name: Run make to build app
|
- name: Run make to build app
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
71
.github/actions/setup-cache-go/action.yaml
vendored
71
.github/actions/setup-cache-go/action.yaml
vendored
|
|
@ -1,71 +0,0 @@
|
||||||
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 }}
|
|
||||||
|
|
@ -6,11 +6,6 @@ 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'
|
||||||
|
|
@ -22,39 +17,6 @@ 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
|
||||||
|
|
@ -137,72 +99,14 @@ 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:
|
||||||
if: ${{ github.event_name != 'schedule' }}
|
name: CI
|
||||||
name: CI run build and linting
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: config
|
needs: config
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
uses: ./.github/actions/build
|
uses: ./.github/actions/build
|
||||||
|
|
@ -226,45 +130,27 @@ jobs:
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v9
|
uses: golangci/golangci-lint-action@v9
|
||||||
with:
|
with:
|
||||||
version: v2.9
|
version: v2.7
|
||||||
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: Linting
|
- name: Lint
|
||||||
run: make lint
|
run: make lint
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
# - name: Testing
|
- name: Test
|
||||||
# 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:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Check GoReleaser
|
- name: Check GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v6
|
uses: goreleaser/goreleaser-action@v6
|
||||||
343
.github/workflows/ci_new.yaml
vendored
343
.github/workflows/ci_new.yaml
vendored
|
|
@ -1,343 +0,0 @@
|
||||||
name: CI Workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- alpha
|
|
||||||
- main
|
|
||||||
workflow_dispatch:
|
|
||||||
schedule:
|
|
||||||
# every sunday at 00:00
|
|
||||||
# - cron: '0 0 * * 0'
|
|
||||||
# every day at 00:00
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '!main'
|
|
||||||
- '!alpha'
|
|
||||||
paths:
|
|
||||||
- '!.github'
|
|
||||||
|
|
||||||
env:
|
|
||||||
GO_VERSION: "1.25"
|
|
||||||
CODE_COVERAGE_FILE_NAME: "coverage.out" # must be the same as in Makefile
|
|
||||||
CODE_COVERAGE_ARTIFACT_NAME: "code-coverage"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
config:
|
|
||||||
if: ${{ github.event_name != 'schedule' }}
|
|
||||||
name: Check GoReleaser config
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Check GoReleaser
|
|
||||||
uses: goreleaser/goreleaser-action@v7
|
|
||||||
with:
|
|
||||||
args: check
|
|
||||||
|
|
||||||
prepare:
|
|
||||||
name: Prepare GO cache
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read # Required to identify workflow run.
|
|
||||||
checks: write # Required to add status summary.
|
|
||||||
contents: read # Required to checkout repository.
|
|
||||||
pull-requests: write # Required to add PR comment.
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Install Go ${{ inputs.go-version }}
|
|
||||||
id: go-install
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
# go-version: ${{ inputs.go-version }}
|
|
||||||
check-latest: true
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- name: Determine GOMODCACHE
|
|
||||||
shell: bash
|
|
||||||
id: goenv
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
# echo "::set-output name=gomodcache::$(go env GOMODCACHE)"
|
|
||||||
echo "gomodcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Restore cached GO pkg
|
|
||||||
id: cache-gopkg
|
|
||||||
uses: actions/cache/restore@v5
|
|
||||||
with:
|
|
||||||
path: "${{ steps.goenv.outputs.gomodcache }}"
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
- name: Install go tools
|
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
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: Get all go packages
|
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
go get ./...
|
|
||||||
|
|
||||||
- name: Save Cache
|
|
||||||
if: steps.cache-gopkg.outputs.cache-hit != 'true'
|
|
||||||
id: cache-gopkg-save
|
|
||||||
uses: actions/cache/save@v5
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
${{ steps.goenv.outputs.gomodcache }}
|
|
||||||
key: ${{ runner.os }}-gopkg
|
|
||||||
|
|
||||||
|
|
||||||
publish_test:
|
|
||||||
name: "Test readiness for publishing provider"
|
|
||||||
needs:
|
|
||||||
- config
|
|
||||||
- prepare
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read # Required to identify workflow run.
|
|
||||||
checks: write # Required to add status summary.
|
|
||||||
contents: read # Required to checkout repository.
|
|
||||||
pull-requests: write # Required to add PR comment.
|
|
||||||
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 unzip bc
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
# go-version: ${{ env.GO_VERSION }}
|
|
||||||
check-latest: true
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- 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: Run build pkg directory
|
|
||||||
# run: |
|
|
||||||
# go run generator/main.go build
|
|
||||||
|
|
||||||
- name: Set up s3cfg
|
|
||||||
run: |
|
|
||||||
cat <<'EOF' >> ~/.s3cfg
|
|
||||||
[default]
|
|
||||||
host_base = https://object.storage.eu01.onstackit.cloud
|
|
||||||
host_bucket = https://%(bucket).object.storage.eu01.onstackit.cloud
|
|
||||||
check_ssl_certificate = False
|
|
||||||
access_key = ${{ secrets.S3_ACCESS_KEY }}
|
|
||||||
secret_key = ${{ secrets.S3_SECRET_KEY }}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Import GPG key
|
|
||||||
run: |
|
|
||||||
echo "${{ secrets.PRIVATE_KEY_PEM }}" > ~/private.key.pem
|
|
||||||
gpg --import ~/private.key.pem
|
|
||||||
rm ~/private.key.pem
|
|
||||||
|
|
||||||
- name: Run GoReleaser with SNAPSHOT
|
|
||||||
id: goreleaser
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
|
|
||||||
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
|
|
||||||
uses: goreleaser/goreleaser-action@v7
|
|
||||||
with:
|
|
||||||
args: release --skip publish --clean --snapshot
|
|
||||||
|
|
||||||
- name: Prepare key file
|
|
||||||
run: |
|
|
||||||
echo "${{ secrets.PUBLIC_KEY_PEM }}" >public_key.pem
|
|
||||||
|
|
||||||
- name: Prepare provider directory structure
|
|
||||||
run: |
|
|
||||||
VERSION=$(jq -r .version < dist/metadata.json)
|
|
||||||
go run generator/main.go \
|
|
||||||
publish \
|
|
||||||
--namespace=mhenselin \
|
|
||||||
--providerName=stackitprivatepreview \
|
|
||||||
--repoName=terraform-provider-stackitprivatepreview \
|
|
||||||
--domain=tfregistry.sysops.stackit.rocks \
|
|
||||||
--gpgFingerprint="${{ secrets.GPG_FINGERPRINT }}" \
|
|
||||||
--gpgPubKeyFile=public_key.pem \
|
|
||||||
--version=${VERSION}
|
|
||||||
|
|
||||||
testing:
|
|
||||||
name: CI run tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- config
|
|
||||||
- prepare
|
|
||||||
env:
|
|
||||||
TF_ACC_PROJECT_ID: ${{ vars.TF_ACC_PROJECT_ID }}
|
|
||||||
TF_ACC_ORGANIZATION_ID: ${{ vars.TF_ACC_ORGANIZATION_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: |
|
|
||||||
TF_ACC_SERVICE_ACCOUNT_FILE=~/.service_account.json
|
|
||||||
export TF_ACC_SERVICE_ACCOUNT_FILE
|
|
||||||
make test
|
|
||||||
|
|
||||||
# - name: Acceptance Testing
|
|
||||||
# env:
|
|
||||||
# TF_ACC: "1"
|
|
||||||
# if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
# run: |
|
|
||||||
# TF_ACC_SERVICE_ACCOUNT_FILE=~/.service_account.json
|
|
||||||
# export TF_ACC_SERVICE_ACCOUNT_FILE
|
|
||||||
# make test-acceptance-tf
|
|
||||||
|
|
||||||
- name: Run Test
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
uses: ./.github/actions/acc_test
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
project_id: ${{ vars.TF_ACC_PROJECT_ID }}
|
|
||||||
region: ${{ vars.TF_ACC_REGION }}
|
|
||||||
service_account_json_content_b64: "${{ secrets.TF_ACC_SERVICE_ACCOUNT_JSON_B64 }}"
|
|
||||||
project_user_email: ${{ vars.TEST_PROJECT_USER_EMAIL }}
|
|
||||||
tf_acc_kek_key_id: ${{ vars.TF_ACC_KEK_KEY_ID }}
|
|
||||||
tf_acc_kek_key_ring_id: ${{ vars.TF_ACC_KEK_KEY_RING_ID }}
|
|
||||||
tf_acc_kek_key_version: ${{ vars.TF_ACC_KEK_KEY_VERSION }}
|
|
||||||
tf_acc_kek_service_account: ${{ vars.TF_ACC_KEK_SERVICE_ACCOUNT }}
|
|
||||||
# service_account_json_file_path: "~/service_account.json"
|
|
||||||
|
|
||||||
- name: Check coverage threshold
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
make coverage
|
|
||||||
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
|
||||||
echo "Coverage: $COVERAGE%"
|
|
||||||
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
|
|
||||||
echo "Coverage is below 80%"
|
|
||||||
# exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Archive code coverage results
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
|
||||||
path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
|
||||||
|
|
||||||
main:
|
|
||||||
if: ${{ github.event_name != 'schedule' }}
|
|
||||||
name: CI run build and linting
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- config
|
|
||||||
- prepare
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
# - uses: actions/cache@v5
|
|
||||||
# id: cache
|
|
||||||
# with:
|
|
||||||
# path: path/to/dependencies
|
|
||||||
# key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
|
||||||
|
|
||||||
# - name: Install Dependencies
|
|
||||||
# if: steps.cache.outputs.cache-hit != 'true'
|
|
||||||
# run: /install.sh
|
|
||||||
|
|
||||||
- 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: "Ensure docs are up-to-date"
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
run: ./scripts/check-docs.sh
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: "Run go mod tidy"
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
run: go mod tidy
|
|
||||||
|
|
||||||
- name: golangci-lint
|
|
||||||
uses: golangci/golangci-lint-action@v9
|
|
||||||
with:
|
|
||||||
version: v2.10
|
|
||||||
args: --config=.golang-ci.yaml --allow-parallel-runners --timeout=5m
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Linting terraform files
|
|
||||||
run: make lint-tf
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
code_coverage:
|
|
||||||
name: "Code coverage report"
|
|
||||||
if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- main
|
|
||||||
- prepare
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
actions: read # to download code coverage results from "main" job
|
|
||||||
pull-requests: write # write permission needed to comment on PR
|
|
||||||
steps:
|
|
||||||
- name: Install needed tools
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
apt-get -y -qq update
|
|
||||||
apt-get -y -qq install sudo
|
|
||||||
|
|
||||||
- name: Check new code coverage
|
|
||||||
uses: fgrosse/go-coverage-report@v1.2.0
|
|
||||||
continue-on-error: true # Add this line to prevent pipeline failures in forks
|
|
||||||
with:
|
|
||||||
coverage-artifact-name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
|
||||||
coverage-file-name: ${{ env.CODE_COVERAGE_FILE_NAME }}
|
|
||||||
root-package: 'github.com/stackitcloud/terraform-provider-stackit'
|
|
||||||
35
.github/workflows/publish.yaml
vendored
35
.github/workflows/publish.yaml
vendored
|
|
@ -23,7 +23,7 @@ jobs:
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Check GoReleaser
|
- name: Check GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
args: check
|
args: check
|
||||||
|
|
||||||
|
|
@ -43,15 +43,10 @@ jobs:
|
||||||
apt-get -y -qq update
|
apt-get -y -qq update
|
||||||
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget
|
apt-get -y -qq install jq python3 python3-pip python-is-python3 s3cmd git make wget
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
# go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ env.GO_VERSION }}
|
||||||
check-latest: true
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
- name: Install go tools
|
- name: Install go tools
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -65,6 +60,13 @@ jobs:
|
||||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Run build pkg directory
|
||||||
|
run: |
|
||||||
|
go run cmd/main.go build
|
||||||
|
|
||||||
- name: Set up s3cfg
|
- name: Set up s3cfg
|
||||||
run: |
|
run: |
|
||||||
cat <<'EOF' >> ~/.s3cfg
|
cat <<'EOF' >> ~/.s3cfg
|
||||||
|
|
@ -88,7 +90,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
|
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
|
||||||
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
|
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
args: release --skip publish --clean --snapshot
|
args: release --skip publish --clean --snapshot
|
||||||
|
|
||||||
|
|
@ -98,7 +100,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
|
GITHUB_TOKEN: ${{ env.FORGEJO_TOKEN }}
|
||||||
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
|
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
args: release --skip publish --clean
|
args: release --skip publish --clean
|
||||||
|
|
||||||
|
|
@ -109,7 +111,7 @@ jobs:
|
||||||
- name: Prepare provider directory structure
|
- name: Prepare provider directory structure
|
||||||
run: |
|
run: |
|
||||||
VERSION=$(jq -r .version < dist/metadata.json)
|
VERSION=$(jq -r .version < dist/metadata.json)
|
||||||
go run generator/main.go \
|
go run cmd/main.go \
|
||||||
publish \
|
publish \
|
||||||
--namespace=mhenselin \
|
--namespace=mhenselin \
|
||||||
--providerName=stackitprivatepreview \
|
--providerName=stackitprivatepreview \
|
||||||
|
|
@ -125,16 +127,3 @@ jobs:
|
||||||
cd release/
|
cd release/
|
||||||
s3cmd put --recursive v1 s3://terraform-provider-privatepreview/
|
s3cmd put --recursive v1 s3://terraform-provider-privatepreview/
|
||||||
s3cmd put --recursive .well-known s3://terraform-provider-privatepreview/
|
s3cmd put --recursive .well-known s3://terraform-provider-privatepreview/
|
||||||
|
|
||||||
- name: Import SSH key
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.DOCS_UPLOAD_SSH_KEY }}" > ~/.ssh/id_ed25519
|
|
||||||
chmod 0600 ~/.ssh/id_ed25519
|
|
||||||
|
|
||||||
- name: Upload docs via scp
|
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
ssh -o StrictHostKeyChecking=no ubuntu@${{ vars.DOCS_SERVER_IP }} 'rm -rf /srv/www/docs'
|
|
||||||
echo "${{ github.ref_name }}" >docs/_version.txt
|
|
||||||
scp -o StrictHostKeyChecking=no -r docs ubuntu@${{ vars.DOCS_SERVER_IP }}:/srv/www/
|
|
||||||
|
|
|
||||||
8
.github/workflows/release.yaml
vendored
8
.github/workflows/release.yaml
vendored
|
|
@ -18,23 +18,21 @@ jobs:
|
||||||
goreleaser:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# Allow goreleaser to access older tag information.
|
# Allow goreleaser to access older tag information.
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
- uses: https://code.forgejo.org/actions/setup-go@v6
|
|
||||||
with:
|
with:
|
||||||
go-version-file: "go.mod"
|
go-version-file: "go.mod"
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
- name: Import GPG key
|
- name: Import GPG key
|
||||||
uses: crazy-max/ghaction-import-gpg@v6
|
uses: crazy-max/ghaction-import-gpg@v6
|
||||||
id: import_gpg
|
id: import_gpg
|
||||||
with:
|
with:
|
||||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v7
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
args: release --clean
|
args: release --clean
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
2
.github/workflows/renovate.yaml
vendored
2
.github/workflows/renovate.yaml
vendored
|
|
@ -11,7 +11,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
- name: Self-hosted Renovate
|
- name: Self-hosted Renovate
|
||||||
uses: renovatebot/github-action@v41.0.0
|
uses: renovatebot/github-action@v41.0.0
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
29
.github/workflows/runnerstats.yaml
vendored
29
.github/workflows/runnerstats.yaml
vendored
|
|
@ -1,29 +0,0 @@
|
||||||
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
|
|
||||||
30
.github/workflows/tf-acc-test.yaml
vendored
30
.github/workflows/tf-acc-test.yaml
vendored
|
|
@ -7,23 +7,21 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
acc_test:
|
main:
|
||||||
name: Acceptance Tests
|
name: Acceptance Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
- name: Install project tools and dependencies
|
||||||
- name: Run Test
|
run: make project-tools
|
||||||
uses: ./.github/actions/acc_test
|
- name: Run tests
|
||||||
with:
|
run: |
|
||||||
go-version: ${{ env.GO_VERSION }}
|
make test-acceptance-tf TF_ACC_PROJECT_ID=$${{ secrets.TF_ACC_PROJECT_ID }} TF_ACC_ORGANIZATION_ID=$${{ secrets.TF_ACC_ORGANIZATION_ID }} TF_ACC_REGION="eu01"
|
||||||
project_id: ${{ vars.TF_ACC_PROJECT_ID }}
|
env:
|
||||||
region: 'eu01'
|
STACKIT_SERVICE_ACCOUNT_TOKEN: ${{ secrets.TF_ACC_SERVICE_ACCOUNT_TOKEN }}
|
||||||
service_account_json_content_b64: "${{ secrets.TF_ACC_SERVICE_ACCOUNT_JSON_B64 }}"
|
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL: ${{ secrets.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_EMAIL }}
|
||||||
project_user_email: ${{ vars.TEST_PROJECT_USER_EMAIL }}
|
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN: ${{ secrets.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN }}
|
||||||
tf_acc_kek_key_id: ${{ vars.TF_ACC_KEK_KEY_ID }}
|
TF_ACC_TEST_PROJECT_PARENT_CONTAINER_ID: ${{ secrets.TF_ACC_TEST_PROJECT_PARENT_CONTAINER_ID }}
|
||||||
tf_acc_kek_key_ring_id: ${{ vars.TF_ACC_KEK_KEY_RING_ID }}
|
TF_ACC_TEST_PROJECT_PARENT_UUID: ${{ secrets.TF_ACC_TEST_PROJECT_PARENT_UUID }}
|
||||||
tf_acc_kek_key_version: ${{ vars.TF_ACC_KEK_KEY_VERSION }}
|
TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ secrets.TF_ACC_TEST_PROJECT_USER_EMAIL }}
|
||||||
tf_acc_kek_service_account: ${{ vars.TF_ACC_KEK_SERVICE_ACCOUNT }}
|
|
||||||
# service_account_json_file_path: "~/service_account.json"
|
|
||||||
|
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -40,12 +40,8 @@ coverage.out
|
||||||
coverage.html
|
coverage.html
|
||||||
generated
|
generated
|
||||||
stackit-sdk-generator
|
stackit-sdk-generator
|
||||||
stackit-sdk-generator/**
|
|
||||||
dist
|
dist
|
||||||
|
|
||||||
.secrets
|
.secrets
|
||||||
|
|
||||||
pkg_gen
|
pkg_gen
|
||||||
/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' ]
|
||||||
|
|
|
||||||
14
Makefile
14
Makefile
|
|
@ -12,20 +12,17 @@ project-tools:
|
||||||
# LINT
|
# LINT
|
||||||
lint-golangci-lint:
|
lint-golangci-lint:
|
||||||
@echo "Linting with golangci-lint"
|
@echo "Linting with golangci-lint"
|
||||||
@go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint run --fix --config .golang-ci.yaml
|
@$(SCRIPTS_BASE)/lint-golangci-lint.sh
|
||||||
|
|
||||||
|
|
||||||
lint-tf:
|
lint-tf:
|
||||||
@echo "Linting terraform files"
|
@echo "Linting terraform files"
|
||||||
@terraform fmt -check -diff -recursive examples/
|
@terraform fmt -check -diff -recursive
|
||||||
@terraform fmt -check -diff -recursive stackit/
|
|
||||||
|
|
||||||
lint: lint-golangci-lint lint-tf
|
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:
|
||||||
|
|
@ -37,16 +34,15 @@ 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 -timeout 0 ./... -count=1 -coverprofile=../coverage.out && cd $(ROOT_DIR)
|
@cd $(ROOT_DIR)/stackit && go test ./... -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 -timeout 0 ./... -count=1 -coverprofile=../coverage.out || true) && cd $(ROOT_DIR)
|
@cd $(ROOT_DIR)/stackit && (go test ./... -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
|
||||||
|
|
|
||||||
21
README.md
21
README.md
|
|
@ -1,14 +1,15 @@
|
||||||
<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 <br />(PRIVATE PREVIEW)
|
# STACKIT Terraform Provider
|
||||||
|
|
||||||
[](https://registry.terraform.io/providers/stackitcloud/stackit/latest)  [](https://www.apache.org/licenses/LICENSE-2.0)
|
[](https://goreportcard.com/report/github.com/stackitcloud/terraform-provider-stackit) [](https://registry.terraform.io/providers/stackitcloud/stackit/latest)  [](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
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 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 a **private preview only**, which allows you to manage STACKIT resources through Terraform.
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|
@ -17,22 +18,20 @@ To install the [STACKIT Terraform Provider](https://registry.terraform.io/provid
|
||||||
```hcl
|
```hcl
|
||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
stackitprivatepreview = {
|
stackit = {
|
||||||
source = "tfregistry.sysops.stackit.rocks/mhenselin/stackitprivatepreview"
|
source = "stackitcloud/stackit"
|
||||||
version = "= 0.0.5-alpha"
|
version = "X.X.X"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provider "stackitprivatepreview" {
|
provider "stackit" {
|
||||||
# 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:
|
||||||
|
|
|
||||||
737
cmd/cmd/build/build.go
Normal file
737
cmd/cmd/build/build.go
Normal file
|
|
@ -0,0 +1,737 @@
|
||||||
|
package build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/ldez/go-git-cmd-wrapper/v2/clone"
|
||||||
|
"github.com/ldez/go-git-cmd-wrapper/v2/git"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OAS_REPO_NAME = "stackit-api-specifications"
|
||||||
|
OAS_REPO = "https://github.com/stackitcloud/stackit-api-specifications.git"
|
||||||
|
GEN_REPO_NAME = "stackit-sdk-generator"
|
||||||
|
GEN_REPO = "https://github.com/stackitcloud/stackit-sdk-generator.git"
|
||||||
|
)
|
||||||
|
|
||||||
|
type version struct {
|
||||||
|
verString string
|
||||||
|
major int
|
||||||
|
minor int
|
||||||
|
}
|
||||||
|
|
||||||
|
func Build() error {
|
||||||
|
slog.Info("Starting Builder")
|
||||||
|
root, err := getRoot()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if root == nil || *root == "" {
|
||||||
|
return fmt.Errorf("unable to determine root directory from git")
|
||||||
|
}
|
||||||
|
slog.Info("Using root directory", "dir", *root)
|
||||||
|
|
||||||
|
slog.Info("Cleaning up old generator directory")
|
||||||
|
err = os.RemoveAll(path.Join(*root, GEN_REPO_NAME))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Cleaning up old packages directory")
|
||||||
|
err = os.RemoveAll(path.Join(*root, "pkg_gen"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Creating generator dir", "dir", fmt.Sprintf("%s/%s", *root, GEN_REPO_NAME))
|
||||||
|
genDir, err := createGeneratorDir(*root, GEN_REPO, GEN_REPO_NAME)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Creating oas dir", "dir", fmt.Sprintf("%s/%s", *root, OAS_REPO_NAME))
|
||||||
|
repoDir, err := createRepoDir(genDir, OAS_REPO, OAS_REPO_NAME)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Retrieving versions from subdirs")
|
||||||
|
// TODO - major
|
||||||
|
verMap, err := getVersions(repoDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Reducing to only latest or highest")
|
||||||
|
res, err := getOnlyLatest(verMap)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Creating OAS dir")
|
||||||
|
err = os.MkdirAll(path.Join(genDir, "oas"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Copying OAS files")
|
||||||
|
for service, item := range res {
|
||||||
|
baseService := strings.TrimSuffix(service, "alpha")
|
||||||
|
baseService = strings.TrimSuffix(baseService, "beta")
|
||||||
|
itemVersion := fmt.Sprintf("v%d%s", item.major, item.verString)
|
||||||
|
if item.minor != 0 {
|
||||||
|
itemVersion = itemVersion + "" + strconv.Itoa(item.minor)
|
||||||
|
}
|
||||||
|
srcFile := path.Join(
|
||||||
|
repoDir,
|
||||||
|
"services",
|
||||||
|
baseService,
|
||||||
|
itemVersion,
|
||||||
|
fmt.Sprintf("%s.json", baseService),
|
||||||
|
)
|
||||||
|
dstFile := path.Join(genDir, "oas", fmt.Sprintf("%s.json", service))
|
||||||
|
_, err = copyFile(srcFile, dstFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Cleaning up", "dir", repoDir)
|
||||||
|
err = os.RemoveAll(filepath.Dir(repoDir))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Changing dir", "dir", genDir)
|
||||||
|
err = os.Chdir(genDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Calling make", "command", "generate-go-sdk")
|
||||||
|
cmd := exec.Command("make", "generate-go-sdk")
|
||||||
|
var stdOut, stdErr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdOut
|
||||||
|
cmd.Stderr = &stdErr
|
||||||
|
|
||||||
|
if err = cmd.Start(); err != nil {
|
||||||
|
slog.Error("cmd.Start", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cmd.Wait(); err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
|
slog.Error("cmd.Wait", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("cmd.Wait", "err", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Cleaning up go.mod and go.sum files")
|
||||||
|
cleanDir := path.Join(genDir, "sdk-repo-updated", "services")
|
||||||
|
dirEntries, err := os.ReadDir(cleanDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
err = deleteFiles(
|
||||||
|
path.Join(cleanDir, entry.Name(), "go.mod"),
|
||||||
|
path.Join(cleanDir, entry.Name(), "go.sum"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Changing dir", "dir", *root)
|
||||||
|
err = os.Chdir(*root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Rearranging package directories")
|
||||||
|
err = os.MkdirAll(path.Join(*root, "pkg_gen"), 0755) // noqa:gosec
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
srcDir := path.Join(genDir, "sdk-repo-updated", "services")
|
||||||
|
items, err := os.ReadDir(srcDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, item := range items {
|
||||||
|
if item.IsDir() {
|
||||||
|
slog.Info(" -> package", "name", item.Name())
|
||||||
|
tgtDir := path.Join(*root, "pkg_gen", item.Name())
|
||||||
|
// no backup needed as we generate new
|
||||||
|
//bakName := fmt.Sprintf("%s.%s", item.Name(), time.Now().Format("20060102-150405"))
|
||||||
|
//if _, err = os.Stat(tgtDir); !os.IsNotExist(err) {
|
||||||
|
// err = os.Rename(
|
||||||
|
// tgtDir,
|
||||||
|
// path.Join(*root, "pkg", bakName),
|
||||||
|
// )
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
err = os.Rename(path.Join(srcDir, item.Name()), tgtDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait is placed outside now
|
||||||
|
//if _, err = os.Stat(path.Join(*root, "pkg", bakName, "wait")); !os.IsNotExist(err) {
|
||||||
|
// slog.Info(" Copying wait subfolder")
|
||||||
|
// err = os.Rename(path.Join(*root, "pkg", bakName, "wait"), path.Join(tgtDir, "wait"))
|
||||||
|
// if err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Checking needed commands available")
|
||||||
|
err = checkCommands([]string{"tfplugingen-framework", "tfplugingen-openapi"})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Generating service boilerplate")
|
||||||
|
err = generateServiceFiles(*root, path.Join(*root, GEN_REPO_NAME))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Copying all service files")
|
||||||
|
err = CopyDirectory(
|
||||||
|
path.Join(*root, "generated", "internal", "services"),
|
||||||
|
path.Join(*root, "stackit", "internal", "services"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = createBoilerplate(*root, path.Join(*root, "stackit", "internal", "services"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Finally removing temporary files and directories")
|
||||||
|
//err = os.RemoveAll(path.Join(*root, "generated"))
|
||||||
|
//if err != nil {
|
||||||
|
// slog.Error("RemoveAll", "dir", path.Join(*root, "generated"), "err", err)
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
|
err = os.RemoveAll(path.Join(*root, GEN_REPO_NAME))
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("RemoveAll", "dir", path.Join(*root, GEN_REPO_NAME), "err", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("Done")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type templateData struct {
|
||||||
|
PackageName string
|
||||||
|
NameCamel string
|
||||||
|
NamePascal string
|
||||||
|
NameSnake string
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileExists(path string) bool {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func createBoilerplate(rootFolder, folder string) error {
|
||||||
|
services, err := os.ReadDir(folder)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, svc := range services {
|
||||||
|
if !svc.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resources, err := os.ReadDir(path.Join(folder, svc.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var handleDS bool
|
||||||
|
var handleRes bool
|
||||||
|
var foundDS bool
|
||||||
|
var foundRes bool
|
||||||
|
|
||||||
|
for _, res := range resources {
|
||||||
|
if !res.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceName := res.Name()
|
||||||
|
|
||||||
|
dsFile := path.Join(folder, svc.Name(), res.Name(), "datasources_gen", fmt.Sprintf("%s_data_source_gen.go", res.Name()))
|
||||||
|
handleDS = fileExists(dsFile)
|
||||||
|
|
||||||
|
resFile := path.Join(folder, svc.Name(), res.Name(), "resources_gen", fmt.Sprintf("%s_resource_gen.go", res.Name()))
|
||||||
|
handleRes = fileExists(resFile)
|
||||||
|
|
||||||
|
dsGoFile := path.Join(folder, svc.Name(), res.Name(), "datasource.go")
|
||||||
|
foundDS = fileExists(dsGoFile)
|
||||||
|
|
||||||
|
resGoFile := path.Join(folder, svc.Name(), res.Name(), "resource.go")
|
||||||
|
foundRes = fileExists(resGoFile)
|
||||||
|
|
||||||
|
if handleDS && !foundDS {
|
||||||
|
slog.Info("Creating missing datasource.go", "service", svc.Name(), "resource", resourceName)
|
||||||
|
if !ValidateSnakeCase(resourceName) {
|
||||||
|
return errors.New("resource name is invalid")
|
||||||
|
}
|
||||||
|
|
||||||
|
tplName := "data_source_scaffold.gotmpl"
|
||||||
|
err = writeTemplateToFile(
|
||||||
|
tplName,
|
||||||
|
path.Join(rootFolder, "tools", "templates", tplName),
|
||||||
|
path.Join(folder, svc.Name(), res.Name(), "datasource.go"),
|
||||||
|
&templateData{
|
||||||
|
PackageName: svc.Name(),
|
||||||
|
NameCamel: ToCamelCase(resourceName),
|
||||||
|
NamePascal: ToPascalCase(resourceName),
|
||||||
|
NameSnake: resourceName,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if handleRes && !foundRes {
|
||||||
|
slog.Info("Creating missing resource.go", "service", svc.Name(), "resource", resourceName)
|
||||||
|
if !ValidateSnakeCase(resourceName) {
|
||||||
|
return errors.New("resource name is invalid")
|
||||||
|
}
|
||||||
|
|
||||||
|
tplName := "resource_scaffold.gotmpl"
|
||||||
|
err = writeTemplateToFile(
|
||||||
|
tplName,
|
||||||
|
path.Join(rootFolder, "tools", "templates", tplName),
|
||||||
|
path.Join(folder, svc.Name(), res.Name(), "resource.go"),
|
||||||
|
&templateData{
|
||||||
|
PackageName: svc.Name(),
|
||||||
|
NameCamel: ToCamelCase(resourceName),
|
||||||
|
NamePascal: ToPascalCase(resourceName),
|
||||||
|
NameSnake: resourceName,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ucfirst(s string) string {
|
||||||
|
if len(s) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.ToUpper(s[:1]) + s[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeTemplateToFile(tplName, tplFile, outFile string, data *templateData) error {
|
||||||
|
fn := template.FuncMap{
|
||||||
|
"ucfirst": ucfirst,
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.New(tplName).Funcs(fn).ParseFiles(tplFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var f *os.File
|
||||||
|
f, err = os.Create(outFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tmpl.Execute(f, *data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateServiceFiles(rootDir, generatorDir string) error {
|
||||||
|
// slog.Info("Generating specs folder")
|
||||||
|
err := os.MkdirAll(path.Join(rootDir, "generated", "specs"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
specs, err := os.ReadDir(path.Join(rootDir, "service_specs"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, spec := range specs {
|
||||||
|
if spec.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// slog.Info("Checking spec", "name", spec.Name())
|
||||||
|
r := regexp.MustCompile(`^([a-z-]+)_(.*)_config.yml$`)
|
||||||
|
matches := r.FindAllStringSubmatch(spec.Name(), -1)
|
||||||
|
if matches != nil {
|
||||||
|
fileName := matches[0][0]
|
||||||
|
service := matches[0][1]
|
||||||
|
resource := matches[0][2]
|
||||||
|
slog.Info(
|
||||||
|
"Found service spec",
|
||||||
|
"name",
|
||||||
|
spec.Name(),
|
||||||
|
"service",
|
||||||
|
service,
|
||||||
|
"resource",
|
||||||
|
resource,
|
||||||
|
)
|
||||||
|
|
||||||
|
for _, part := range []string{"alpha", "beta"} {
|
||||||
|
oasFile := path.Join(generatorDir, "oas", fmt.Sprintf("%s%s.json", service, part))
|
||||||
|
if _, err = os.Stat(oasFile); !os.IsNotExist(err) {
|
||||||
|
slog.Info("found matching oas", "service", service, "version", part)
|
||||||
|
scName := fmt.Sprintf("%s%s", service, part)
|
||||||
|
scName = strings.ReplaceAll(scName, "-", "")
|
||||||
|
err = os.MkdirAll(path.Join(rootDir, "generated", "internal", "services", scName, resource), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// slog.Info("Generating openapi spec json")
|
||||||
|
specFile := path.Join(rootDir, "generated", "specs", fmt.Sprintf("%s_%s_spec.json", scName, resource))
|
||||||
|
|
||||||
|
var stdOut, stdErr bytes.Buffer
|
||||||
|
|
||||||
|
// noqa:gosec
|
||||||
|
cmd := exec.Command(
|
||||||
|
"tfplugingen-openapi",
|
||||||
|
"generate",
|
||||||
|
"--config",
|
||||||
|
path.Join(rootDir, "service_specs", fileName),
|
||||||
|
"--output",
|
||||||
|
specFile,
|
||||||
|
oasFile,
|
||||||
|
)
|
||||||
|
cmd.Stdout = &stdOut
|
||||||
|
cmd.Stderr = &stdErr
|
||||||
|
|
||||||
|
if err = cmd.Start(); err != nil {
|
||||||
|
slog.Error("tfplugingen-openapi generate", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cmd.Wait(); err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
|
slog.Error("tfplugingen-openapi generate", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("tfplugingen-openapi generate", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// slog.Info("Creating terraform service resource files folder")
|
||||||
|
tgtFolder := path.Join(rootDir, "generated", "internal", "services", scName, resource, "resources_gen")
|
||||||
|
err = os.MkdirAll(tgtFolder, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// slog.Info("Generating terraform service resource files")
|
||||||
|
|
||||||
|
// noqa:gosec
|
||||||
|
cmd2 := exec.Command(
|
||||||
|
"tfplugingen-framework",
|
||||||
|
"generate",
|
||||||
|
"resources",
|
||||||
|
"--input",
|
||||||
|
specFile,
|
||||||
|
"--output",
|
||||||
|
tgtFolder,
|
||||||
|
"--package",
|
||||||
|
scName,
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd2.Stdout = &stdOut
|
||||||
|
cmd2.Stderr = &stdErr
|
||||||
|
if err = cmd2.Start(); err != nil {
|
||||||
|
slog.Error("tfplugingen-framework generate resources", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cmd2.Wait(); err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
|
slog.Error("tfplugingen-framework generate resources", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("tfplugingen-framework generate resources", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// slog.Info("Creating terraform service datasource files folder")
|
||||||
|
tgtFolder = path.Join(rootDir, "generated", "internal", "services", scName, resource, "datasources_gen")
|
||||||
|
err = os.MkdirAll(tgtFolder, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// slog.Info("Generating terraform service resource files")
|
||||||
|
|
||||||
|
// noqa:gosec
|
||||||
|
cmd3 := exec.Command(
|
||||||
|
"tfplugingen-framework",
|
||||||
|
"generate",
|
||||||
|
"data-sources",
|
||||||
|
"--input",
|
||||||
|
specFile,
|
||||||
|
"--output",
|
||||||
|
tgtFolder,
|
||||||
|
"--package",
|
||||||
|
scName,
|
||||||
|
)
|
||||||
|
var stdOut3, stdErr3 bytes.Buffer
|
||||||
|
cmd3.Stdout = &stdOut3
|
||||||
|
cmd3.Stderr = &stdErr3
|
||||||
|
|
||||||
|
if err = cmd3.Start(); err != nil {
|
||||||
|
slog.Error("tfplugingen-framework generate data-sources", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cmd3.Wait(); err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
|
slog.Error("tfplugingen-framework generate data-sources", "code", exitErr.ExitCode(), "error", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return fmt.Errorf("%s", stdErr.String())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("tfplugingen-framework generate data-sources", "err", err, "stdout", stdOut.String(), "stderr", stdErr.String())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkCommands(commands []string) error {
|
||||||
|
for _, commandName := range commands {
|
||||||
|
if !commandExists(commandName) {
|
||||||
|
return fmt.Errorf("missing command %s", commandName)
|
||||||
|
}
|
||||||
|
slog.Info("found", "command", commandName)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func commandExists(cmd string) bool {
|
||||||
|
_, err := exec.LookPath(cmd)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteFiles(fNames ...string) error {
|
||||||
|
for _, fName := range fNames {
|
||||||
|
if _, err := os.Stat(fName); !os.IsNotExist(err) {
|
||||||
|
err = os.Remove(fName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFile(src, dst string) (int64, error) {
|
||||||
|
sourceFileStat, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sourceFileStat.Mode().IsRegular() {
|
||||||
|
return 0, fmt.Errorf("%s is not a regular file", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
destination, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer destination.Close()
|
||||||
|
nBytes, err := io.Copy(destination, source)
|
||||||
|
return nBytes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOnlyLatest(m map[string]version) (map[string]version, error) {
|
||||||
|
tmpMap := make(map[string]version)
|
||||||
|
for k, v := range m {
|
||||||
|
item, ok := tmpMap[k]
|
||||||
|
if !ok {
|
||||||
|
tmpMap[k] = v
|
||||||
|
} else {
|
||||||
|
if item.major == v.major && item.minor < v.minor {
|
||||||
|
tmpMap[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmpMap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVersions(dir string) (map[string]version, error) {
|
||||||
|
res := make(map[string]version)
|
||||||
|
children, err := os.ReadDir(path.Join(dir, "services"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range children {
|
||||||
|
if entry.IsDir() {
|
||||||
|
versions, err := os.ReadDir(path.Join(dir, "services", entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m, err2 := extractVersions(entry.Name(), versions)
|
||||||
|
if err2 != nil {
|
||||||
|
return m, err2
|
||||||
|
}
|
||||||
|
for k, v := range m {
|
||||||
|
res[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractVersions(service string, versionDirs []os.DirEntry) (map[string]version, error) {
|
||||||
|
res := make(map[string]version)
|
||||||
|
for _, vDir := range versionDirs {
|
||||||
|
if vDir.IsDir() {
|
||||||
|
r := regexp.MustCompile(`v([0-9]+)([a-z]+)([0-9]*)`)
|
||||||
|
matches := r.FindAllStringSubmatch(vDir.Name(), -1)
|
||||||
|
if matches == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
svc, ver, err := handleVersion(service, matches[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if svc != nil && ver != nil {
|
||||||
|
res[*svc] = *ver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleVersion(service string, match []string) (*string, *version, error) {
|
||||||
|
if match == nil {
|
||||||
|
fmt.Println("no matches")
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
verString := match[2]
|
||||||
|
if verString != "alpha" && verString != "beta" {
|
||||||
|
return nil, nil, errors.New("unsupported version")
|
||||||
|
}
|
||||||
|
majVer, err := strconv.Atoi(match[1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if match[3] == "" {
|
||||||
|
match[3] = "0"
|
||||||
|
}
|
||||||
|
minVer, err := strconv.Atoi(match[3])
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
resStr := fmt.Sprintf("%s%s", service, verString)
|
||||||
|
return &resStr, &version{verString: verString, major: majVer, minor: minVer}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createRepoDir(root, repoUrl, repoName string) (string, error) {
|
||||||
|
oasTmpDir, err := os.MkdirTemp(root, "oas-tmp")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
targetDir := path.Join(oasTmpDir, repoName)
|
||||||
|
_, err = git.Clone(
|
||||||
|
clone.Repository(repoUrl),
|
||||||
|
clone.Directory(targetDir),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return targetDir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createGeneratorDir(root, repoUrl, repoName string) (string, error) {
|
||||||
|
targetDir := path.Join(root, repoName)
|
||||||
|
_, err := git.Clone(
|
||||||
|
clone.Repository(repoUrl),
|
||||||
|
clone.Directory(targetDir),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return targetDir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,6 @@ package build
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -75,24 +74,14 @@ func Copy(srcFile, dstFile string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func(out *os.File) {
|
defer out.Close()
|
||||||
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 func(in *os.File) {
|
defer in.Close()
|
||||||
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 {
|
||||||
51
cmd/cmd/build/templates/data_source_scaffold.gotmpl
Normal file
51
cmd/cmd/build/templates/data_source_scaffold.gotmpl
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
package {{.PackageName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg/{{.PackageName}}"
|
||||||
|
|
||||||
|
{{.PackageName}}Gen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/{{.PackageName}}/{{.NameSnake}}/datasources_gen"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ datasource.DataSource = (*{{.NameCamel}}DataSource)(nil)
|
||||||
|
|
||||||
|
func New{{.NamePascal}}DataSource() datasource.DataSource {
|
||||||
|
return &{{.NameCamel}}DataSource{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type {{.NameCamel}}DataSource struct{
|
||||||
|
client *{{.PackageName}}.APIClient
|
||||||
|
providerData core.ProviderData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *{{.NameCamel}}DataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||||
|
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *{{.NameCamel}}DataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
resp.Schema = {{.PackageName}}Gen.{{.NamePascal}}DataSourceSchema(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *{{.NameCamel}}DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||||
|
var data {{.PackageName}}Gen.{{.NameCamel}}Model
|
||||||
|
|
||||||
|
// Read Terraform configuration data into the model
|
||||||
|
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: Read API call logic
|
||||||
|
|
||||||
|
// Example data value setting
|
||||||
|
// data.Id = types.StringValue("example-id")
|
||||||
|
|
||||||
|
// Save data into Terraform state
|
||||||
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
}
|
||||||
208
cmd/cmd/build/templates/resource_scaffold.gotmpl
Normal file
208
cmd/cmd/build/templates/resource_scaffold.gotmpl
Normal file
|
|
@ -0,0 +1,208 @@
|
||||||
|
package {{.PackageName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
|
|
||||||
|
{{.PackageName}}Gen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/{{.PackageName}}/{{.NameSnake}}/resources_gen"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ resource.Resource = &{{.NameCamel}}Resource{}
|
||||||
|
_ resource.ResourceWithConfigure = &{{.NameCamel}}Resource{}
|
||||||
|
_ resource.ResourceWithImportState = &{{.NameCamel}}Resource{}
|
||||||
|
_ resource.ResourceWithModifyPlan = &{{.NameCamel}}Resource{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func New{{.NamePascal}}Resource() resource.Resource {
|
||||||
|
return &{{.NameCamel}}Resource{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type {{.NameCamel}}Resource struct{
|
||||||
|
client *{{.PackageName}}.APIClient
|
||||||
|
providerData core.ProviderData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||||
|
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
resp.Schema = {{.PackageName}}Gen.{{.NamePascal}}ResourceSchema(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure adds the provider configured client to the resource.
|
||||||
|
func (r *{{.NameCamel}}Resource) Configure(
|
||||||
|
ctx context.Context,
|
||||||
|
req resource.ConfigureRequest,
|
||||||
|
resp *resource.ConfigureResponse,
|
||||||
|
) {
|
||||||
|
var ok bool
|
||||||
|
r.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
apiClientConfigOptions := []config.ConfigurationOption{
|
||||||
|
config.WithCustomAuth(r.providerData.RoundTripper),
|
||||||
|
utils.UserAgentConfigOption(r.providerData.Version),
|
||||||
|
}
|
||||||
|
if r.providerData.PostgresFlexCustomEndpoint != "" {
|
||||||
|
apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(r.providerData.PostgresFlexCustomEndpoint))
|
||||||
|
} else {
|
||||||
|
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(r.providerData.GetRegion()))
|
||||||
|
}
|
||||||
|
apiClient, err := {{.PackageName}}.NewAPIClient(apiClientConfigOptions...)
|
||||||
|
if err != nil {
|
||||||
|
resp.Diagnostics.AddError( "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.client = apiClient
|
||||||
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} client configured")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||||
|
var data {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
|
||||||
|
// Read Terraform plan data into the model
|
||||||
|
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Create API call logic
|
||||||
|
|
||||||
|
// Example data value setting
|
||||||
|
data.{{.NameCamel | ucfirst}}Id = types.StringValue("id-from-response")
|
||||||
|
|
||||||
|
// Save data into Terraform state
|
||||||
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
||||||
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} created")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||||
|
var data {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
|
||||||
|
// Read Terraform prior state data into the model
|
||||||
|
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: Read API call logic
|
||||||
|
|
||||||
|
// Save updated data into Terraform state
|
||||||
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
||||||
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} read")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||||
|
var data {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
|
||||||
|
// Read Terraform plan data into the model
|
||||||
|
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: Update API call logic
|
||||||
|
|
||||||
|
// Save updated data into Terraform state
|
||||||
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
||||||
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} updated")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *{{.NameCamel}}Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||||
|
var data {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
|
||||||
|
// Read Terraform prior state data into the model
|
||||||
|
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: Delete API call logic
|
||||||
|
|
||||||
|
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} deleted")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifyPlan implements resource.ResourceWithModifyPlan.
|
||||||
|
// Use the modifier to set the effective region in the current plan.
|
||||||
|
func (r *{{.NameCamel}}Resource) ModifyPlan(
|
||||||
|
ctx context.Context,
|
||||||
|
req resource.ModifyPlanRequest,
|
||||||
|
resp *resource.ModifyPlanResponse,
|
||||||
|
) { // nolint:gocritic // function signature required by Terraform
|
||||||
|
var configModel {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
// skip initial empty configuration to avoid follow-up errors
|
||||||
|
if req.Config.Raw.IsNull() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var planModel {{.PackageName}}Gen.{{.NamePascal}}Model
|
||||||
|
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImportState imports a resource into the Terraform state on success.
|
||||||
|
// The expected format of the resource import identifier is: project_id,zone_id,record_set_id
|
||||||
|
func (r *{{.NameCamel}}Resource) ImportState(
|
||||||
|
ctx context.Context,
|
||||||
|
req resource.ImportStateRequest,
|
||||||
|
resp *resource.ImportStateResponse,
|
||||||
|
) {
|
||||||
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
|
// Todo: Import logic
|
||||||
|
if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" {
|
||||||
|
core.LogAndAddError(
|
||||||
|
ctx, &resp.Diagnostics,
|
||||||
|
"Error importing database",
|
||||||
|
fmt.Sprintf(
|
||||||
|
"Expected import identifier with format [project_id],[region],..., got %q",
|
||||||
|
req.ID,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
|
||||||
|
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
|
||||||
|
// ... more ...
|
||||||
|
|
||||||
|
core.LogAndAddWarning(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"{{.PackageName | ucfirst}} database imported with empty password",
|
||||||
|
"The database password is not imported as it is only available upon creation of a new database. The password field will be empty.",
|
||||||
|
)
|
||||||
|
tflog.Info(ctx, "{{.PackageName | ucfirst}} {{.NameCamel}} state imported")
|
||||||
|
}
|
||||||
17
cmd/cmd/buildCmd.go
Normal file
17
cmd/cmd/buildCmd.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/build"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewBuildCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "build",
|
||||||
|
Short: "Build the necessary boilerplate",
|
||||||
|
Long: `...`,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return build.Build()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,27 +35,36 @@ 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()
|
||||||
|
|
@ -85,7 +94,7 @@ func (p *Provider) CreateArchitectureFiles() error {
|
||||||
archFileName := path.Join(downloadPathPrefix, target, arch)
|
archFileName := path.Join(downloadPathPrefix, target, arch)
|
||||||
|
|
||||||
a := Architecture{
|
a := Architecture{
|
||||||
Protocols: []string{"5.1", "6.0"},
|
Protocols: []string{"5.1"},
|
||||||
OS: target,
|
OS: target,
|
||||||
Arch: arch,
|
Arch: arch,
|
||||||
FileName: sum.Path,
|
FileName: sum.Path,
|
||||||
|
|
@ -107,6 +116,33 @@ 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)
|
||||||
|
|
||||||
|
|
@ -124,12 +160,8 @@ 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(
|
err = os.WriteFile(filePath, jsonString, os.ModePerm)
|
||||||
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", "6.1"},
|
Protocols: []string{"5.1"},
|
||||||
Platforms: nil,
|
Platforms: nil,
|
||||||
}
|
}
|
||||||
for _, sum := range shasums {
|
for _, sum := range shasums {
|
||||||
|
|
@ -161,12 +161,10 @@ func (p *Provider) createVersionsFile() error {
|
||||||
target := fileNameSplit[2]
|
target := fileNameSplit[2]
|
||||||
arch := fileNameSplit[3]
|
arch := fileNameSplit[3]
|
||||||
|
|
||||||
version.Platforms = append(
|
version.Platforms = append(version.Platforms, Platform{
|
||||||
version.Platforms, Platform{
|
OS: target,
|
||||||
OS: target,
|
Arch: arch,
|
||||||
Arch: arch,
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := Data{}
|
data := Data{}
|
||||||
|
|
@ -208,19 +206,16 @@ 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/"}`),
|
||||||
0o644,
|
0644,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -229,10 +224,9 @@ func (p *Provider) CreateWellKnown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDir(pathValue string) error {
|
func CreateDir(path string) error {
|
||||||
log.Printf("* Creating %s directory", pathValue)
|
log.Printf("* Creating %s directory", path)
|
||||||
//nolint:gosec // this file is not sensitive, so we can use ModePerm
|
err := os.MkdirAll(path, os.ModePerm)
|
||||||
err := os.MkdirAll(pathValue, os.ModePerm)
|
|
||||||
if errors.Is(err, fs.ErrExist) {
|
if errors.Is(err, fs.ErrExist) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -275,23 +269,13 @@ func CopyFile(src, dst string) (int64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer func(source *os.File) {
|
defer source.Close()
|
||||||
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 func(destination *os.File) {
|
defer destination.Close()
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
@ -22,25 +22,16 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
//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)
|
||||||
}
|
}
|
||||||
|
|
@ -91,13 +82,7 @@ func (d *Data) LoadFromUrl(uri string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func(name string) {
|
defer os.Remove(file.Name()) // Clean up
|
||||||
//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(),
|
||||||
|
|
@ -134,30 +119,20 @@ 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(urlValue, filepath string) error {
|
func DownloadFile(url string, 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 func(out *os.File) {
|
defer out.Close()
|
||||||
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 func(Body io.ReadCloser) {
|
defer resp.Body.Close()
|
||||||
_ = 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,8 +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/generator/cmd/publish"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -29,32 +28,20 @@ var publishCmd = &cobra.Command{
|
||||||
Use: "publish",
|
Use: "publish",
|
||||||
Short: "Publish terraform provider",
|
Short: "Publish terraform provider",
|
||||||
Long: `...`,
|
Long: `...`,
|
||||||
RunE: func(_ *cobra.Command, _ []string) error {
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
return publish()
|
return publish()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { //nolint:gochecknoinits //this is the standard way to set up cobra commands
|
func init() { // nolint: gochecknoinits
|
||||||
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(
|
publishCmd.Flags().StringVarP(&gpgFingerprint, "gpgFingerprint", "f", "", "GPG Fingerprint for the Terraform registry.")
|
||||||
&gpgFingerprint,
|
publishCmd.Flags().StringVarP(&gpgPubKeyFile, "gpgPubKeyFile", "k", "", "GPG PubKey file name for the Terraform registry.")
|
||||||
"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 {
|
||||||
|
|
@ -117,7 +104,6 @@ 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)
|
||||||
27
cmd/main.go
Normal file
27
cmd/main.go
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
rootCmd := cmd.NewRootCmd()
|
||||||
|
//rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
|
||||||
|
//rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
|
||||||
|
//rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
|
||||||
|
|
||||||
|
rootCmd.SetOut(os.Stdout)
|
||||||
|
|
||||||
|
rootCmd.AddCommand(
|
||||||
|
cmd.NewBuildCmd(),
|
||||||
|
cmd.NewPublishCmd(),
|
||||||
|
)
|
||||||
|
|
||||||
|
err := rootCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_database Data Source - stackitprivatepreview"
|
page_title: "stackitprivatepreview_postgresflexalpha_database Data Source - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
Postgres Flex database resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_database (Data Source)
|
# stackitprivatepreview_postgresflexalpha_database (Data Source)
|
||||||
|
|
||||||
|
Postgres Flex database resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -25,14 +25,16 @@ data "stackitprivatepreview_postgresflexalpha_database" "example" {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `database_id` (Number) The ID of the database.
|
- `instance_id` (String) ID of the Postgres Flex instance.
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `project_id` (String) The STACKIT project ID.
|
|
||||||
- `region` (String) The region which should be addressed
|
### Optional
|
||||||
|
|
||||||
|
- `database_id` (Number) Database ID.
|
||||||
|
- `name` (String) Database name.
|
||||||
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`,`database_id`\".",
|
- `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) Username of the database owner.
|
||||||
- `owner` (String) The owner of the database.
|
|
||||||
- `tf_original_api_id` (Number) The id of the database.
|
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,7 @@ description: |-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 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 generated by tfplugindocs -->
|
||||||
## Schema
|
## Schema
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ Read-Only:
|
||||||
|
|
||||||
- `cpu` (Number) The cpu count of the instance.
|
- `cpu` (Number) The cpu count of the instance.
|
||||||
- `description` (String) The flavor description.
|
- `description` (String) The flavor description.
|
||||||
|
- `id` (String) The id of the instance flavor.
|
||||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
||||||
- `memory` (Number) The memory of the instance in Gibibyte.
|
- `memory` (Number) The memory of the instance in Gibibyte.
|
||||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
- `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
|
- `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))
|
- `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>
|
<a id="nestedatt--flavors--storage_classes"></a>
|
||||||
### Nested Schema for `flavors.storage_classes`
|
### Nested Schema for `flavors.storage_classes`
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
||||||
|
|
||||||
### Read-Only
|
### 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.
|
||||||
- `backup_schedule` (String) The schedule for when the database backup will be created. Currently, ONLY daily schedules are supported (every 24 hours). 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))
|
||||||
- `connection_info` (Attributes) The connection information of the instance (see [below for nested schema](#nestedatt--connection_info))
|
|
||||||
- `encryption` (Attributes) The configuration for instance's volume and backup storage encryption.
|
- `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))
|
⚠️ **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.
|
- `flavor_id` (String) The id of the instance flavor.
|
||||||
|
- `id` (String) The ID of the instance.
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
||||||
- `name` (String) The name of the instance.
|
- `name` (String) The name of the instance.
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
||||||
|
|
@ -44,7 +44,6 @@ data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
||||||
- `retention_days` (Number) How long backups are retained. The value can only be between 32 and 365 days.
|
- `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.
|
- `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))
|
- `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.
|
- `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>
|
<a id="nestedatt--connection_info"></a>
|
||||||
|
|
@ -52,18 +51,10 @@ data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
||||||
|
|
||||||
Read-Only:
|
Read-Only:
|
||||||
|
|
||||||
- `write` (Attributes) The DNS name and port in the instance overview (see [below for nested schema](#nestedatt--connection_info--write))
|
|
||||||
|
|
||||||
<a id="nestedatt--connection_info--write"></a>
|
|
||||||
### Nested Schema for `connection_info.write`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `host` (String) The host of the instance.
|
- `host` (String) The host of the instance.
|
||||||
- `port` (Number) The port of the instance.
|
- `port` (Number) The port of the instance.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
<a id="nestedatt--encryption"></a>
|
||||||
### Nested Schema for `encryption`
|
### Nested Schema for `encryption`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_user Data Source - stackitprivatepreview"
|
page_title: "stackitprivatepreview_postgresflexalpha_user Data Source - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
Postgres Flex user data source schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_user (Data Source)
|
# stackitprivatepreview_postgresflexalpha_user (Data Source)
|
||||||
|
|
||||||
|
Postgres Flex user data source schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -25,18 +25,20 @@ data "stackitprivatepreview_postgresflexalpha_user" "example" {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `instance_id` (String) ID of the PostgresFlex instance.
|
||||||
- `project_id` (String) The STACKIT project ID.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `region` (String) The region which should be addressed
|
- `user_id` (String) User ID.
|
||||||
- `user_id` (Number) The ID of the user.
|
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
- `id` (String) Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`,`user_id`\".",
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
- `name` (String) The name of the user.
|
- `connection_string` (String) The connection string for the user to the instance.
|
||||||
- `roles` (List of String) A list of user roles.
|
- `host` (String) The host address for the user to connect to the instance.
|
||||||
|
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
|
||||||
|
- `port` (Number) The port number for the user to connect to the instance.
|
||||||
|
- `roles` (Set of String) The roles assigned to the user.
|
||||||
- `status` (String) The current status of the user.
|
- `status` (String) The current status of the user.
|
||||||
- `tf_original_api_id` (Number) The ID of the user.
|
- `username` (String) The name of the user.
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ description: |-
|
||||||
|
|
||||||
- `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.
|
- `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.
|
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
||||||
- `id` (String) The terraform internal identifier.
|
- `id` (Number) The id of the database.
|
||||||
- `name` (String) The name of the database.
|
- `name` (String) The name of the database.
|
||||||
- `owner` (String) The owner of the database.
|
- `owner` (String) The owner of the database.
|
||||||
- `tf_original_api_id` (Number) The id of the database.
|
|
||||||
|
|
|
||||||
43
docs/data-sources/sqlserverflexalpha_flavor.md
Normal file
43
docs/data-sources/sqlserverflexalpha_flavor.md
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
---
|
||||||
|
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||||
|
page_title: "stackitprivatepreview_sqlserverflexalpha_flavor Data Source - stackitprivatepreview"
|
||||||
|
subcategory: ""
|
||||||
|
description: |-
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# stackitprivatepreview_sqlserverflexalpha_flavor (Data Source)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 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)
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Data Source - stackitprivatepreview"
|
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Data Source - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
SQLServer Flex ALPHA instance resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_instance (Data Source)
|
# stackitprivatepreview_sqlserverflexalpha_instance (Data Source)
|
||||||
|
|
||||||
|
SQLServer Flex ALPHA instance resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -24,48 +24,61 @@ data "stackitprivatepreview_sqlserverflexalpha_instance" "example" {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `instance_id` (String) ID of the SQLServer Flex instance.
|
||||||
- `project_id` (String) The STACKIT project ID.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `region` (String) The region which should be addressed
|
|
||||||
|
### Optional
|
||||||
|
|
||||||
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
|
|
||||||
### Read-Only
|
### 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.
|
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *")
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
- `edition` (String)
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
- `encryption` (Attributes) The encryption block. (see [below for nested schema](#nestedatt--encryption))
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
- `flavor` (Attributes) (see [below for nested schema](#nestedatt--flavor))
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`".
|
||||||
- `name` (String) The name of the instance.
|
- `is_deletable` (Boolean)
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
- `name` (String) Instance name.
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
- `network` (Attributes) The network block. (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
|
- `replicas` (Number)
|
||||||
|
- `retention_days` (Number)
|
||||||
- `status` (String)
|
- `status` (String)
|
||||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
|
||||||
- `tf_original_api_id` (String) The ID of the instance.
|
- `version` (String)
|
||||||
- `version` (String) The sqlserver version used for the instance.
|
|
||||||
|
|
||||||
<a id="nestedatt--encryption"></a>
|
<a id="nestedatt--encryption"></a>
|
||||||
### Nested Schema for `encryption`
|
### Nested Schema for `encryption`
|
||||||
|
|
||||||
Read-Only:
|
Read-Only:
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
- `key_id` (String) STACKIT KMS - Key ID of the encryption key to use.
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
- `key_version` (String) STACKIT KMS - Key version to use in the encryption key.
|
||||||
- `kek_key_version` (String) The key version
|
- `keyring_id` (String) STACKIT KMS - KeyRing ID of the encryption key to use.
|
||||||
- `service_account` (String)
|
- `service_account` (String)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--flavor"></a>
|
||||||
|
### Nested Schema for `flavor`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `cpu` (Number)
|
||||||
|
- `description` (String)
|
||||||
|
- `id` (String)
|
||||||
|
- `node_type` (String)
|
||||||
|
- `ram` (Number)
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
<a id="nestedatt--network"></a>
|
||||||
### Nested Schema for `network`
|
### Nested Schema for `network`
|
||||||
|
|
||||||
Read-Only:
|
Read-Only:
|
||||||
|
|
||||||
- `access_scope` (String) The network access scope of the instance
|
- `access_scope` (String) The access scope of the instance. (e.g. SNA)
|
||||||
|
- `acl` (List of String) The Access Control List (ACL) for the SQLServer Flex 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.
|
- `instance_address` (String) The returned instance IP address of the SQLServer Flex instance.
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
- `router_address` (String) The returned router IP address of the SQLServer Flex instance.
|
||||||
- `instance_address` (String)
|
|
||||||
- `router_address` (String)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--storage"></a>
|
<a id="nestedatt--storage"></a>
|
||||||
|
|
@ -73,5 +86,5 @@ Read-Only:
|
||||||
|
|
||||||
Read-Only:
|
Read-Only:
|
||||||
|
|
||||||
- `class` (String) The storage class for the storage.
|
- `class` (String)
|
||||||
- `size` (Number) The storage size in Gigabytes.
|
- `size` (Number)
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_user Data Source - stackitprivatepreview"
|
page_title: "stackitprivatepreview_sqlserverflexalpha_user Data Source - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
SQLServer Flex user data source schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_user (Data Source)
|
# stackitprivatepreview_sqlserverflexalpha_user (Data Source)
|
||||||
|
|
||||||
|
SQLServer Flex user data source schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -25,38 +25,20 @@ data "stackitprivatepreview_sqlserverflexalpha_user" "example" {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `instance_id` (String) ID of the SQLServer Flex instance.
|
||||||
- `project_id` (String) The STACKIT project ID.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `region` (String) The region which should be addressed
|
- `user_id` (Number) User ID.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
- `page` (Number) Number of the page of items list to be returned.
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
- `size` (Number) Number of items to be returned on each page.
|
|
||||||
- `sort` (String) Sorting of the users to be returned on each page.
|
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
- `pagination` (Attributes) (see [below for nested schema](#nestedatt--pagination))
|
- `default_database` (String)
|
||||||
- `users` (Attributes List) List of all users inside an instance (see [below for nested schema](#nestedatt--users))
|
- `host` (String)
|
||||||
|
- `id` (String) Terraform's internal data source. ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
|
||||||
<a id="nestedatt--pagination"></a>
|
- `port` (Number)
|
||||||
### Nested Schema for `pagination`
|
- `roles` (Set of String) Database access levels for the user.
|
||||||
|
- `status` (String)
|
||||||
Read-Only:
|
- `username` (String) Username of the SQLServer Flex instance.
|
||||||
|
|
||||||
- `page` (Number)
|
|
||||||
- `size` (Number)
|
|
||||||
- `sort` (String)
|
|
||||||
- `total_pages` (Number)
|
|
||||||
- `total_rows` (Number)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--users"></a>
|
|
||||||
### Nested Schema for `users`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `status` (String) The current status of the user.
|
|
||||||
- `tf_original_api_id` (Number) The ID of the user.
|
|
||||||
- `username` (String) The name of the user.
|
|
||||||
|
|
|
||||||
35
docs/data-sources/sqlserverflexalpha_version.md
Normal file
35
docs/data-sources/sqlserverflexalpha_version.md
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
---
|
||||||
|
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||||
|
page_title: "stackitprivatepreview_sqlserverflexalpha_version Data Source - stackitprivatepreview"
|
||||||
|
subcategory: ""
|
||||||
|
description: |-
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# stackitprivatepreview_sqlserverflexalpha_version (Data Source)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- schema generated by tfplugindocs -->
|
||||||
|
## Schema
|
||||||
|
|
||||||
|
### Required
|
||||||
|
|
||||||
|
- `project_id` (String) The STACKIT project ID.
|
||||||
|
- `region` (String) The region which should be addressed
|
||||||
|
|
||||||
|
### Read-Only
|
||||||
|
|
||||||
|
- `versions` (Attributes List) A list containing available sqlserver versions. (see [below for nested schema](#nestedatt--versions))
|
||||||
|
|
||||||
|
<a id="nestedatt--versions"></a>
|
||||||
|
### Nested Schema for `versions`
|
||||||
|
|
||||||
|
Read-Only:
|
||||||
|
|
||||||
|
- `beta` (Boolean) Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.
|
||||||
|
- `deprecated` (String) Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.
|
||||||
|
- `recommend` (Boolean) Flag if the version is recommend by the STACKIT Team.
|
||||||
|
- `version` (String) The sqlserver version used for the 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,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,54 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_user Data Source - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_user (Data Source)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 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
|
|
||||||
|
|
||||||
### 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 users to be returned on each page.
|
|
||||||
|
|
||||||
### Read-Only
|
|
||||||
|
|
||||||
- `pagination` (Attributes) (see [below for nested schema](#nestedatt--pagination))
|
|
||||||
- `users` (Attributes List) List of all users inside an instance (see [below for nested schema](#nestedatt--users))
|
|
||||||
|
|
||||||
<a id="nestedatt--pagination"></a>
|
|
||||||
### Nested Schema for `pagination`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `page` (Number)
|
|
||||||
- `size` (Number)
|
|
||||||
- `sort` (String)
|
|
||||||
- `total_pages` (Number)
|
|
||||||
- `total_rows` (Number)
|
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--users"></a>
|
|
||||||
### Nested Schema for `users`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `status` (String) The current status of the user.
|
|
||||||
- `tf_original_api_id` (Number) The ID of the user.
|
|
||||||
- `username` (String) The name of the user.
|
|
||||||
|
|
@ -16,13 +16,14 @@ provider "stackitprivatepreview" {
|
||||||
default_region = "eu01"
|
default_region = "eu01"
|
||||||
}
|
}
|
||||||
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
service_account_key_path = "service_account.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
|
|
||||||
|
# Token flow (scheduled for deprecation and will be removed on December 17, 2025)
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
service_account_token = var.service_account_token
|
||||||
|
}
|
||||||
|
|
||||||
# Key flow
|
# Key flow
|
||||||
provider "stackitprivatepreview" {
|
provider "stackitprivatepreview" {
|
||||||
default_region = "eu01"
|
default_region = "eu01"
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_database Resource - stackitprivatepreview"
|
page_title: "stackitprivatepreview_postgresflexalpha_database Resource - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
Postgres Flex database resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_database (Resource)
|
# stackitprivatepreview_postgresflexalpha_database (Resource)
|
||||||
|
|
||||||
|
Postgres Flex database resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -25,16 +25,6 @@ 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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
<!-- schema generated by tfplugindocs -->
|
||||||
|
|
@ -42,16 +32,16 @@ import {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `name` (String) The name of the database.
|
- `instance_id` (String) ID of the Postgres Flex instance.
|
||||||
|
- `name` (String) Database name.
|
||||||
|
- `owner` (String) Username of the database owner.
|
||||||
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
- `database_id` (Number) The ID of the database.
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
- `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
|
### Read-Only
|
||||||
|
|
||||||
- `id` (Number) The id of the database.
|
- `database_id` (Number) Database ID.
|
||||||
|
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`,`database_id`".
|
||||||
|
|
|
||||||
|
|
@ -13,29 +13,21 @@ description: |-
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
```terraform
|
```terraform
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "example-instance" {
|
resource "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
||||||
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"]
|
||||||
backup_schedule = "0 0 * * *"
|
backup_schedule = "00 00 * * *"
|
||||||
retention_days = 30
|
flavor = {
|
||||||
flavor_id = "flavor.id"
|
cpu = 2
|
||||||
replicas = 1
|
ram = 4
|
||||||
|
}
|
||||||
|
replicas = 3
|
||||||
storage = {
|
storage = {
|
||||||
performance_class = "premium-perf2-stackit"
|
class = "class"
|
||||||
size = 10
|
size = 5
|
||||||
}
|
}
|
||||||
encryption = {
|
version = 14
|
||||||
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
|
# Only use the import statement, if you want to import an existing postgresflex instance
|
||||||
|
|
@ -43,15 +35,6 @@ import {
|
||||||
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id}"
|
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 generated by tfplugindocs -->
|
||||||
|
|
@ -59,7 +42,7 @@ import {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `backup_schedule` (String) The schedule for when the database backup will be created. Currently, ONLY daily schedules are supported (every 24 hours). The schedule is written as a cron schedule.
|
- `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.
|
- `flavor_id` (String) The id of the instance flavor.
|
||||||
- `name` (String) The name of the instance.
|
- `name` (String) The name of the instance.
|
||||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
||||||
|
|
@ -72,15 +55,14 @@ import {
|
||||||
|
|
||||||
- `encryption` (Attributes) The configuration for instance's volume and backup storage encryption.
|
- `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))
|
⚠️ **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.
|
- `instance_id` (String) The ID of the instance.
|
||||||
- `project_id` (String) The STACKIT project ID.
|
- `project_id` (String) The STACKIT project ID.
|
||||||
- `region` (String) The region which should be addressed
|
- `region` (String) The region which should be addressed
|
||||||
|
|
||||||
### Read-Only
|
### 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))
|
||||||
- `connection_info` (Attributes) The connection information of the instance (see [below for nested schema](#nestedatt--connection_info))
|
|
||||||
- `id` (String) The ID of the instance.
|
- `id` (String) The ID of the instance.
|
||||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
||||||
- `status` (String) The current status of the instance.
|
- `status` (String) The current status of the instance.
|
||||||
|
|
@ -95,9 +77,6 @@ Required:
|
||||||
Optional:
|
Optional:
|
||||||
|
|
||||||
- `access_scope` (String) The access scope of the instance. It defines if the instance is public or airgapped.
|
- `access_scope` (String) The access scope of the instance. It defines if the instance is public or airgapped.
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `instance_address` (String)
|
- `instance_address` (String)
|
||||||
- `router_address` (String)
|
- `router_address` (String)
|
||||||
|
|
||||||
|
|
@ -127,12 +106,5 @@ Required:
|
||||||
|
|
||||||
Read-Only:
|
Read-Only:
|
||||||
|
|
||||||
- `write` (Attributes) The DNS name and port in the instance overview (see [below for nested schema](#nestedatt--connection_info--write))
|
|
||||||
|
|
||||||
<a id="nestedatt--connection_info--write"></a>
|
|
||||||
### Nested Schema for `connection_info.write`
|
|
||||||
|
|
||||||
Read-Only:
|
|
||||||
|
|
||||||
- `host` (String) The host of the instance.
|
- `host` (String) The host of the instance.
|
||||||
- `port` (Number) The port of the instance.
|
- `port` (Number) The port of the instance.
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_postgresflexalpha_user Resource - stackitprivatepreview"
|
page_title: "stackitprivatepreview_postgresflexalpha_user Resource - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
Postgres Flex user resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_postgresflexalpha_user (Resource)
|
# stackitprivatepreview_postgresflexalpha_user (Resource)
|
||||||
|
|
||||||
|
Postgres Flex user resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ description: |-
|
||||||
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"
|
||||||
name = "username"
|
username = "username"
|
||||||
roles = ["role"]
|
roles = ["role"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,16 +25,6 @@ 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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
<!-- schema generated by tfplugindocs -->
|
||||||
|
|
@ -42,18 +32,21 @@ import {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `name` (String) The name of the user.
|
- `instance_id` (String) ID of the PostgresFlex instance.
|
||||||
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
|
- `roles` (Set of String) Database access levels for the user. Possible values are: `login`, `createdb`, `createrole`.
|
||||||
|
- `username` (String) The name of the user.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
- `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
|
### Read-Only
|
||||||
|
|
||||||
- `id` (Number) The ID of the user.
|
- `connection_string` (String) The connection string for the user to the instance.
|
||||||
- `password` (String) The password for the user.
|
- `host` (String) The host of the Postgres Flex instance.
|
||||||
|
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
|
||||||
|
- `password` (String, Sensitive) The password for the user. This is only set upon creation.
|
||||||
|
- `port` (Number) The port of the Postgres Flex instance.
|
||||||
- `status` (String) The current status of the user.
|
- `status` (String) The current status of the user.
|
||||||
|
- `user_id` (Number) User ID.
|
||||||
|
|
|
||||||
|
|
@ -10,34 +10,7 @@ description: |-
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
```terraform
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- schema generated by tfplugindocs -->
|
<!-- schema generated by tfplugindocs -->
|
||||||
## Schema
|
## Schema
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Resource - stackitprivatepreview"
|
page_title: "stackitprivatepreview_sqlserverflexalpha_instance Resource - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
SQLServer Flex ALPHA instance resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_instance (Resource)
|
# stackitprivatepreview_sqlserverflexalpha_instance (Resource)
|
||||||
|
|
||||||
|
SQLServer Flex ALPHA instance resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -41,55 +41,41 @@ import {
|
||||||
|
|
||||||
### Required
|
### 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)
|
||||||
- `flavor_id` (String) The id of the instance flavor.
|
- `name` (String) Instance name.
|
||||||
- `name` (String) The name of the instance.
|
- `network` (Attributes) The network block. (see [below for nested schema](#nestedatt--network))
|
||||||
- `network` (Attributes) the network configuration of the instance. (see [below for nested schema](#nestedatt--network))
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `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
|
### Optional
|
||||||
|
|
||||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
- `backup_schedule` (String) The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *")
|
||||||
- `instance_id` (String) The ID of the instance.
|
- `encryption` (Attributes) The encryption block. (see [below for nested schema](#nestedatt--encryption))
|
||||||
- `project_id` (String) The STACKIT project ID.
|
- `is_deletable` (Boolean)
|
||||||
- `region` (String) The region which should be addressed
|
- `region` (String) The resource region. If not defined, the provider region is used.
|
||||||
|
- `retention_days` (Number)
|
||||||
|
- `status` (String)
|
||||||
|
- `storage` (Attributes) (see [below for nested schema](#nestedatt--storage))
|
||||||
|
- `version` (String)
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
- `edition` (String) Edition of the MSSQL server instance
|
- `edition` (String)
|
||||||
- `id` (String) The ID of the instance.
|
- `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.
|
- `instance_id` (String) ID of the SQLServer Flex instance.
|
||||||
- `replicas` (Number) How many replicas the instance should have.
|
- `replicas` (Number)
|
||||||
- `status` (String)
|
|
||||||
|
|
||||||
<a id="nestedatt--network"></a>
|
<a id="nestedatt--network"></a>
|
||||||
### Nested Schema for `network`
|
### Nested Schema for `network`
|
||||||
|
|
||||||
Required:
|
Required:
|
||||||
|
|
||||||
- `acl` (List of String) List of IPV4 cidr.
|
- `access_scope` (String) The access scope of the instance. (SNA | PUBLIC)
|
||||||
|
- `acl` (List of String) The Access Control List (ACL) for the SQLServer Flex instance.
|
||||||
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:
|
Read-Only:
|
||||||
|
|
||||||
- `instance_address` (String)
|
- `instance_address` (String) The returned instance IP address of the SQLServer Flex instance.
|
||||||
- `router_address` (String)
|
- `router_address` (String) The returned router IP address of the SQLServer Flex instance.
|
||||||
|
|
||||||
|
|
||||||
<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>
|
<a id="nestedatt--encryption"></a>
|
||||||
|
|
@ -97,7 +83,16 @@ Required:
|
||||||
|
|
||||||
Required:
|
Required:
|
||||||
|
|
||||||
- `kek_key_id` (String) The key identifier
|
- `key_id` (String) STACKIT KMS - Key ID of the encryption key to use.
|
||||||
- `kek_key_ring_id` (String) The keyring identifier
|
- `key_version` (String) STACKIT KMS - Key version to use in the encryption key.
|
||||||
- `kek_key_version` (String) The key version
|
- `keyring_id` (String) STACKIT KMS - KeyRing ID of the encryption key to use.
|
||||||
- `service_account` (String)
|
- `service_account` (String)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="nestedatt--storage"></a>
|
||||||
|
### Nested Schema for `storage`
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
|
||||||
|
- `class` (String)
|
||||||
|
- `size` (Number)
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
page_title: "stackitprivatepreview_sqlserverflexalpha_user Resource - stackitprivatepreview"
|
page_title: "stackitprivatepreview_sqlserverflexalpha_user Resource - stackitprivatepreview"
|
||||||
subcategory: ""
|
subcategory: ""
|
||||||
description: |-
|
description: |-
|
||||||
|
SQLServer Flex user resource schema. Must have a region specified in the provider configuration.
|
||||||
---
|
---
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexalpha_user (Resource)
|
# stackitprivatepreview_sqlserverflexalpha_user (Resource)
|
||||||
|
|
||||||
|
SQLServer Flex user resource schema. Must have a `region` specified in the provider configuration.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
|
@ -32,22 +32,21 @@ import {
|
||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `roles` (List of String) A list containing the user roles for the instance. A list with the valid user roles can be retrieved using the List Roles endpoint.
|
- `instance_id` (String) ID of the SQLServer Flex instance.
|
||||||
- `username` (String) The name of the user.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
|
- `roles` (Set of String) Database access levels for the user. The values for the default roles are: `##STACKIT_DatabaseManager##`, `##STACKIT_LoginManager##`, `##STACKIT_ProcessManager##`, `##STACKIT_ServerManager##`, `##STACKIT_SQLAgentManager##`, `##STACKIT_SQLAgentUser##`
|
||||||
|
- `username` (String) Username of the SQLServer Flex instance.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
- `default_database` (String) The default database for a user of the instance.
|
- `region` (String)
|
||||||
- `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
|
### Read-Only
|
||||||
|
|
||||||
- `host` (String) The host of the instance in which the user belongs to.
|
- `default_database` (String)
|
||||||
- `id` (Number) The ID of the user.
|
- `host` (String)
|
||||||
- `password` (String) The password for the user.
|
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`,`user_id`".
|
||||||
- `port` (Number) The port of the instance in which the user belongs to.
|
- `password` (String, Sensitive) Password of the user account.
|
||||||
- `status` (String) The current status of the user.
|
- `port` (Number)
|
||||||
- `uri` (String) The connection string for the user to the instance.
|
- `status` (String)
|
||||||
|
- `user_id` (Number) User ID.
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_database Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_database (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
|
|
||||||
|
|
||||||
- `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)
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
---
|
|
||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
|
||||||
page_title: "stackitprivatepreview_sqlserverflexbeta_user Resource - stackitprivatepreview"
|
|
||||||
subcategory: ""
|
|
||||||
description: |-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# stackitprivatepreview_sqlserverflexbeta_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. A list with the valid user roles can be retrieved using the List Roles endpoint.
|
|
||||||
- `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,8 +0,0 @@
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
data "stackitprivatepreview_sqlserverflexbeta_database" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
database_name = "dbname"
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
data "stackitprivatepreview_sqlserverflexbeta_instance" "example" {
|
|
||||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
}
|
|
||||||
|
|
@ -2,13 +2,14 @@ provider "stackitprivatepreview" {
|
||||||
default_region = "eu01"
|
default_region = "eu01"
|
||||||
}
|
}
|
||||||
|
|
||||||
provider "stackitprivatepreview" {
|
|
||||||
default_region = "eu01"
|
|
||||||
service_account_key_path = "service_account.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
|
|
||||||
|
# Token flow (scheduled for deprecation and will be removed on December 17, 2025)
|
||||||
|
provider "stackitprivatepreview" {
|
||||||
|
default_region = "eu01"
|
||||||
|
service_account_token = var.service_account_token
|
||||||
|
}
|
||||||
|
|
||||||
# Key flow
|
# Key flow
|
||||||
provider "stackitprivatepreview" {
|
provider "stackitprivatepreview" {
|
||||||
default_region = "eu01"
|
default_region = "eu01"
|
||||||
|
|
@ -22,3 +23,4 @@ provider "stackitprivatepreview" {
|
||||||
service_account_key_path = var.service_account_key_path
|
service_account_key_path = var.service_account_key_path
|
||||||
private_key_path = var.private_key_path
|
private_key_path = var.private_key_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,3 @@ 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,26 +1,18 @@
|
||||||
resource "stackitprivatepreview_postgresflexalpha_instance" "example-instance" {
|
resource "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
||||||
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"]
|
||||||
backup_schedule = "0 0 * * *"
|
backup_schedule = "00 00 * * *"
|
||||||
retention_days = 30
|
flavor = {
|
||||||
flavor_id = "flavor.id"
|
cpu = 2
|
||||||
replicas = 1
|
ram = 4
|
||||||
|
}
|
||||||
|
replicas = 3
|
||||||
storage = {
|
storage = {
|
||||||
performance_class = "premium-perf2-stackit"
|
class = "class"
|
||||||
size = 10
|
size = 5
|
||||||
}
|
}
|
||||||
encryption = {
|
version = 14
|
||||||
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
|
# Only use the import statement, if you want to import an existing postgresflex instance
|
||||||
|
|
@ -28,12 +20,3 @@ import {
|
||||||
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
to = stackitprivatepreview_postgresflexalpha_instance.import-example
|
||||||
id = "${var.project_id},${var.region},${var.postgres_instance_id}"
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
name = "username"
|
username = "username"
|
||||||
roles = ["role"]
|
roles = ["role"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -10,13 +10,3 @@ 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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
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}"
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
# 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
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}"
|
|
||||||
}
|
|
||||||
|
|
@ -1,346 +0,0 @@
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"go/ast"
|
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Builder struct {
|
|
||||||
rootDir string
|
|
||||||
SkipClone bool
|
|
||||||
SkipCleanup bool
|
|
||||||
PackagesOnly bool
|
|
||||||
Verbose bool
|
|
||||||
Debug bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) Build() error {
|
|
||||||
slog.Info("Starting Builder")
|
|
||||||
if b.PackagesOnly {
|
|
||||||
slog.Info(" >>> only generating pkg_gen <<<")
|
|
||||||
}
|
|
||||||
|
|
||||||
rootErr := b.determineRoot()
|
|
||||||
if rootErr != nil {
|
|
||||||
return rootErr
|
|
||||||
}
|
|
||||||
|
|
||||||
if !b.PackagesOnly {
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info(" ... Checking needed commands available")
|
|
||||||
}
|
|
||||||
chkErr := checkCommands([]string{})
|
|
||||||
if chkErr != nil {
|
|
||||||
return chkErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if !b.SkipCleanup {
|
|
||||||
// slog.Info("Cleaning up old packages directory")
|
|
||||||
// err := os.RemoveAll(path.Join(b.rootDir, "pkg_gen"))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
// if !b.SkipCleanup && !b.PackagesOnly {
|
|
||||||
// slog.Info("Cleaning up old packages directory")
|
|
||||||
// err := os.RemoveAll(path.Join(b.rootDir, "pkg_gen"))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
// slog.Info("Creating generator dir", "dir", fmt.Sprintf("%s/%s", *root, GEN_REPO_NAME))
|
|
||||||
// genDir := path.Join(*root, GEN_REPO_NAME)
|
|
||||||
// if !b.SkipClone {
|
|
||||||
// err = createGeneratorDir(GEN_REPO, genDir, b.SkipClone)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
oasHandlerErr := b.oasHandler(path.Join(b.rootDir, "service_specs"))
|
|
||||||
if oasHandlerErr != nil {
|
|
||||||
return oasHandlerErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// if !b.PackagesOnly {
|
|
||||||
// slog.Info("Generating service boilerplate")
|
|
||||||
// err = generateServiceFiles(*root, path.Join(*root, GEN_REPO_NAME))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// slog.Info("Copying all service files")
|
|
||||||
// err = CopyDirectory(
|
|
||||||
// path.Join(*root, "generated", "internal", "services"),
|
|
||||||
// path.Join(*root, "stackit", "internal", "services"),
|
|
||||||
// )
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// err = createBoilerplate(*root, path.Join(*root, "stackit", "internal", "services"))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
// workaround to remove linter complain :D
|
|
||||||
if b.PackagesOnly && b.Verbose && b.SkipClone && b.SkipCleanup {
|
|
||||||
bpErr := createBoilerplate(b.rootDir, "boilerplate")
|
|
||||||
if bpErr != nil {
|
|
||||||
return bpErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("Done")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type templateData struct {
|
|
||||||
PackageName string
|
|
||||||
PackageNameCamel string
|
|
||||||
PackageNamePascal string
|
|
||||||
NameCamel string
|
|
||||||
NamePascal string
|
|
||||||
NameSnake string
|
|
||||||
Fields []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func createBoilerplate(rootFolder, folder string) error {
|
|
||||||
services, err := os.ReadDir(folder)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, svc := range services {
|
|
||||||
if !svc.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
resources, err := os.ReadDir(path.Join(folder, svc.Name()))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var handleDS bool
|
|
||||||
var handleRes bool
|
|
||||||
var foundDS bool
|
|
||||||
var foundRes bool
|
|
||||||
|
|
||||||
for _, res := range resources {
|
|
||||||
if !res.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
resourceName := res.Name()
|
|
||||||
|
|
||||||
dsFile := path.Join(
|
|
||||||
folder,
|
|
||||||
svc.Name(),
|
|
||||||
res.Name(),
|
|
||||||
"datasources_gen",
|
|
||||||
fmt.Sprintf("%s_data_source_gen.go", res.Name()),
|
|
||||||
)
|
|
||||||
handleDS = FileExists(dsFile)
|
|
||||||
|
|
||||||
resFile := path.Join(
|
|
||||||
folder,
|
|
||||||
svc.Name(),
|
|
||||||
res.Name(),
|
|
||||||
"resources_gen",
|
|
||||||
fmt.Sprintf("%s_resource_gen.go", res.Name()),
|
|
||||||
)
|
|
||||||
handleRes = FileExists(resFile)
|
|
||||||
|
|
||||||
dsGoFile := path.Join(folder, svc.Name(), res.Name(), "datasource.go")
|
|
||||||
foundDS = FileExists(dsGoFile)
|
|
||||||
|
|
||||||
resGoFile := path.Join(folder, svc.Name(), res.Name(), "resource.go")
|
|
||||||
foundRes = FileExists(resGoFile)
|
|
||||||
|
|
||||||
if handleDS && !foundDS {
|
|
||||||
slog.Info(" creating missing datasource.go", "service", svc.Name(), "resource", resourceName)
|
|
||||||
if !ValidateSnakeCase(resourceName) {
|
|
||||||
return errors.New("resource name is invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
fields, tokenErr := getTokens(dsFile)
|
|
||||||
if tokenErr != nil {
|
|
||||||
return fmt.Errorf("error reading tokens: %w", tokenErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
tplName := "data_source_scaffold.gotmpl"
|
|
||||||
err = writeTemplateToFile(
|
|
||||||
tplName,
|
|
||||||
path.Join(rootFolder, "cmd", "cmd", "build", "templates", tplName),
|
|
||||||
dsGoFile,
|
|
||||||
&templateData{
|
|
||||||
PackageName: svc.Name(),
|
|
||||||
PackageNameCamel: ToCamelCase(svc.Name()),
|
|
||||||
PackageNamePascal: ToPascalCase(svc.Name()),
|
|
||||||
NameCamel: ToCamelCase(resourceName),
|
|
||||||
NamePascal: ToPascalCase(resourceName),
|
|
||||||
NameSnake: resourceName,
|
|
||||||
Fields: fields,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if handleRes && !foundRes {
|
|
||||||
slog.Info(" creating missing resource.go", "service", svc.Name(), "resource", resourceName)
|
|
||||||
if !ValidateSnakeCase(resourceName) {
|
|
||||||
return errors.New("resource name is invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
fields, tokenErr := getTokens(resFile)
|
|
||||||
if tokenErr != nil {
|
|
||||||
return fmt.Errorf("error reading tokens: %w", tokenErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
tplName := "resource_scaffold.gotmpl"
|
|
||||||
err = writeTemplateToFile(
|
|
||||||
tplName,
|
|
||||||
path.Join(rootFolder, "cmd", "cmd", "build", "templates", tplName),
|
|
||||||
resGoFile,
|
|
||||||
&templateData{
|
|
||||||
PackageName: svc.Name(),
|
|
||||||
PackageNameCamel: ToCamelCase(svc.Name()),
|
|
||||||
PackageNamePascal: ToPascalCase(svc.Name()),
|
|
||||||
NameCamel: ToCamelCase(resourceName),
|
|
||||||
NamePascal: ToPascalCase(resourceName),
|
|
||||||
NameSnake: resourceName,
|
|
||||||
Fields: fields,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !FileExists(path.Join(folder, svc.Name(), res.Name(), "functions.go")) {
|
|
||||||
slog.Info(" creating missing functions.go", "service", svc.Name(), "resource", resourceName)
|
|
||||||
if !ValidateSnakeCase(resourceName) {
|
|
||||||
return errors.New("resource name is invalid")
|
|
||||||
}
|
|
||||||
fncTplName := "functions_scaffold.gotmpl"
|
|
||||||
err = writeTemplateToFile(
|
|
||||||
fncTplName,
|
|
||||||
path.Join(rootFolder, "cmd", "cmd", "build", "templates", fncTplName),
|
|
||||||
path.Join(folder, svc.Name(), res.Name(), "functions.go"),
|
|
||||||
&templateData{
|
|
||||||
PackageName: svc.Name(),
|
|
||||||
PackageNameCamel: ToCamelCase(svc.Name()),
|
|
||||||
PackageNamePascal: ToPascalCase(svc.Name()),
|
|
||||||
NameCamel: ToCamelCase(resourceName),
|
|
||||||
NamePascal: ToPascalCase(resourceName),
|
|
||||||
NameSnake: resourceName,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleLine(line string) (string, error) {
|
|
||||||
schemaRegex := regexp.MustCompile(`(\s+")(id)(": schema.[a-zA-Z0-9]+Attribute{)`)
|
|
||||||
|
|
||||||
schemaMatches := schemaRegex.FindAllStringSubmatch(line, -1)
|
|
||||||
if schemaMatches != nil {
|
|
||||||
return fmt.Sprintf("%stf_original_api_id%s", schemaMatches[0][1], schemaMatches[0][3]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
modelRegex := regexp.MustCompile(`(\s+Id\s+types.[a-zA-Z0-9]+\s+.tfsdk:")(id)(".)`)
|
|
||||||
modelMatches := modelRegex.FindAllStringSubmatch(line, -1)
|
|
||||||
if modelMatches != nil {
|
|
||||||
return fmt.Sprintf("%stf_original_api_id%s", modelMatches[0][1], modelMatches[0][3]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return line, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) determineRoot() error {
|
|
||||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
|
||||||
out, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lines := strings.Split(string(out), "\n")
|
|
||||||
if lines[0] == "" {
|
|
||||||
return fmt.Errorf("unable to determine root directory from git")
|
|
||||||
}
|
|
||||||
b.rootDir = lines[0]
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info(" ... using root", "dir", b.rootDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// func createGeneratorDir(repoUrl, targetDir string, skipClone bool) error {
|
|
||||||
// if !skipClone {
|
|
||||||
// if FileExists(targetDir) {
|
|
||||||
// remErr := os.RemoveAll(targetDir)
|
|
||||||
// if remErr != nil {
|
|
||||||
// return remErr
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// _, cloneErr := git.Clone(
|
|
||||||
// clone.Repository(repoUrl),
|
|
||||||
// clone.Directory(targetDir),
|
|
||||||
// )
|
|
||||||
// if cloneErr != nil {
|
|
||||||
// return cloneErr
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
func getTokens(fileName string) ([]string, error) {
|
|
||||||
fset := token.NewFileSet()
|
|
||||||
|
|
||||||
var result []string
|
|
||||||
|
|
||||||
node, err := parser.ParseFile(fset, fileName, nil, parser.ParseComments)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ast.Inspect(
|
|
||||||
node, func(n ast.Node) bool {
|
|
||||||
// Suche nach Typ-Deklarationen (structs)
|
|
||||||
ts, ok := n.(*ast.TypeSpec)
|
|
||||||
if ok {
|
|
||||||
if strings.Contains(ts.Name.Name, "Model") {
|
|
||||||
ast.Inspect(
|
|
||||||
ts, func(sn ast.Node) bool {
|
|
||||||
tts, tok := sn.(*ast.Field)
|
|
||||||
if tok {
|
|
||||||
result = append(result, tts.Names[0].String())
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
)
|
|
||||||
|
|
||||||
func FileExists(pathValue string) bool {
|
|
||||||
_, err := os.Stat(pathValue)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func ucfirst(s string) string {
|
|
||||||
if s == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return strings.ToUpper(s[:1]) + s[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeTemplateToFile(tplName, tplFile, outFile string, data *templateData) error {
|
|
||||||
fn := template.FuncMap{
|
|
||||||
"ucfirst": ucfirst,
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.New(tplName).Funcs(fn).ParseFiles(tplFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var f *os.File
|
|
||||||
f, err = os.Create(outFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tmpl.Execute(f, *data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/* saved for later
|
|
||||||
func deleteFiles(fNames ...string) error {
|
|
||||||
for _, fName := range fNames {
|
|
||||||
if _, err := os.Stat(fName); !os.IsNotExist(err) {
|
|
||||||
err = os.Remove(fName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyFile(src, dst string) (int64, error) {
|
|
||||||
sourceFileStat, err := os.Stat(src)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !sourceFileStat.Mode().IsRegular() {
|
|
||||||
return 0, fmt.Errorf("%s is not a regular file", src)
|
|
||||||
}
|
|
||||||
|
|
||||||
source, err := os.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
defer func(source *os.File) {
|
|
||||||
err := source.Close()
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("copyFile", "err", err)
|
|
||||||
}
|
|
||||||
}(source)
|
|
||||||
|
|
||||||
destination, err := os.Create(dst)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
defer func(destination *os.File) {
|
|
||||||
err := destination.Close()
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("copyFile", "err", err)
|
|
||||||
}
|
|
||||||
}(destination)
|
|
||||||
nBytes, err := io.Copy(destination, source)
|
|
||||||
return nBytes, err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func checkCommands(commands []string) error {
|
|
||||||
for _, commandName := range commands {
|
|
||||||
if !commandExists(commandName) {
|
|
||||||
return fmt.Errorf("missing command %s", commandName)
|
|
||||||
}
|
|
||||||
slog.Info(" found", "command", commandName)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func commandExists(cmd string) bool {
|
|
||||||
_, err := exec.LookPath(cmd)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,446 +0,0 @@
|
||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
|
|
||||||
"github.com/ldez/go-git-cmd-wrapper/v2/clone"
|
|
||||||
"github.com/ldez/go-git-cmd-wrapper/v2/git"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
OasRepoName = "stackit-api-specifications"
|
|
||||||
OasRepo = "https://github.com/stackitcloud/stackit-api-specifications.git"
|
|
||||||
|
|
||||||
ResTypeResource = "resources"
|
|
||||||
ResTypeDataSource = "datasources"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Data struct {
|
|
||||||
ServiceName string `yaml:",omitempty" json:",omitempty"`
|
|
||||||
Versions []Version `yaml:"versions" json:"versions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Version struct {
|
|
||||||
Name string `yaml:"name" json:"name"`
|
|
||||||
Path string `yaml:"path" json:"path"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var oasTempDir string
|
|
||||||
|
|
||||||
func (b *Builder) oasHandler(specDir string) error {
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info("creating schema files", "dir", specDir)
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(specDir); os.IsNotExist(err) {
|
|
||||||
return fmt.Errorf("spec files directory does not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
err := b.createRepoDir(b.SkipClone)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
err2 := b.handleServices(specDir)
|
|
||||||
if err2 != nil {
|
|
||||||
return err2
|
|
||||||
}
|
|
||||||
|
|
||||||
if !b.SkipCleanup {
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info("Finally removing temporary files and directories")
|
|
||||||
}
|
|
||||||
err := os.RemoveAll(path.Join(b.rootDir, "generated"))
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("RemoveAll", "dir", path.Join(b.rootDir, "generated"), "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.RemoveAll(oasTempDir)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("RemoveAll", "dir", oasTempDir, "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) handleServices(specDir string) error {
|
|
||||||
services, err := os.ReadDir(specDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, svc := range services {
|
|
||||||
if !svc.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info(" ... found", "service", svc.Name())
|
|
||||||
}
|
|
||||||
var svcVersions Data
|
|
||||||
svcVersions.ServiceName = svc.Name()
|
|
||||||
|
|
||||||
versionsErr := b.getServiceVersions(path.Join(specDir, svc.Name(), "generator_settings.yml"), &svcVersions)
|
|
||||||
if versionsErr != nil {
|
|
||||||
return versionsErr
|
|
||||||
}
|
|
||||||
|
|
||||||
oasSpecErr := b.generateServiceFiles(&svcVersions)
|
|
||||||
if oasSpecErr != nil {
|
|
||||||
return oasSpecErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) getServiceVersions(confFile string, data *Data) error {
|
|
||||||
if _, cfgFileErr := os.Stat(confFile); os.IsNotExist(cfgFileErr) {
|
|
||||||
return fmt.Errorf("config file does not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
fileContent, fileErr := os.ReadFile(confFile)
|
|
||||||
if fileErr != nil {
|
|
||||||
return fileErr
|
|
||||||
}
|
|
||||||
convErr := yaml.Unmarshal(fileContent, &data)
|
|
||||||
if convErr != nil {
|
|
||||||
return convErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) createRepoDir(skipClone bool) error {
|
|
||||||
tmpDirName, err := os.MkdirTemp("", "oasbuild")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
oasTempDir = path.Join(tmpDirName, OasRepoName)
|
|
||||||
slog.Info("Creating oas repo dir", "dir", oasTempDir)
|
|
||||||
if !skipClone {
|
|
||||||
if FileExists(oasTempDir) {
|
|
||||||
slog.Warn("target dir exists - skipping", "targetDir", oasTempDir)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out, cloneErr := git.Clone(
|
|
||||||
clone.Repository(OasRepo),
|
|
||||||
clone.Directory(oasTempDir),
|
|
||||||
)
|
|
||||||
if cloneErr != nil {
|
|
||||||
slog.Error("git clone error", "output", out)
|
|
||||||
return cloneErr
|
|
||||||
}
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info("git clone result", "output", out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) generateServiceFiles(data *Data) error {
|
|
||||||
err := os.MkdirAll(path.Join(b.rootDir, "generated", "specs"), 0o750)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range data.Versions {
|
|
||||||
specFiles, specsErr := os.ReadDir(path.Join(b.rootDir, "service_specs", data.ServiceName, v.Name))
|
|
||||||
if specsErr != nil {
|
|
||||||
return specsErr
|
|
||||||
}
|
|
||||||
for _, specFile := range specFiles {
|
|
||||||
if specFile.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
r := regexp.MustCompile(`^(.*)_config.yml$`)
|
|
||||||
matches := r.FindAllStringSubmatch(specFile.Name(), -1)
|
|
||||||
if matches == nil {
|
|
||||||
slog.Warn(" skipping file (no regex match)", "file", specFile.Name())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
srcSpecFile := path.Join(b.rootDir, "service_specs", data.ServiceName, v.Name, specFile.Name())
|
|
||||||
|
|
||||||
if matches[0][0] != specFile.Name() {
|
|
||||||
return fmt.Errorf("matched filename differs from original filename - this should not happen")
|
|
||||||
}
|
|
||||||
resource := matches[0][1]
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info(
|
|
||||||
" found service spec",
|
|
||||||
"service",
|
|
||||||
data.ServiceName,
|
|
||||||
"resource",
|
|
||||||
resource,
|
|
||||||
"file",
|
|
||||||
specFile.Name(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
oasFile := path.Join(
|
|
||||||
oasTempDir,
|
|
||||||
"services",
|
|
||||||
data.ServiceName,
|
|
||||||
v.Path,
|
|
||||||
fmt.Sprintf("%s.json", data.ServiceName),
|
|
||||||
)
|
|
||||||
if _, oasErr := os.Stat(oasFile); os.IsNotExist(oasErr) {
|
|
||||||
slog.Warn(
|
|
||||||
" could not find matching oas",
|
|
||||||
"svc",
|
|
||||||
data.ServiceName,
|
|
||||||
"version",
|
|
||||||
v.Name,
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine correct target service name
|
|
||||||
scName := fmt.Sprintf("%s%s", data.ServiceName, v.Name)
|
|
||||||
scName = strings.ReplaceAll(scName, "-", "")
|
|
||||||
|
|
||||||
specJSONFile := path.Join(
|
|
||||||
b.rootDir,
|
|
||||||
"generated",
|
|
||||||
"specs",
|
|
||||||
fmt.Sprintf("%s_%s_spec.json", scName, resource),
|
|
||||||
)
|
|
||||||
|
|
||||||
cmdErr := b.runTerraformPluginGenOpenAPI(srcSpecFile, specJSONFile, oasFile)
|
|
||||||
if cmdErr != nil {
|
|
||||||
return cmdErr
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdResGenErr := b.runTerraformPluginGenFramework(ResTypeResource, scName, resource, specJSONFile)
|
|
||||||
if cmdResGenErr != nil {
|
|
||||||
return cmdResGenErr
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdDsGenErr := b.runTerraformPluginGenFramework(ResTypeDataSource, scName, resource, specJSONFile)
|
|
||||||
if cmdDsGenErr != nil {
|
|
||||||
return cmdDsGenErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) runTerraformPluginGenFramework(resType, svcName, resource, specJSONFile string) error {
|
|
||||||
var stdOut, stdErr bytes.Buffer
|
|
||||||
tgtFolder := path.Join(
|
|
||||||
b.rootDir,
|
|
||||||
"stackit",
|
|
||||||
"internal",
|
|
||||||
"services",
|
|
||||||
svcName,
|
|
||||||
resource,
|
|
||||||
fmt.Sprintf("%s_gen", resType),
|
|
||||||
)
|
|
||||||
|
|
||||||
//nolint:gosec // this file is not sensitive, so we can use 0755
|
|
||||||
err := os.MkdirAll(tgtFolder, 0o755)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var subCmd string
|
|
||||||
switch resType {
|
|
||||||
case ResTypeResource:
|
|
||||||
subCmd = "resources"
|
|
||||||
case ResTypeDataSource:
|
|
||||||
subCmd = "data-sources"
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unknown resource type given: %s", resType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// nolint:gosec // #nosec this command is not using any untrusted input, so we can ignore gosec warning
|
|
||||||
cmd := exec.Command(
|
|
||||||
"tfplugingen-framework",
|
|
||||||
"generate",
|
|
||||||
subCmd,
|
|
||||||
"--input",
|
|
||||||
specJSONFile,
|
|
||||||
"--output",
|
|
||||||
tgtFolder,
|
|
||||||
"--package",
|
|
||||||
svcName,
|
|
||||||
)
|
|
||||||
|
|
||||||
cmd.Stdout = &stdOut
|
|
||||||
cmd.Stderr = &stdErr
|
|
||||||
if err = cmd.Start(); err != nil {
|
|
||||||
slog.Error(fmt.Sprintf("tfplugingen-framework generate %s", resType), "error", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = cmd.Wait(); err != nil {
|
|
||||||
var exitErr *exec.ExitError
|
|
||||||
if errors.As(err, &exitErr) {
|
|
||||||
slog.Error(
|
|
||||||
fmt.Sprintf("tfplugingen-framework generate %s", resType),
|
|
||||||
"code",
|
|
||||||
exitErr.ExitCode(),
|
|
||||||
"error",
|
|
||||||
err,
|
|
||||||
"stdout",
|
|
||||||
stdOut.String(),
|
|
||||||
"stderr",
|
|
||||||
stdErr.String(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
slog.Error(
|
|
||||||
fmt.Sprintf("tfplugingen-framework generate %s", resType),
|
|
||||||
"err",
|
|
||||||
err,
|
|
||||||
"stdout",
|
|
||||||
stdOut.String(),
|
|
||||||
"stderr",
|
|
||||||
stdErr.String(),
|
|
||||||
)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if resType == ResTypeDataSource {
|
|
||||||
tfAnoErr := b.handleTfTagForDatasourceFile(
|
|
||||||
path.Join(tgtFolder, fmt.Sprintf("%s_data_source_gen.go", resource)),
|
|
||||||
svcName,
|
|
||||||
resource,
|
|
||||||
)
|
|
||||||
if tfAnoErr != nil {
|
|
||||||
return tfAnoErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) runTerraformPluginGenOpenAPI(srcSpecFile, specJSONFile, oasFile string) error {
|
|
||||||
var stdOut, stdErr bytes.Buffer
|
|
||||||
|
|
||||||
// nolint:gosec // #nosec this command is not using any untrusted input, so we can ignore gosec warning
|
|
||||||
cmd := exec.Command(
|
|
||||||
"tfplugingen-openapi",
|
|
||||||
"generate",
|
|
||||||
"--config",
|
|
||||||
srcSpecFile,
|
|
||||||
"--output",
|
|
||||||
specJSONFile,
|
|
||||||
oasFile,
|
|
||||||
)
|
|
||||||
cmd.Stdout = &stdOut
|
|
||||||
cmd.Stderr = &stdErr
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
slog.Error(
|
|
||||||
"tfplugingen-openapi generate",
|
|
||||||
"error",
|
|
||||||
err,
|
|
||||||
"stdOut",
|
|
||||||
stdOut.String(),
|
|
||||||
"stdErr",
|
|
||||||
stdErr.String(),
|
|
||||||
)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
|
||||||
var exitErr *exec.ExitError
|
|
||||||
if errors.As(err, &exitErr) {
|
|
||||||
slog.Error(
|
|
||||||
"tfplugingen-openapi generate",
|
|
||||||
"code",
|
|
||||||
exitErr.ExitCode(),
|
|
||||||
"error",
|
|
||||||
err,
|
|
||||||
"stdout",
|
|
||||||
stdOut.String(),
|
|
||||||
"stderr",
|
|
||||||
stdErr.String(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("%s", stdErr.String())
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
slog.Error(
|
|
||||||
"tfplugingen-openapi generate",
|
|
||||||
"err",
|
|
||||||
err,
|
|
||||||
"stdout",
|
|
||||||
stdOut.String(),
|
|
||||||
"stderr",
|
|
||||||
stdErr.String(),
|
|
||||||
)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if stdOut.Len() > 0 {
|
|
||||||
slog.Warn(" command output", "stdout", stdOut.String(), "stderr", stdErr.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleTfTagForDatasourceFile replaces existing "id" with "stf_original_api_id"
|
|
||||||
func (b *Builder) handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
|
||||||
if b.Verbose {
|
|
||||||
slog.Info(" handle terraform tag for datasource", "service", service, "resource", resource)
|
|
||||||
}
|
|
||||||
if !FileExists(filePath) {
|
|
||||||
slog.Warn(" could not find file, skipping", "path", filePath)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
f, err := os.Open(filePath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp, err := os.CreateTemp(b.rootDir, "replace-*")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sc := bufio.NewScanner(f)
|
|
||||||
for sc.Scan() {
|
|
||||||
resLine, err := handleLine(sc.Text())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := tmp.WriteString(resLine + "\n"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if scErr := sc.Err(); scErr != nil {
|
|
||||||
return scErr
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tmp.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint:gosec // path traversal is not a concern here
|
|
||||||
if err := os.Rename(tmp.Name(), filePath); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
||||||
package {{.PackageName}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
|
||||||
|
|
||||||
{{.PackageName}}Pkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/{{.PackageName}}"
|
|
||||||
|
|
||||||
{{.PackageName}}Gen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/{{.PackageName}}/{{.NameSnake}}/datasources_gen"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ datasource.DataSource = (*{{.NameCamel}}DataSource)(nil)
|
|
||||||
|
|
||||||
const errorPrefix = "[{{.PackageNamePascal}} - {{.NamePascal}}]"
|
|
||||||
|
|
||||||
func New{{.NamePascal}}DataSource() datasource.DataSource {
|
|
||||||
return &{{.NameCamel}}DataSource{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type dsModel struct {
|
|
||||||
{{.PackageName}}Gen.{{.NamePascal}}Model
|
|
||||||
TfId types.String `tfsdk:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type {{.NameCamel}}DataSource struct{
|
|
||||||
client *{{.PackageName}}Pkg.APIClient
|
|
||||||
providerData core.ProviderData
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *{{.NameCamel}}DataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
|
||||||
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *{{.NameCamel}}DataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
|
||||||
resp.Schema = {{.PackageName}}Gen.{{.NamePascal}}DataSourceSchema(ctx)
|
|
||||||
resp.Schema.Attributes["id"] = schema.StringAttribute{
|
|
||||||
Computed: true,
|
|
||||||
Description: "The terraform internal identifier.",
|
|
||||||
MarkdownDescription: "The terraform internal identifier.",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure adds the provider configured client to the data source.
|
|
||||||
func (d *{{.NameCamel}}DataSource) Configure(
|
|
||||||
ctx context.Context,
|
|
||||||
req datasource.ConfigureRequest,
|
|
||||||
resp *datasource.ConfigureResponse,
|
|||||||