Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94f222fe19 | ||
|
|
a3da44f2ad | ||
|
|
ef7fa62e79 | ||
|
|
4bb75fe0d7 | ||
|
|
8cf4680ce1 | ||
|
|
bf1afc66dd | ||
|
|
d9c10c0d9c | ||
|
|
f28588fea5 | ||
|
|
3e72f72d15 | ||
|
|
bf179b9d12 | ||
|
|
9379289e58 | ||
|
|
edf7728cb5 |
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: Release to registry
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Fetch all tags
|
||||
run: git fetch --force --tags
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.17
|
||||
|
||||
- name: Import GPG key
|
||||
id: import_gpg
|
||||
uses: crazy-max/ghaction-import-gpg@v4
|
||||
with:
|
||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
passphrase: ${{ secrets.PASSPHRASE }}
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
args: release --rm-dist --release-notes CHANGELOG.md
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
decort/vendor/
|
||||
examples/
|
||||
url_scrapping/
|
||||
terraform-provider-decort*
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
# Visit https://goreleaser.com for documentation on how to customize this
|
||||
# behavior.
|
||||
before:
|
||||
hooks:
|
||||
# this is just an example and not a requirement for provider building/publishing
|
||||
- go mod tidy
|
||||
builds:
|
||||
- env:
|
||||
# goreleaser does not work with CGO, it could also complicate
|
||||
# usage by users in CI/CD systems like Terraform Cloud where
|
||||
# they are unable to install libraries.
|
||||
- CGO_ENABLED=0
|
||||
mod_timestamp: '{{ .CommitTimestamp }}'
|
||||
flags:
|
||||
@@ -37,11 +31,9 @@ checksum:
|
||||
signs:
|
||||
- artifacts: checksum
|
||||
args:
|
||||
# if you are using this in a GitHub action or some other automated pipeline, you
|
||||
# need to pass the batch flag to indicate its not interactive.
|
||||
- "--batch"
|
||||
- "--local-user"
|
||||
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
|
||||
- "{{ .Env.GPG_FINGERPRINT }}"
|
||||
- "--output"
|
||||
- "${signature}"
|
||||
- "--detach-sign"
|
||||
@@ -50,7 +42,5 @@ release:
|
||||
extra_files:
|
||||
- glob: 'terraform-registry-manifest.json'
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
|
||||
# If you want to manually examine the release before its live, uncomment this line:
|
||||
# draft: true
|
||||
changelog:
|
||||
skip: true
|
||||
skip: false
|
||||
|
||||
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
@@ -0,0 +1,5 @@
|
||||
### Bug fixes
|
||||
- k8s state import
|
||||
|
||||
### Minor changes
|
||||
- increased k8s and k8s\_wg create/update timeouts
|
||||
39
Makefile
Normal file
39
Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
TEST?=$$(go list ./... | grep -v 'vendor')
|
||||
HOSTNAME=digitalenergy.online
|
||||
NAMESPACE=decort
|
||||
NAME=terraform-provider-decort
|
||||
#BINARY=terraform-provider-${NAME}
|
||||
BINARY=${NAME}.exe
|
||||
VERSION=0.2
|
||||
#OS_ARCH=darwin_amd64
|
||||
OS_ARCH=windows_amd64
|
||||
|
||||
default: install
|
||||
|
||||
build:
|
||||
go build -o ${BINARY}
|
||||
|
||||
release:
|
||||
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
|
||||
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
|
||||
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
|
||||
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
|
||||
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
|
||||
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
|
||||
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
|
||||
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
|
||||
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
|
||||
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
|
||||
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
|
||||
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
|
||||
|
||||
install: build
|
||||
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
|
||||
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
|
||||
|
||||
test:
|
||||
go test -i $(TEST) || exit 1
|
||||
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
|
||||
|
||||
testacc:
|
||||
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
|
||||
146
README.md
146
README.md
@@ -1,55 +1,117 @@
|
||||
# terraform-provider-decort
|
||||
Terraform provider for Digital Energy Cloud Orchestration Technology (DECORT) platform
|
||||
Terraform provider для платформы Digital Energy Cloud Orchestration Technology (DECORT)
|
||||
|
||||
NOTE: provider rc-1.25 is designed for DECORT API 3.7.x. For older API versions please use:
|
||||
- DECORT API 3.6.x versions - provider version rc-1.10
|
||||
- DECORT API versions prior to 3.6.0 - Terraform DECS provider (https://github.com/rudecs/terraform-provider-decs)
|
||||
Внимание: провайдер версии rc-1.25 разработан для DECORT API 3.7.x.
|
||||
Для более старых версий можно использовать:
|
||||
- DECORT API 3.6.x - версия провайдера rc-1.10
|
||||
- DECORT API до 3.6.0 - terraform DECS provider (https://github.com/rudecs/terraform-provider-decs)
|
||||
|
||||
With this provider you can manage Compute instances, disks, virtual network segments and resource
|
||||
groups in DECORT platform, as well as query the platform for information about existing resources.
|
||||
This provider supports Import operations on pre-existing resources.
|
||||
## Возможности провайдера
|
||||
- Работа с Compute instances,
|
||||
- Работа с disks,
|
||||
- Работа с k8s,
|
||||
- Работа с virtual network segments,
|
||||
- Работа с image,
|
||||
- Работа с reource groups,
|
||||
- Работа с VINS,
|
||||
- Работа с pfw,
|
||||
- Работа с accounts.
|
||||
|
||||
See user guide at https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
|
||||
For a quick start follow these steps (assuming that your build host is running Linux; this provider builds on Windows as well, however, some paths may differ from what is mentioned below).
|
||||
## Начало
|
||||
Старт возможен по двум путям:
|
||||
1. Установка через собранные пакеты.
|
||||
2. Ручная установка.
|
||||
|
||||
1. Obtain the latest GO compiler. As of beginning 2021 it is recommended to use v.1.16.3 but as new Terraform versions are released newer Go compiler may be required, so check official Terraform repository regularly for more information.
|
||||
### Установка через собранные пакеты.
|
||||
1. Скачайте и установите terraform по ссылке: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
|
||||
2. Создайте файл `main.tf` и добавьте в него следующий блок.
|
||||
```terraform
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
```
|
||||
cd /tmp
|
||||
wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
|
||||
tar xvf ./go1.16.3.linux-amd64.tar.gz
|
||||
sudo mv go /usr/local
|
||||
3. Выполните команду
|
||||
```
|
||||
terraform init
|
||||
```
|
||||
Провайдер автоматически будет установлен на ваш компьютер из terraform registry.
|
||||
|
||||
### Ручная установка
|
||||
1. Скачайте и установите Go по ссылке: https://go.dev/dl/
|
||||
2. Скачайте и установите terraform по ссылке: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
|
||||
3. Склонируйте репозиторий с провайдером, выполнив команду:
|
||||
```bash
|
||||
git clone https://github.com/rudecs/terraform-provider-decort.git
|
||||
```
|
||||
4. Перейдите в скачанную папку с провайдером и выполните команду
|
||||
```bash
|
||||
go build -o terraform-provider-decort
|
||||
```
|
||||
Если вы знаете как устроен _makefile_, то можно изменить в файле `Makefile` параметры под вашу ОС и выполнить команду
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
5. Полученный файл необходимо поместить:
|
||||
Linux:
|
||||
```bash
|
||||
~/.terraform.d/plugins/${host_name}/${namespace}/${type}/${version}/${target}
|
||||
```
|
||||
Windows:
|
||||
```powershell
|
||||
%APPDATA%\terraform.d\plugins\${host_name}/${namespace}/${type}/${version}/${target}
|
||||
```
|
||||
ВНИМАНИЕ: для ОС Windows `%APP_DATA%` является каталогом, в котором будут помещены будущие файлы terraform.
|
||||
Где:
|
||||
- host_name - имя хоста, держателя провайдера, например, digitalenergy.online
|
||||
- namespace - пространство имен хоста, например decort
|
||||
- type - тип провайдера, может совпадать с пространством имен, например, decort
|
||||
- version - версия провайдера, например 1.2
|
||||
- target - версия ОС, например windows_amd64
|
||||
6. После этого, создайте файл `main.tf`.
|
||||
7. Добавьте в него следующий блок
|
||||
```terraform
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.2"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
В поле `version` указывается версия провайдера.
|
||||
Обязательный параметр
|
||||
Тип поля - строка
|
||||
ВНИМАНИЕ: Версии в блоке и в репозитории, в который был помещен провайдер должны совпадать!
|
||||
|
||||
В поле `source` помещается путь до репозитория с версией вида:
|
||||
```bash
|
||||
${host_name}/${namespace}/${type}
|
||||
```
|
||||
ВНИМАНИЕ: все параметры должны совпадать с путем репозитория, в котором помещен провайдер.
|
||||
|
||||
8. В консоле выполнить команду
|
||||
```bash
|
||||
terraform init
|
||||
```
|
||||
|
||||
2. Add the following environment variables' declarations to shell startup script:
|
||||
```
|
||||
export GOPATH=/opt/gopkg:~/
|
||||
export GOROOT=/usr/local/go
|
||||
export PATH=$PATH:$GOROOT/bin
|
||||
```
|
||||
9. Если все прошло хорошо - ошибок не будет.
|
||||
|
||||
3. Clone Terraform Plugin SDK framework repository to $GOPKG/src/github.com/hashicorp
|
||||
```
|
||||
mkdir -p $GOPKG/src/github.com/hashicorp
|
||||
cd $GOPKG/src/github.com/hashicorp
|
||||
git clone https://github.com/hashicorp/terraform-plugin-sdk.git
|
||||
```
|
||||
Более подробно о сборке провайдера можно найти по ссылке: https://learn.hashicorp.com/tutorials/terraform/provider-use?in=terraform/providers
|
||||
|
||||
4. Clone jwt-go package repository to $GOPKG/src/github.com/dgrijalva/jwt-go:
|
||||
```
|
||||
mkdir -p $GOPKG/src/github.com/dgrijalva
|
||||
cd $GOPKG/src/github.com/dgrijalva
|
||||
git clone https://github.com/dgrijalva/jwt-go.git
|
||||
```
|
||||
## Примеры работы
|
||||
Примеры работы можно найти:
|
||||
- На вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
- В папке `samples`
|
||||
|
||||
5. Clone Terraform DECORT provider repository to $GOPKG/src/github.com/terraform-provider-decort
|
||||
```
|
||||
cd $GOPKG/src/github.com
|
||||
git clone https://github.com/rudecs/terraform-provider-decort.git
|
||||
```
|
||||
Схемы к terraform'у доступны:
|
||||
- В папке `docs`
|
||||
|
||||
6. Build Terraform DECORT provider:
|
||||
```
|
||||
cd $GOPKG/src/github.com/terraform-provider-decort
|
||||
go build -o terraform-provider-decort
|
||||
```
|
||||
Хорошей работы!
|
||||
|
||||
118
README_EN.md
Normal file
118
README_EN.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# terraform-provider-decort
|
||||
Terraform provider for Digital Energy Cloud Orchestration Technology (DECORT) platform
|
||||
|
||||
NOTE: provider rc-1.25 is designed for DECORT API 3.7.x. For older API versions please use:
|
||||
- DECORT API 3.6.x versions - provider version rc-1.10
|
||||
- DECORT API versions prior to 3.6.0 - Terraform DECS provider (https://github.com/rudecs/terraform-provider-decs)
|
||||
|
||||
## Features
|
||||
- Work with Compute instances,
|
||||
- Work with disks,
|
||||
- Work with k8s,
|
||||
- Work with virtual network segments,
|
||||
- Work with image,
|
||||
- Work with reource groups,
|
||||
- Work with VINS,
|
||||
- Work with pfw,
|
||||
- Work with accounts.
|
||||
|
||||
This provider supports Import operations on pre-existing resources.
|
||||
|
||||
See user guide at https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
|
||||
|
||||
## Get Started
|
||||
Two ways for starting:
|
||||
1. Installing via binary packages
|
||||
2. Manual installing
|
||||
|
||||
### Installing via binary packages
|
||||
1. Download and install terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
|
||||
2. Create a file `main.tf` and add to it next section.
|
||||
```terraform
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
```
|
||||
3. Execute next command
|
||||
```
|
||||
terraform init
|
||||
```
|
||||
The Provider will automatically install on your computer from the terrafrom registry.
|
||||
|
||||
### Manual installing
|
||||
1. Download and install Go Programming Language: https://go.dev/dl/
|
||||
2. Download and install terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
|
||||
3. Clone provider's repo:
|
||||
```bash
|
||||
git clone https://github.com/rudecs/terraform-provider-decort.git
|
||||
```
|
||||
4. Change directory to clone provider's and execute next command
|
||||
```bash
|
||||
go build -o terraform-provider-decort
|
||||
```
|
||||
If you have experience with _makefile_, you can change `Makefile`'s paramters and execute next command
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
5. Now move compilled file to:
|
||||
Linux:
|
||||
```bash
|
||||
~/.terraform.d/plugins/${host_name}/${namespace}/${type}/${version}/${target}
|
||||
```
|
||||
Windows:
|
||||
```powershell
|
||||
%APPDATA%\terraform.d\plugins\${host_name}/${namespace}/${type}/${version}/${target}
|
||||
```
|
||||
NOTE: for Windows OS `%APP_DATA%` is a cataloge, where will place terraform files.
|
||||
Example:
|
||||
- host_name - digitalenergy.online
|
||||
- namespace - decort
|
||||
- type - decort
|
||||
- version - 1.2
|
||||
- target - windows_amd64
|
||||
6. After all, create a file `main.tf`.
|
||||
7. Add to the file next code section
|
||||
```terraform
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.2"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
`version`- field for provider's version
|
||||
Required
|
||||
String
|
||||
Note: Versions in code section and in a repository must be equal!
|
||||
|
||||
`source` - path to repository with provider's version
|
||||
```bash
|
||||
${host_name}/${namespace}/${type}
|
||||
```
|
||||
NOTE: all paramters must be equal to the repository path!
|
||||
|
||||
8. Execute command in your terminal
|
||||
```bash
|
||||
terraform init
|
||||
```
|
||||
|
||||
9. If everything all right - you got green message in your terminal!
|
||||
|
||||
More details about the provider's building process: https://learn.hashicorp.com/tutorials/terraform/provider-use?in=terraform/providers
|
||||
|
||||
## Examples and Samples
|
||||
- Examples: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
- Samples: see in repository `samples`
|
||||
|
||||
Terraform schemas in:
|
||||
- See in repository `docs`
|
||||
|
||||
Good work!
|
||||
100
decort/data_source_grid.go
Normal file
100
decort/data_source_grid.go
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func flattenGrid(d *schema.ResourceData, grid *Grid) {
|
||||
d.Set("name", grid.Name)
|
||||
d.Set("flag", grid.Flag)
|
||||
d.Set("gid", grid.Gid)
|
||||
d.Set("guid", grid.Guid)
|
||||
d.Set("location_code", grid.LocationCode)
|
||||
d.Set("id", grid.Id)
|
||||
return
|
||||
}
|
||||
|
||||
func dataSourceGridRead(d *schema.ResourceData, m interface{}) error {
|
||||
grid, err := utilityGridCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId(strconv.Itoa(grid.Id))
|
||||
flattenGrid(d, grid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGetGridSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"grid_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"flag": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"location_code": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceGrid() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceGridRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGetGridSchemaMake(),
|
||||
}
|
||||
}
|
||||
128
decort/data_source_grid_list.go
Normal file
128
decort/data_source_grid_list.go
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func flattenGridList(gl GridList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range gl {
|
||||
temp := map[string]interface{}{
|
||||
"name": item.Name,
|
||||
"flag": item.Flag,
|
||||
"gid": item.Gid,
|
||||
"guid": item.Guid,
|
||||
"location_code": item.LocationCode,
|
||||
"id": item.Id,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceGridListRead(d *schema.ResourceData, m interface{}) error {
|
||||
gridList, err := utilityGridListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenGridList(gridList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "grid list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceGridSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceGridSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"flag": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"location_code": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceGridList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceGridListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Sergey Shubin, <sergey.shubin@digitalenergy.online>, <svs1370@gmail.com>
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -25,57 +25,275 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
)
|
||||
|
||||
func flattenImage(d *schema.ResourceData, image *Image) {
|
||||
d.Set("name", image.Name)
|
||||
d.Set("drivers", image.Drivers)
|
||||
d.Set("url", image.Url)
|
||||
d.Set("gid", image.Gid)
|
||||
d.Set("image_id", image.ImageId)
|
||||
d.Set("boot_type", image.Boottype)
|
||||
d.Set("image_type", image.Imagetype)
|
||||
d.Set("bootable", image.Bootable)
|
||||
d.Set("sep_id", image.SepId)
|
||||
d.Set("unc_path", image.UNCPath)
|
||||
d.Set("link_to", image.LinkTo)
|
||||
d.Set("status", image.Status)
|
||||
d.Set("tech_status", image.TechStatus)
|
||||
d.Set("version", image.Version)
|
||||
d.Set("size", image.Size)
|
||||
d.Set("enabled", image.Enabled)
|
||||
d.Set("computeci_id", image.ComputeciId)
|
||||
d.Set("pool_name", image.PoolName)
|
||||
d.Set("username", image.Username)
|
||||
d.Set("username_dl", image.UsernameDL)
|
||||
d.Set("password", image.Password)
|
||||
d.Set("password_dl", image.PasswordDL)
|
||||
d.Set("account_id", image.AccountId)
|
||||
d.Set("guid", image.Guid)
|
||||
d.Set("milestones", image.Milestones)
|
||||
d.Set("provider_name", image.ProviderName)
|
||||
d.Set("purge_attempts", image.PurgeAttempts)
|
||||
d.Set("reference_id", image.ReferenceId)
|
||||
d.Set("res_id", image.ResId)
|
||||
d.Set("res_name", image.ResName)
|
||||
d.Set("rescuecd", image.Rescuecd)
|
||||
d.Set("architecture", image.Architecture)
|
||||
d.Set("hot_resize", image.Hotresize)
|
||||
d.Set("history", flattenHistory(image.History))
|
||||
d.Set("last_modified", image.LastModified)
|
||||
d.Set("meta", flattenMeta(image.Meta))
|
||||
d.Set("desc", image.Desc)
|
||||
d.Set("shared_with", image.SharedWith)
|
||||
return
|
||||
}
|
||||
|
||||
func dataSourceImageRead(d *schema.ResourceData, m interface{}) error {
|
||||
name := d.Get("name").(string)
|
||||
// rg_id, rgid_set := d.GetOk("rg_id")
|
||||
accId, accSet := d.GetOk("account_id")
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
url_values := &url.Values{}
|
||||
if accSet {
|
||||
url_values.Add("accountId", fmt.Sprintf("%d", accId.(int)))
|
||||
}
|
||||
body_string, err := controller.decortAPICall("POST", ImagesListAPI, url_values)
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
d.SetId(strconv.Itoa(image.Guid))
|
||||
flattenImage(d, image)
|
||||
|
||||
log.Debugf("dataSourceImageRead: ready to decode response body from %s", ImagesListAPI)
|
||||
model := ImagesListResp{}
|
||||
err = json.Unmarshal([]byte(body_string), &model)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceImageSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the rescue disk",
|
||||
},
|
||||
"url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "URL where to download media from",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "grid (platform) ID where this template should be create in",
|
||||
},
|
||||
"boot_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Boot type of image bios or uefi",
|
||||
},
|
||||
"image_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Image type linux, windows or other",
|
||||
},
|
||||
"shared_with": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"history": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"hot_resize": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Does this machine supports hot resize",
|
||||
},
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Optional username for the image",
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Optional password for the image",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "AccountId to make the image exclusive",
|
||||
},
|
||||
"username_dl": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "username for upload binary media",
|
||||
},
|
||||
"password_dl": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "password for upload binary media",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "pool for image create",
|
||||
},
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "image id",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Whether to completely delete the image",
|
||||
},
|
||||
"bootable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Does this image boot OS",
|
||||
},
|
||||
"unc_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "unc path",
|
||||
},
|
||||
"link_to": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "tech atatus",
|
||||
},
|
||||
"version": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "version",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image size",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"provider_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rescuecd": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"last_modified": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
// log.Printf("%#v", model)
|
||||
log.Debugf("dataSourceImageRead: traversing decoded JSON of length %d", len(model))
|
||||
for index, item := range model {
|
||||
// need to match Image by name
|
||||
if item.Name == name {
|
||||
log.Debugf("dataSourceImageRead: index %d, matched name %s", index, item.Name)
|
||||
d.SetId(fmt.Sprintf("%d", item.ID))
|
||||
d.Set("account_id", item.AccountID)
|
||||
d.Set("arch", item.Arch)
|
||||
d.Set("sep_id", item.SepID)
|
||||
d.Set("pool", item.Pool)
|
||||
d.Set("status", item.Status)
|
||||
d.Set("size", item.Size)
|
||||
// d.Set("field_name", value)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("Cannot find Image name %s", name)
|
||||
}
|
||||
|
||||
func dataSourceImage() *schema.Resource {
|
||||
@@ -89,57 +307,6 @@ func dataSourceImage() *schema.Resource {
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of the image to locate. This parameter is case sensitive.",
|
||||
},
|
||||
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.IntAtLeast(1),
|
||||
Description: "Optional ID of the account to limit image search to.",
|
||||
},
|
||||
|
||||
"arch": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Binary architecture of this image.",
|
||||
},
|
||||
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Storage end-point provider serving this image.",
|
||||
},
|
||||
|
||||
/*
|
||||
"sep_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Type of the storage end-point provider serving this image.",
|
||||
},
|
||||
*/
|
||||
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Pool where this image is located.",
|
||||
},
|
||||
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Size of the image in GB.",
|
||||
},
|
||||
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Current model status of this image.",
|
||||
},
|
||||
},
|
||||
Schema: dataSourceImageSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
140
decort/data_source_image_list.go
Normal file
140
decort/data_source_image_list.go
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func flattenImageList(il ImageList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range il {
|
||||
temp := map[string]interface{}{
|
||||
"name": item.Name,
|
||||
"url": item.Url,
|
||||
"gid": item.Gid,
|
||||
"guid": item.Guid,
|
||||
"drivers": item.Drivers,
|
||||
"image_id": item.ImageId,
|
||||
"boot_type": item.Boottype,
|
||||
"bootable": item.Bootable,
|
||||
"image_type": item.Imagetype,
|
||||
"status": item.Status,
|
||||
"tech_status": item.TechStatus,
|
||||
"version": item.Version,
|
||||
"username": item.Username,
|
||||
"username_dl": item.UsernameDL,
|
||||
"password": item.Password,
|
||||
"password_dl": item.PasswordDL,
|
||||
"purge_attempts": item.PurgeAttempts,
|
||||
"architecture": item.Architecture,
|
||||
"account_id": item.AccountId,
|
||||
"computeci_id": item.ComputeciId,
|
||||
"enabled": item.Enabled,
|
||||
"reference_id": item.ReferenceId,
|
||||
"res_id": item.ResId,
|
||||
"res_name": item.ResName,
|
||||
"rescuecd": item.Rescuecd,
|
||||
"provider_name": item.ProviderName,
|
||||
"milestones": item.Milestones,
|
||||
"size": item.Size,
|
||||
"sep_id": item.SepId,
|
||||
"link_to": item.LinkTo,
|
||||
"unc_path": item.UNCPath,
|
||||
"pool_name": item.PoolName,
|
||||
"hot_resize": item.Hotresize,
|
||||
"history": flattenHistory(item.History),
|
||||
"last_modified": item.LastModified,
|
||||
"meta": flattenMeta(item.Meta),
|
||||
"desc": item.Desc,
|
||||
"shared_with": item.SharedWith,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceImageListRead(d *schema.ResourceData, m interface{}) error {
|
||||
imageList, err := utilityImageListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenImageList(imageList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceImageListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "filter images by storage endpoint provider ID",
|
||||
},
|
||||
"shared_with": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "filter images by account ID availability",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "image list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceImageSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceImageList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceImageListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceImageListSchemaMake(),
|
||||
}
|
||||
}
|
||||
182
decort/data_source_image_list_stacks.go
Normal file
182
decort/data_source_image_list_stacks.go
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func flattenImageListStacks(d *schema.ResourceData, stack ImageListStacks) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0)
|
||||
for _, item := range stack {
|
||||
t := map[string]interface{}{
|
||||
"api_url": item.ApiURL,
|
||||
"api_key": item.ApiKey,
|
||||
"app_id": item.AppId,
|
||||
"desc": item.Desc,
|
||||
"drivers": item.Drivers,
|
||||
"error": item.Error,
|
||||
"guid": item.Guid,
|
||||
"id": item.Id,
|
||||
"images": item.Images,
|
||||
"login": item.Login,
|
||||
"name": item.Name,
|
||||
"passwd": item.Passwd,
|
||||
"reference_id": item.ReferenceId,
|
||||
"status": item.Status,
|
||||
"type": item.Type,
|
||||
}
|
||||
|
||||
temp = append(temp, t)
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func dataSourceImageListStacksRead(d *schema.ResourceData, m interface{}) error {
|
||||
imageListStacks, err := utilityImageListStacksCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenImageListStacks(d, imageListStacks))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceImageListStackSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"api_url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"api_key": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"error": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"images": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"passwd": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "image id",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceImageListStackSchemaMake(),
|
||||
},
|
||||
Description: "items of stacks list",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceImageListStacks() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceImageListStacksRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceImageListStacksSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p
|
||||
package decort
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -35,6 +36,7 @@ import (
|
||||
var Timeout30s = time.Second * 30
|
||||
var Timeout60s = time.Second * 60
|
||||
var Timeout180s = time.Second * 180
|
||||
var Timeout20m = time.Minute * 20
|
||||
|
||||
//
|
||||
// structures related to /cloudapi/rg/list API
|
||||
@@ -581,11 +583,16 @@ const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
|
||||
|
||||
//K8sNodeRecord represents a worker/master group
|
||||
type K8sNodeRecord struct {
|
||||
ID int `json:"id"`
|
||||
Disk int `json:"disk"`
|
||||
Cpu int `json:"cpu"`
|
||||
Num int `json:"num"`
|
||||
Ram int `json:"ram"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Disk int `json:"disk"`
|
||||
Cpu int `json:"cpu"`
|
||||
Num int `json:"num"`
|
||||
Ram int `json:"ram"`
|
||||
DetailedInfo []struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"detailedInfo"`
|
||||
}
|
||||
|
||||
//K8sRecord represents k8s instance
|
||||
@@ -611,22 +618,38 @@ const K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete"
|
||||
const K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd"
|
||||
const K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete"
|
||||
|
||||
const K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd"
|
||||
const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
|
||||
|
||||
const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
|
||||
|
||||
//Blasphemous workaround for parsing Result value
|
||||
type TaskResult int
|
||||
|
||||
func (r *TaskResult) UnmarshalJSON(b []byte) error {
|
||||
b = bytes.Trim(b, `"`)
|
||||
if len(b) == 0 {
|
||||
*r = 0
|
||||
return nil
|
||||
if b[0] == '"' {
|
||||
b := b[1 : len(b)-1]
|
||||
if len(b) == 0 {
|
||||
*r = 0
|
||||
return nil
|
||||
}
|
||||
n, err := strconv.Atoi(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*r = TaskResult(n)
|
||||
} else if b[0] == '[' {
|
||||
res := []interface{}{}
|
||||
if err := json.Unmarshal(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
if n, ok := res[0].(float64); ok {
|
||||
*r = TaskResult(n)
|
||||
} else {
|
||||
return fmt.Errorf("could not unmarshal %v into int", res[0])
|
||||
}
|
||||
}
|
||||
|
||||
n, err := strconv.Atoi(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = TaskResult(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -667,3 +690,112 @@ type SshKeyConfig struct {
|
||||
SshKey string
|
||||
UserShell string
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// IMAGE API //
|
||||
////////////////////
|
||||
const imageCreateAPI = "/restmachine/cloudbroker/image/createImage"
|
||||
const imageSyncCreateAPI = "/restmachine/cloudbroker/image/syncCreateImage"
|
||||
const imageCreateVirtualAPI = "/restmachine/cloudbroker/image/createVirtual"
|
||||
const imageCreateCDROMAPI = "/restmachine/cloudbroker/image/createCDROMImage"
|
||||
const imageListStacksApi = "/restmachine/cloudbroker/image/listStacks"
|
||||
const imageGetAPI = "/restmachine/cloudbroker/image/get"
|
||||
const imageListGetAPI = "/restmachine/cloudbroker/image/list"
|
||||
const imageEditAPI = "/restmachine/cloudbroker/image/edit"
|
||||
const imageDeleteAPI = "/restmachine/cloudbroker/image/delete"
|
||||
const imageDeleteCDROMAPI = "/restmachine/cloudbroker/image/deleteCDROMImage"
|
||||
const imageEnableAPI = "/restmachine/cloudbroker/image/enable"
|
||||
const imageDisableAPI = "/restmachine/cloudbroker/image/disable"
|
||||
const imageEditNameAPI = "/restmachine/cloudbroker/image/rename"
|
||||
const imageLinkAPI = "/restmachine/cloudbroker/image/link"
|
||||
const imageShareAPI = "/restmachine/cloudbroker/image/share"
|
||||
const imageComputeciSetAPI = "/restmachine/cloudbroker/image/computeciSet"
|
||||
const imageComputeciUnsetAPI = "/restmachine/cloudbroker/image/computeciUnset"
|
||||
const imageUpdateNodesAPI = "/restmachine/cloudbroker/image/updateNodes"
|
||||
const imageDeleteImagesAPI = "/restmachine/cloudbroker/image/deleteImages"
|
||||
|
||||
type History struct {
|
||||
Guid string `json:"guid"`
|
||||
Id int `json:"id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
ImageId int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Gid int `json:"gid"`
|
||||
Guid int `json:"guid"`
|
||||
Boottype string `json:"bootType"`
|
||||
Imagetype string `json:"type"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Hotresize bool `json:"hotResize"`
|
||||
Bootable bool `json:"bootable"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
AccountId int `json:"accountId"`
|
||||
UsernameDL string `json:"usernameDL"`
|
||||
PasswordDL string `json:"passwordDL"`
|
||||
SepId int `json:"sepId"`
|
||||
PoolName string `json:"pool"`
|
||||
Architecture string `json:"architecture"`
|
||||
UNCPath string `json:"UNCPath"`
|
||||
LinkTo int `json:"linkTo"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Size int `json:"size"`
|
||||
Version string `json:"version"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ComputeciId int `json:"computeciId"`
|
||||
Milestones int `json:"milestones"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
PurgeAttempts int `json:"purgeAttempts"`
|
||||
ReferenceId string `json:"referenceId"`
|
||||
ResId string `json:"resId"`
|
||||
ResName string `json:"resName"`
|
||||
Rescuecd bool `json:"rescuecd"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
History []History `json:"history"`
|
||||
LastModified int64 `json:"lastModified"`
|
||||
Desc string `json:"desc"`
|
||||
SharedWith []int `json:"sharedWith"`
|
||||
}
|
||||
|
||||
type ImageList []Image
|
||||
|
||||
type ImageStack struct {
|
||||
ApiURL string `json:"apiUrl"`
|
||||
ApiKey string `json:"apikey"`
|
||||
AppId string `json:"appId"`
|
||||
Desc string `json:"desc"`
|
||||
Drivers []string `json:"drivers"`
|
||||
Error int `json:"error"`
|
||||
Guid int `json:"guid"`
|
||||
Id int `json:"id"`
|
||||
Images []int `json:"images"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
Passwd string `json:"passwd"`
|
||||
ReferenceId string `json:"referenceId"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type ImageListStacks []ImageStack
|
||||
|
||||
/////////////////
|
||||
// GRID API //
|
||||
/////////////////
|
||||
const GridListGetAPI = "/restmachine/cloudbroker/grid/list"
|
||||
const GridGetAPI = "/restmachine/cloudbroker/grid/get"
|
||||
|
||||
type Grid struct {
|
||||
Flag string `json:"flag"`
|
||||
Gid int `json:"gid"`
|
||||
Guid int `json:"guid"`
|
||||
Id int `json:"id"`
|
||||
LocationCode string `json:"locationCode"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type GridList []Grid
|
||||
|
||||
@@ -58,7 +58,6 @@ func parseNode(nodeList []interface{}) K8sNodeRecord {
|
||||
func nodeToResource(node K8sNodeRecord) []interface{} {
|
||||
mp := make(map[string]interface{})
|
||||
|
||||
mp["id"] = node.ID
|
||||
mp["num"] = node.Num
|
||||
mp["cpu"] = node.Cpu
|
||||
mp["ram"] = node.Ram
|
||||
@@ -72,7 +71,6 @@ func nodeK8sSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Number of nodes to create.",
|
||||
},
|
||||
|
||||
|
||||
@@ -99,22 +99,30 @@ func Provider() *schema.Provider {
|
||||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"decort_resgroup": resourceResgroup(),
|
||||
"decort_kvmvm": resourceCompute(),
|
||||
"decort_disk": resourceDisk(),
|
||||
"decort_vins": resourceVins(),
|
||||
"decort_pfw": resourcePfw(),
|
||||
"decort_k8s": resourceK8s(),
|
||||
"decort_k8s_wg": resourceK8sWg(),
|
||||
"decort_resgroup": resourceResgroup(),
|
||||
"decort_kvmvm": resourceCompute(),
|
||||
"decort_disk": resourceDisk(),
|
||||
"decort_vins": resourceVins(),
|
||||
"decort_pfw": resourcePfw(),
|
||||
"decort_k8s": resourceK8s(),
|
||||
"decort_k8s_wg": resourceK8sWg(),
|
||||
"decort_image": resourceImage(),
|
||||
"decort_virtual_image": resourceVirtualImage(),
|
||||
"decort_cdrom_image": resourceCDROMImage(),
|
||||
"decort_delete_images": resourceDeleteImages(),
|
||||
},
|
||||
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
"decort_account": dataSourceAccount(),
|
||||
"decort_resgroup": dataSourceResgroup(),
|
||||
"decort_kvmvm": dataSourceCompute(),
|
||||
"decort_image": dataSourceImage(),
|
||||
"decort_disk": dataSourceDisk(),
|
||||
"decort_vins": dataSourceVins(),
|
||||
"decort_account": dataSourceAccount(),
|
||||
"decort_resgroup": dataSourceResgroup(),
|
||||
"decort_kvmvm": dataSourceCompute(),
|
||||
"decort_image": dataSourceImage(),
|
||||
"decort_disk": dataSourceDisk(),
|
||||
"decort_vins": dataSourceVins(),
|
||||
"decort_grid": dataSourceGrid(),
|
||||
"decort_grid_list": dataSourceGridList(),
|
||||
"decort_image_list": dataSourceImageList(),
|
||||
"decort_image_list_stacks": dataSourceImageListStacks(),
|
||||
// "decort_pfw": dataSourcePfw(),
|
||||
},
|
||||
|
||||
|
||||
449
decort/resource_cdrom_image.go
Normal file
449
decort/resource_cdrom_image.go
Normal file
@@ -0,0 +1,449 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceCDROMImageCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceCDROMImageCreate: called for image %s", d.Get("name").(string))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("url", d.Get("url").(string))
|
||||
urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int)))
|
||||
|
||||
tstr := d.Get("drivers").([]interface{})
|
||||
temp := ""
|
||||
l := len(tstr)
|
||||
for i, str := range tstr {
|
||||
s := "\"" + str.(string) + "\""
|
||||
if i != (l - 1) {
|
||||
s += ","
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("drivers", temp)
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
urlValues.Add("username", username.(string))
|
||||
}
|
||||
if password, ok := d.GetOk("password"); ok {
|
||||
urlValues.Add("password", password.(string))
|
||||
}
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
|
||||
}
|
||||
if usernameDL, ok := d.GetOk("username_dl"); ok {
|
||||
urlValues.Add("usernameDL", usernameDL.(string))
|
||||
}
|
||||
if passwordDL, ok := d.GetOk("password_dl"); ok {
|
||||
urlValues.Add("passwordDL", passwordDL.(string))
|
||||
}
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
urlValues.Add("sepId", strconv.Itoa(sepId.(int)))
|
||||
}
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
urlValues.Add("pool_name", poolName.(string))
|
||||
}
|
||||
if architecture, ok := d.GetOk("architecture"); ok {
|
||||
urlValues.Add("architecture", architecture.(string))
|
||||
}
|
||||
|
||||
imageId, err := controller.decortAPICall("POST", imageCreateCDROMAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(imageId)
|
||||
d.Set("image_id", imageId)
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(image.ImageId))
|
||||
d.Set("bootable", image.Bootable)
|
||||
//d.Set("image_id", image.ImageId)
|
||||
|
||||
err = resourceImageRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceCDROMImageDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceCDROMImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if image == nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
|
||||
if permanently, ok := d.GetOk("permanently"); ok {
|
||||
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
||||
}
|
||||
|
||||
_, err = controller.decortAPICall("POST", imageDeleteCDROMAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of the rescue disk",
|
||||
},
|
||||
"url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "URL where to download ISO from",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "grid (platform) ID where this template should be create in",
|
||||
},
|
||||
"boot_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Boot type of image bios or uefi",
|
||||
},
|
||||
"image_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Image type linux, windows or other",
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"hot_resize": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this machine supports hot resize",
|
||||
},
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional username for the image",
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional password for the image",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "AccountId to make the image exclusive",
|
||||
},
|
||||
"username_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "username for upload binary media",
|
||||
},
|
||||
"password_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "password for upload binary media",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "pool for image create",
|
||||
},
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image id",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Whether to completely delete the image",
|
||||
},
|
||||
"bootable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this image boot OS",
|
||||
},
|
||||
"unc_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "unc path",
|
||||
},
|
||||
"link_to": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "tech atatus",
|
||||
},
|
||||
"version": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "version",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image size",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"provider_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rescuecd": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"shared_with": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"enabled_stacks": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"history": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceCDROMImage() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceCDROMImageCreate,
|
||||
Read: resourceImageRead,
|
||||
Update: resourceImageEdit,
|
||||
Delete: resourceCDROMImageDelete,
|
||||
Exists: resourceImageExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
CustomizeDiff: customdiff.All(
|
||||
customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool {
|
||||
if old.(bool) != new.(bool) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeEnabled),
|
||||
customdiff.IfValueChange("name", func(old, new, meta interface{}) bool {
|
||||
if old.(string) != new.(string) && old.(string) != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageEditName),
|
||||
customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(int) == o[i].(int) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageShare),
|
||||
customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool {
|
||||
if old.(int) != new.(int) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeComputeci),
|
||||
customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(string) == o[i].(string) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageUpdateNodes),
|
||||
),
|
||||
|
||||
Schema: resourceCDROMImageSchemaMake(),
|
||||
}
|
||||
}
|
||||
131
decort/resource_delete_images.go
Normal file
131
decort/resource_delete_images.go
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceCreateListImages(d *schema.ResourceData, m interface{}) error {
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDeleteListImages(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceDeleteListImages: start deleting...")
|
||||
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
imageIds := d.Get("image_ids").([]interface{})
|
||||
temp := ""
|
||||
l := len(imageIds)
|
||||
for i, imageId := range imageIds {
|
||||
s := strconv.Itoa(imageId.(int))
|
||||
if i != (l - 1) {
|
||||
s += ",\n"
|
||||
} else {
|
||||
s += "\n"
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
|
||||
urlValues.Add("reason", d.Get("reason").(string))
|
||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||
urlValues.Add("imageIds", temp)
|
||||
|
||||
_, err := c.decortAPICall("POST", imageDeleteImagesAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceReadListImages(d *schema.ResourceData, m interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDeleteImagesSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"image_ids": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
MinItems: 1,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "images ids for deleting",
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "reason for deleting the images",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: false,
|
||||
Description: "whether to completely delete the images",
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func resourceDeleteImages() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceCreateListImages,
|
||||
Read: resourceReadListImages,
|
||||
Delete: resourceDeleteListImages,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourceDeleteImagesSchemaMake(),
|
||||
}
|
||||
}
|
||||
738
decort/resource_image.go
Normal file
738
decort/resource_image.go
Normal file
@@ -0,0 +1,738 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceImageCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("url", d.Get("url").(string))
|
||||
urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int)))
|
||||
urlValues.Add("boottype", d.Get("boot_type").(string))
|
||||
urlValues.Add("imagetype", d.Get("image_type").(string))
|
||||
|
||||
tstr := d.Get("drivers").([]interface{})
|
||||
temp := ""
|
||||
l := len(tstr)
|
||||
for i, str := range tstr {
|
||||
s := "\"" + str.(string) + "\""
|
||||
if i != (l - 1) {
|
||||
s += ","
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("drivers", temp)
|
||||
|
||||
if hotresize, ok := d.GetOk("hot_resize"); ok {
|
||||
urlValues.Add("hotresize", strconv.FormatBool(hotresize.(bool)))
|
||||
}
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
urlValues.Add("username", username.(string))
|
||||
}
|
||||
if password, ok := d.GetOk("password"); ok {
|
||||
urlValues.Add("password", password.(string))
|
||||
}
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
|
||||
}
|
||||
if usernameDL, ok := d.GetOk("username_dl"); ok {
|
||||
urlValues.Add("usernameDL", usernameDL.(string))
|
||||
}
|
||||
if passwordDL, ok := d.GetOk("password_dl"); ok {
|
||||
urlValues.Add("passwordDL", passwordDL.(string))
|
||||
}
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
urlValues.Add("sepId", strconv.Itoa(sepId.(int)))
|
||||
}
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
urlValues.Add("poolName", poolName.(string))
|
||||
}
|
||||
if architecture, ok := d.GetOk("architecture"); ok {
|
||||
urlValues.Add("architecture", architecture.(string))
|
||||
}
|
||||
|
||||
api := ""
|
||||
isSync := d.Get("sync").(bool)
|
||||
if !isSync {
|
||||
api = imageCreateAPI
|
||||
} else {
|
||||
api = imageSyncCreateAPI
|
||||
}
|
||||
imageId, err := controller.decortAPICall("POST", api, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(imageId)
|
||||
d.Set("image_id", imageId)
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(image.ImageId))
|
||||
d.Set("bootable", image.Bootable)
|
||||
//d.Set("image_id", image.ImageId)
|
||||
|
||||
err = resourceImageRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageRead(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if image == nil {
|
||||
d.SetId("")
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("name", image.Name)
|
||||
d.Set("drivers", image.Drivers)
|
||||
d.Set("url", image.Url)
|
||||
d.Set("gid", image.Gid)
|
||||
d.Set("image_id", image.ImageId)
|
||||
d.Set("boot_type", image.Boottype)
|
||||
d.Set("image_type", image.Imagetype)
|
||||
d.Set("bootable", image.Bootable)
|
||||
d.Set("sep_id", image.SepId)
|
||||
d.Set("unc_path", image.UNCPath)
|
||||
d.Set("link_to", image.LinkTo)
|
||||
d.Set("status", image.Status)
|
||||
d.Set("tech_status", image.TechStatus)
|
||||
d.Set("version", image.Version)
|
||||
d.Set("size", image.Size)
|
||||
d.Set("enabled", image.Enabled)
|
||||
d.Set("computeci_id", image.ComputeciId)
|
||||
d.Set("pool_name", image.PoolName)
|
||||
d.Set("username", image.Username)
|
||||
d.Set("username_dl", image.UsernameDL)
|
||||
d.Set("password", image.Password)
|
||||
d.Set("password_dl", image.PasswordDL)
|
||||
d.Set("account_id", image.AccountId)
|
||||
d.Set("guid", image.Guid)
|
||||
d.Set("milestones", image.Milestones)
|
||||
d.Set("provider_name", image.ProviderName)
|
||||
d.Set("purge_attempts", image.PurgeAttempts)
|
||||
d.Set("reference_id", image.ReferenceId)
|
||||
d.Set("res_id", image.ResId)
|
||||
d.Set("res_name", image.ResName)
|
||||
d.Set("rescuecd", image.Rescuecd)
|
||||
d.Set("architecture", image.Architecture)
|
||||
d.Set("meta", flattenMeta(image.Meta))
|
||||
d.Set("hot_resize", image.Hotresize)
|
||||
d.Set("history", flattenHistory(image.History))
|
||||
d.Set("last_modified", image.LastModified)
|
||||
d.Set("desc", image.Desc)
|
||||
d.Set("shared_with", image.SharedWith)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if image == nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
if reason, ok := d.GetOk("reason"); ok {
|
||||
urlValues.Add("reason", reason.(string))
|
||||
} else {
|
||||
urlValues.Add("reason", "")
|
||||
}
|
||||
if permanently, ok := d.GetOk("permanently"); ok {
|
||||
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
||||
}
|
||||
|
||||
_, err = controller.decortAPICall("POST", imageDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
log.Debugf("resourceImageExists: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if image == nil {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func resourceImageEditName(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
_, err := c.decortAPICall("POST", imageEditNameAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageEdit(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
|
||||
urlValues.Add("username", d.Get("username").(string))
|
||||
urlValues.Add("password", d.Get("password").(string))
|
||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||
urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool)))
|
||||
urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool)))
|
||||
|
||||
//_, err := c.decortAPICall("POST", imageEditAPI, urlValues)
|
||||
_, err := c.decortAPICall("POST", imageEditAPI, urlValues)
|
||||
if err != nil {
|
||||
err = resourceImageRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
err = resourceImageRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageChangeEnabled(d *schema.ResourceDiff, m interface{}) error {
|
||||
var api string
|
||||
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
if d.Get("enabled").(bool) {
|
||||
api = imageEnableAPI
|
||||
} else {
|
||||
api = imageDisableAPI
|
||||
}
|
||||
resp, err := c.decortAPICall("POST", api, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res, err := strconv.ParseBool(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !res {
|
||||
return errors.New("Cannot enable/disable")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageLink(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
urlValues.Add("targetId", strconv.Itoa(d.Get("link_to").(int)))
|
||||
_, err := c.decortAPICall("POST", imageLinkAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageShare(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
accIds := d.Get("shared_with").([]interface{})
|
||||
temp := ""
|
||||
l := len(accIds)
|
||||
for i, accId := range accIds {
|
||||
s := strconv.Itoa(accId.(int))
|
||||
if i != (l - 1) {
|
||||
s += ",\n"
|
||||
} else {
|
||||
s += "\n"
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("accounts", temp)
|
||||
_, err := c.decortAPICall("POST", imageShareAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageChangeComputeci(d *schema.ResourceDiff, m interface{}) error {
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
computeci := d.Get("computeci_id").(int)
|
||||
|
||||
api := ""
|
||||
|
||||
if computeci == 0 {
|
||||
api = imageComputeciUnsetAPI
|
||||
} else {
|
||||
urlValues.Add("computeciId", strconv.Itoa(computeci))
|
||||
api = imageComputeciSetAPI
|
||||
}
|
||||
|
||||
_, err := c.decortAPICall("POST", api, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageUpdateNodes(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
enabledStacks := d.Get("enabled_stacks").([]interface{})
|
||||
temp := ""
|
||||
l := len(enabledStacks)
|
||||
for i, stackId := range enabledStacks {
|
||||
s := stackId.(string)
|
||||
if i != (l - 1) {
|
||||
s += ","
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("enabledStacks", temp)
|
||||
_, err := c.decortAPICall("POST", imageUpdateNodesAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceImageSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of the rescue disk",
|
||||
},
|
||||
"url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "URL where to download media from",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "grid (platform) ID where this template should be create in",
|
||||
},
|
||||
"boot_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Boot type of image bios or uefi",
|
||||
},
|
||||
"image_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Image type linux, windows or other",
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"hot_resize": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this machine supports hot resize",
|
||||
},
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional username for the image",
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional password for the image",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "AccountId to make the image exclusive",
|
||||
},
|
||||
"username_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "username for upload binary media",
|
||||
},
|
||||
"password_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "password for upload binary media",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "pool for image create",
|
||||
},
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "image id",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Whether to completely delete the image",
|
||||
},
|
||||
"bootable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this image boot OS",
|
||||
},
|
||||
"unc_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "unc path",
|
||||
},
|
||||
"link_to": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "tech atatus",
|
||||
},
|
||||
"version": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "version",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image size",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"provider_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rescuecd": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"last_modified": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"shared_with": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"sync": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Create image from a media identified by URL (in synchronous mode)",
|
||||
},
|
||||
"enabled_stacks": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"history": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceImage() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceImageCreate,
|
||||
Read: resourceImageRead,
|
||||
Update: resourceImageEdit,
|
||||
Delete: resourceImageDelete,
|
||||
Exists: resourceImageExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
CustomizeDiff: customdiff.All(
|
||||
customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool {
|
||||
if old.(bool) != new.(bool) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeEnabled),
|
||||
customdiff.IfValueChange("name", func(old, new, meta interface{}) bool {
|
||||
if old.(string) != new.(string) && old.(string) != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageEditName),
|
||||
customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(int) == o[i].(int) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageShare),
|
||||
customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool {
|
||||
if old.(int) != new.(int) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeComputeci),
|
||||
customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(string) == o[i].(string) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageUpdateNodes),
|
||||
),
|
||||
|
||||
Schema: resourceImageSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func flattenMeta(m []interface{}) []string {
|
||||
output := []string{}
|
||||
for _, item := range m {
|
||||
switch d := item.(type) {
|
||||
case string:
|
||||
output = append(output, d)
|
||||
case int:
|
||||
output = append(output, strconv.Itoa(d))
|
||||
case int64:
|
||||
output = append(output, strconv.FormatInt(d, 10))
|
||||
case float64:
|
||||
output = append(output, strconv.FormatInt(int64(d), 10))
|
||||
default:
|
||||
output = append(output, "")
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func flattenHistory(history []History) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0)
|
||||
for _, item := range history {
|
||||
t := map[string]interface{}{
|
||||
"id": item.Id,
|
||||
"guid": item.Guid,
|
||||
"timestamp": item.Timestamp,
|
||||
}
|
||||
|
||||
temp = append(temp, t)
|
||||
}
|
||||
return temp
|
||||
}
|
||||
@@ -44,6 +44,7 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int)))
|
||||
urlValues.Add("k8ciId", strconv.Itoa(d.Get("k8sci_id").(int)))
|
||||
urlValues.Add("workerGroupName", d.Get("wg_name").(string))
|
||||
|
||||
var masterNode K8sNodeRecord
|
||||
if masters, ok := d.GetOk("masters"); ok {
|
||||
@@ -67,7 +68,6 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
|
||||
urlValues.Add("workerRam", strconv.Itoa(workerNode.Ram))
|
||||
urlValues.Add("workerDisk", strconv.Itoa(workerNode.Disk))
|
||||
|
||||
//TODO find a way to avoid hardcoding these values
|
||||
//if withLB, ok := d.GetOk("with_lb"); ok {
|
||||
//urlValues.Add("withLB", strconv.FormatBool(withLB.(bool)))
|
||||
//}
|
||||
@@ -121,6 +121,14 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
|
||||
|
||||
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
log.Warnf("could not get kubeconfig: %v", err)
|
||||
}
|
||||
d.Set("kubeconfig", kubeconfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -136,10 +144,20 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error {
|
||||
d.Set("name", k8s.Name)
|
||||
d.Set("rg_id", k8s.RgID)
|
||||
d.Set("k8sci_id", k8s.CI)
|
||||
d.Set("wg_name", k8s.Groups.Workers[0].Name)
|
||||
d.Set("masters", nodeToResource(k8s.Groups.Masters))
|
||||
d.Set("workers", nodeToResource(k8s.Groups.Workers[0]))
|
||||
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
log.Warnf("could not get kubeconfig: %v", err)
|
||||
}
|
||||
d.Set("kubeconfig", kubeconfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -147,13 +165,46 @@ func resourceK8sUpdate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceK8sUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
|
||||
_, err := controller.decortAPICall("POST", K8sUpdateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
if d.HasChange("name") {
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
|
||||
_, err := controller.decortAPICall("POST", K8sUpdateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("workers") {
|
||||
k8s, err := utilityK8sCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wg := k8s.Groups.Workers[0]
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
|
||||
|
||||
newWorkers := parseNode(d.Get("workers").([]interface{}))
|
||||
|
||||
if newWorkers.Num > wg.Num {
|
||||
urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num))
|
||||
_, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for i := wg.Num - 1; i >= newWorkers.Num; i-- {
|
||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||
_, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -216,6 +267,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Description: "ID of the k8s catalog item to base this instance on.",
|
||||
},
|
||||
|
||||
"wg_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Name for first worker group created with cluster.",
|
||||
},
|
||||
|
||||
"masters": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
@@ -230,7 +288,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
"workers": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: nodeK8sSubresourceSchemaMake(),
|
||||
@@ -265,6 +322,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "ID of default workers group for this instace.",
|
||||
},
|
||||
|
||||
"kubeconfig": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Kubeconfig for cluster access.",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +345,13 @@ func resourceK8s() *schema.Resource {
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
//TODO timeouts
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout20m,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout20m,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourceK8sSchemaMake(),
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -39,7 +38,7 @@ func resourceK8sWgCreate(d *schema.ResourceData, m interface{}) error {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
urlValues.Add("name", uuid.New().String())
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("workerNum", strconv.Itoa(d.Get("num").(int)))
|
||||
urlValues.Add("workerCpu", strconv.Itoa(d.Get("cpu").(int)))
|
||||
urlValues.Add("workerRam", strconv.Itoa(d.Get("ram").(int)))
|
||||
@@ -51,6 +50,9 @@ func resourceK8sWgCreate(d *schema.ResourceData, m interface{}) error {
|
||||
}
|
||||
|
||||
d.SetId(resp)
|
||||
|
||||
// This code is the supposed flow, but at the time of writing it's not yet implemented by the platfom
|
||||
|
||||
//urlValues = &url.Values{}
|
||||
//urlValues.Add("auditId", strings.Trim(resp, `"`))
|
||||
|
||||
@@ -90,6 +92,7 @@ func resourceK8sWgRead(d *schema.ResourceData, m interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("name", wg.Name)
|
||||
d.Set("num", wg.Num)
|
||||
d.Set("cpu", wg.Cpu)
|
||||
d.Set("ram", wg.Ram)
|
||||
@@ -98,6 +101,41 @@ func resourceK8sWgRead(d *schema.ResourceData, m interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceK8sWgUpdate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceK8sWgUpdate: called with k8s id %d", d.Get("k8s_id").(int))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
|
||||
wg, err := utilityK8sWgCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||
urlValues.Add("workersGroupId", d.Id())
|
||||
|
||||
newNum := d.Get("num").(int)
|
||||
|
||||
if newNum > wg.Num {
|
||||
urlValues.Add("num", strconv.Itoa(newNum-wg.Num))
|
||||
_, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for i := wg.Num - 1; i >= newNum; i-- {
|
||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||
_, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceK8sWgDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int))
|
||||
|
||||
@@ -145,18 +183,16 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
|
||||
Description: "ID of k8s instance.",
|
||||
},
|
||||
|
||||
//Unused but required by creation API. Sending generated UUID each time
|
||||
//"name": {
|
||||
//Type: schema.TypeString,
|
||||
//Required: true,
|
||||
//ForceNew: true,
|
||||
//Description: "Name of the worker group.",
|
||||
//},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Name of the worker group.",
|
||||
},
|
||||
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: 1,
|
||||
Description: "Number of worker nodes to create.",
|
||||
},
|
||||
@@ -193,6 +229,7 @@ func resourceK8sWg() *schema.Resource {
|
||||
|
||||
Create: resourceK8sWgCreate,
|
||||
Read: resourceK8sWgRead,
|
||||
Update: resourceK8sWgUpdate,
|
||||
Delete: resourceK8sWgDelete,
|
||||
Exists: resourceK8sWgExists,
|
||||
|
||||
@@ -200,7 +237,13 @@ func resourceK8sWg() *schema.Resource {
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
//TODO timeouts
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout20m,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout20m,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourceK8sWgSchemaMake(),
|
||||
}
|
||||
|
||||
402
decort/resource_virtual_image.go
Normal file
402
decort/resource_virtual_image.go
Normal file
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceVirtualImageCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("targetId", strconv.Itoa(d.Get("target_id").(int)))
|
||||
|
||||
imageId, err := controller.decortAPICall("POST", imageCreateVirtualAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(imageId)
|
||||
d.Set("image_id", imageId)
|
||||
|
||||
image, err := utilityImageCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(image.ImageId))
|
||||
d.Set("bootable", image.Bootable)
|
||||
//d.Set("image_id", image.ImageId)
|
||||
|
||||
err = resourceImageRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "name of the virtual image to create",
|
||||
},
|
||||
"target_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of real image to link this virtual image to upon creation",
|
||||
},
|
||||
"history": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "URL where to download media from",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "grid (platform) ID where this template should be create in",
|
||||
},
|
||||
"boot_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Boot type of image bios or uefi",
|
||||
},
|
||||
"image_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Image type linux, windows or other",
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"hot_resize": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this machine supports hot resize",
|
||||
},
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional username for the image",
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Optional password for the image",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "AccountId to make the image exclusive",
|
||||
},
|
||||
"username_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "username for upload binary media",
|
||||
},
|
||||
"password_dl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "password for upload binary media",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "pool for image create",
|
||||
},
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image id",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Whether to completely delete the image",
|
||||
},
|
||||
"bootable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Does this image boot OS",
|
||||
},
|
||||
"unc_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "unc path",
|
||||
},
|
||||
"link_to": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "tech atatus",
|
||||
},
|
||||
"version": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "version",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "image size",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"computeci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"provider_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rescuecd": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"last_modified": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled_stacks": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"shared_with": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceVirtualImage() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceVirtualImageCreate,
|
||||
Read: resourceImageRead,
|
||||
Update: resourceImageEdit,
|
||||
Delete: resourceImageDelete,
|
||||
Exists: resourceImageExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
CustomizeDiff: customdiff.All(
|
||||
customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool {
|
||||
if old.(bool) != new.(bool) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeEnabled),
|
||||
customdiff.IfValueChange("link_to", func(old, new, meta interface{}) bool {
|
||||
if old.(int) != new.(int) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageLink),
|
||||
customdiff.IfValueChange("name", func(old, new, meta interface{}) bool {
|
||||
if old.(string) != new.(string) && old.(string) != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageEditName),
|
||||
customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(int) == o[i].(int) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageShare),
|
||||
customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool {
|
||||
if old.(int) != new.(int) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageChangeComputeci),
|
||||
customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool {
|
||||
o := old.([]interface{})
|
||||
n := new.([]interface{})
|
||||
|
||||
if len(o) != len(n) {
|
||||
return true
|
||||
} else if len(o) == 0 {
|
||||
return false
|
||||
}
|
||||
count := 0
|
||||
for i, v := range n {
|
||||
if v.(string) == o[i].(string) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceImageUpdateNodes),
|
||||
),
|
||||
|
||||
Schema: resourceVirtualImageSchemaMake(),
|
||||
}
|
||||
}
|
||||
62
decort/utility_grid.go
Normal file
62
decort/utility_grid.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, error) {
|
||||
grid := &Grid{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if gridId, ok := d.GetOk("grid_id"); ok {
|
||||
urlValues.Add("gridId", strconv.Itoa(gridId.(int)))
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("grid_id is required"))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridCheckPresence: load grid")
|
||||
gridRaw, err := controller.decortAPICall("POST", GridGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(gridRaw), grid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return grid, nil
|
||||
}
|
||||
61
decort/utility_grid_list.go
Normal file
61
decort/utility_grid_list.go
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridList, error) {
|
||||
gridList := GridList{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridListCheckPresence: load grid list")
|
||||
gridListRaw, err := controller.decortAPICall("POST", GridListGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(gridListRaw), &gridList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gridList, nil
|
||||
}
|
||||
62
decort/utility_image.go
Normal file
62
decort/utility_image.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if (strconv.Itoa(d.Get("image_id").(int))) != "0" {
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
} else {
|
||||
urlValues.Add("imageId", d.Id())
|
||||
}
|
||||
|
||||
resp, err := controller.decortAPICall("POST", imageGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
image := &Image{}
|
||||
if err := json.Unmarshal([]byte(resp), image); err != nil {
|
||||
return nil, errors.New(fmt.Sprint("Can not unmarshall data to image: ", resp, " ", image))
|
||||
}
|
||||
|
||||
return image, nil
|
||||
}
|
||||
68
decort/utility_image_list.go
Normal file
68
decort/utility_image_list.go
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (ImageList, error) {
|
||||
imageList := ImageList{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
urlValues.Add("sepId", strconv.Itoa(sepId.(int)))
|
||||
}
|
||||
if sharedWith, ok := d.GetOk("shared_with"); ok {
|
||||
urlValues.Add("sharedWith", strconv.Itoa(sharedWith.(int)))
|
||||
}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||
}
|
||||
|
||||
log.Debugf("utilityImageListCheckPresence: load image list")
|
||||
imageListRaw, err := controller.decortAPICall("POST", imageListGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(imageListRaw), &imageList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageList, nil
|
||||
}
|
||||
56
decort/utility_image_list_stacks.go
Normal file
56
decort/utility_image_list_stacks.go
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||
Technology platfom.
|
||||
|
||||
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||
*/
|
||||
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{}) (ImageListStacks, error) {
|
||||
imageListStacks := ImageListStacks{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||
|
||||
log.Debugf("utilityImageListStacksCheckPresence: load image list")
|
||||
imageListRaw, err := controller.decortAPICall("POST", imageListStacksApi, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(imageListRaw), &imageListStacks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imageListStacks, nil
|
||||
}
|
||||
43
docs/data-sources/grid.md
Normal file
43
docs/data-sources/grid.md
Normal file
@@ -0,0 +1,43 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_grid Data Source - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_grid (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **grid_id** (Number)
|
||||
|
||||
### Optional
|
||||
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **flag** (String)
|
||||
- **gid** (Number)
|
||||
- **guid** (Number)
|
||||
- **id** (Number) The ID of this resource.
|
||||
- **location_code** (String)
|
||||
- **name** (String)
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **default** (String)
|
||||
- **read** (String)
|
||||
|
||||
|
||||
50
docs/data-sources/grid_list.md
Normal file
50
docs/data-sources/grid_list.md
Normal file
@@ -0,0 +1,50 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_grid_list Data Source - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_grid_list (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **page** (Number) page number
|
||||
- **size** (Number) page size
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **items** (List of Object) grid list (see [below for nested schema](#nestedatt--items))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **default** (String)
|
||||
- **read** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--items"></a>
|
||||
### Nested Schema for `items`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **flag** (String)
|
||||
- **gid** (Number)
|
||||
- **guid** (Number)
|
||||
- **id** (Number)
|
||||
- **location_code** (String)
|
||||
- **name** (String)
|
||||
|
||||
|
||||
@@ -17,21 +17,53 @@ description: |-
|
||||
|
||||
### Required
|
||||
|
||||
- **name** (String) Name of the image to locate. This parameter is case sensitive.
|
||||
- **image_id** (Number) image id
|
||||
|
||||
### Optional
|
||||
|
||||
- **account_id** (Number) Optional ID of the account to limit image search to.
|
||||
- **id** (String) The ID of this resource.
|
||||
- **shared_with** (List of Number)
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **arch** (String) Binary architecture of this image.
|
||||
- **pool** (String) Pool where this image is located.
|
||||
- **sep_id** (Number) Storage end-point provider serving this image.
|
||||
- **size** (Number) Size of the image in GB.
|
||||
- **status** (String) Current model status of this image.
|
||||
- **account_id** (Number) AccountId to make the image exclusive
|
||||
- **architecture** (String) binary architecture of this image, one of X86_64 of PPC64_LE
|
||||
- **boot_type** (String) Boot type of image bios or uefi
|
||||
- **bootable** (Boolean) Does this image boot OS
|
||||
- **computeci_id** (Number)
|
||||
- **desc** (String)
|
||||
- **drivers** (List of String) List of types of compute suitable for image. Example: [ "KVM_X86" ]
|
||||
- **enabled** (Boolean)
|
||||
- **gid** (Number) grid (platform) ID where this template should be create in
|
||||
- **guid** (Number)
|
||||
- **history** (List of Object) (see [below for nested schema](#nestedatt--history))
|
||||
- **hot_resize** (Boolean) Does this machine supports hot resize
|
||||
- **image_type** (String) Image type linux, windows or other
|
||||
- **last_modified** (Number)
|
||||
- **link_to** (Number)
|
||||
- **meta** (List of String) meta
|
||||
- **milestones** (Number)
|
||||
- **name** (String) Name of the rescue disk
|
||||
- **password** (String) Optional password for the image
|
||||
- **password_dl** (String) password for upload binary media
|
||||
- **permanently** (Boolean) Whether to completely delete the image
|
||||
- **pool_name** (String) pool for image create
|
||||
- **provider_name** (String)
|
||||
- **purge_attempts** (Number)
|
||||
- **reference_id** (String)
|
||||
- **res_id** (String)
|
||||
- **res_name** (String)
|
||||
- **rescuecd** (Boolean)
|
||||
- **sep_id** (Number) storage endpoint provider ID
|
||||
- **size** (Number) image size
|
||||
- **status** (String) status
|
||||
- **tech_status** (String) tech atatus
|
||||
- **unc_path** (String) unc path
|
||||
- **url** (String) URL where to download media from
|
||||
- **username** (String) Optional username for the image
|
||||
- **username_dl** (String) username for upload binary media
|
||||
- **version** (String) version
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
@@ -42,3 +74,13 @@ Optional:
|
||||
- **read** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--history"></a>
|
||||
### Nested Schema for `history`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **guid** (String)
|
||||
- **id** (Number)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
|
||||
94
docs/data-sources/image_list.md
Normal file
94
docs/data-sources/image_list.md
Normal file
@@ -0,0 +1,94 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_image_list Data Source - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_image_list (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **page** (Number) page number
|
||||
- **sep_id** (Number) filter images by storage endpoint provider ID
|
||||
- **shared_with** (Number) filter images by account ID availability
|
||||
- **size** (Number) page size
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **items** (List of Object) image list (see [below for nested schema](#nestedatt--items))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **default** (String)
|
||||
- **read** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--items"></a>
|
||||
### Nested Schema for `items`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **account_id** (Number)
|
||||
- **architecture** (String)
|
||||
- **boot_type** (String)
|
||||
- **bootable** (Boolean)
|
||||
- **computeci_id** (Number)
|
||||
- **desc** (String)
|
||||
- **drivers** (List of String)
|
||||
- **enabled** (Boolean)
|
||||
- **gid** (Number)
|
||||
- **guid** (Number)
|
||||
- **history** (List of Object) (see [below for nested schema](#nestedobjatt--items--history))
|
||||
- **hot_resize** (Boolean)
|
||||
- **image_id** (Number)
|
||||
- **image_type** (String)
|
||||
- **last_modified** (Number)
|
||||
- **link_to** (Number)
|
||||
- **meta** (List of String)
|
||||
- **milestones** (Number)
|
||||
- **name** (String)
|
||||
- **password** (String)
|
||||
- **password_dl** (String)
|
||||
- **permanently** (Boolean)
|
||||
- **pool_name** (String)
|
||||
- **provider_name** (String)
|
||||
- **purge_attempts** (Number)
|
||||
- **reference_id** (String)
|
||||
- **res_id** (String)
|
||||
- **res_name** (String)
|
||||
- **rescuecd** (Boolean)
|
||||
- **sep_id** (Number)
|
||||
- **shared_with** (List of Number)
|
||||
- **size** (Number)
|
||||
- **status** (String)
|
||||
- **tech_status** (String)
|
||||
- **unc_path** (String)
|
||||
- **url** (String)
|
||||
- **username** (String)
|
||||
- **username_dl** (String)
|
||||
- **version** (String)
|
||||
|
||||
<a id="nestedobjatt--items--history"></a>
|
||||
### Nested Schema for `items.history`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **guid** (String)
|
||||
- **id** (Number)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
63
docs/data-sources/image_list_stacks.md
Normal file
63
docs/data-sources/image_list_stacks.md
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_image_list_stacks Data Source - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_image_list_stacks (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **image_id** (Number) image id
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **page** (Number) page number
|
||||
- **size** (Number) page size
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **items** (List of Object) items of stacks list (see [below for nested schema](#nestedatt--items))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **default** (String)
|
||||
- **read** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--items"></a>
|
||||
### Nested Schema for `items`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **api_key** (String)
|
||||
- **api_url** (String)
|
||||
- **app_id** (String)
|
||||
- **desc** (String)
|
||||
- **drivers** (List of String)
|
||||
- **error** (Number)
|
||||
- **guid** (Number)
|
||||
- **id** (Number)
|
||||
- **images** (List of Number)
|
||||
- **login** (String)
|
||||
- **name** (String)
|
||||
- **passwd** (String)
|
||||
- **reference_id** (String)
|
||||
- **status** (String)
|
||||
- **type** (String)
|
||||
|
||||
|
||||
89
docs/resources/cdrom_image.md
Normal file
89
docs/resources/cdrom_image.md
Normal file
@@ -0,0 +1,89 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_cdrom_image Resource - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_cdrom_image (Resource)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **drivers** (List of String) List of types of compute suitable for image. Example: [ "KVM_X86" ]
|
||||
- **gid** (Number) grid (platform) ID where this template should be create in
|
||||
- **name** (String) Name of the rescue disk
|
||||
- **url** (String) URL where to download ISO from
|
||||
|
||||
### Optional
|
||||
|
||||
- **account_id** (Number) AccountId to make the image exclusive
|
||||
- **architecture** (String) binary architecture of this image, one of X86_64 of PPC64_LE
|
||||
- **bootable** (Boolean) Does this image boot OS
|
||||
- **computeci_id** (Number)
|
||||
- **enabled** (Boolean)
|
||||
- **enabled_stacks** (List of String)
|
||||
- **hot_resize** (Boolean) Does this machine supports hot resize
|
||||
- **id** (String) The ID of this resource.
|
||||
- **password** (String) Optional password for the image
|
||||
- **password_dl** (String) password for upload binary media
|
||||
- **permanently** (Boolean) Whether to completely delete the image
|
||||
- **pool_name** (String) pool for image create
|
||||
- **sep_id** (Number) storage endpoint provider ID
|
||||
- **shared_with** (List of Number)
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
- **username** (String) Optional username for the image
|
||||
- **username_dl** (String) username for upload binary media
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **boot_type** (String) Boot type of image bios or uefi
|
||||
- **desc** (String)
|
||||
- **guid** (Number)
|
||||
- **history** (List of Object) (see [below for nested schema](#nestedatt--history))
|
||||
- **image_id** (Number) image id
|
||||
- **image_type** (String) Image type linux, windows or other
|
||||
- **link_to** (Number)
|
||||
- **meta** (List of String) meta
|
||||
- **milestones** (Number)
|
||||
- **provider_name** (String)
|
||||
- **purge_attempts** (Number)
|
||||
- **reference_id** (String)
|
||||
- **res_id** (String)
|
||||
- **res_name** (String)
|
||||
- **rescuecd** (Boolean)
|
||||
- **size** (Number) image size
|
||||
- **status** (String) status
|
||||
- **tech_status** (String) tech atatus
|
||||
- **unc_path** (String) unc path
|
||||
- **version** (String) version
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--history"></a>
|
||||
### Nested Schema for `history`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **guid** (String)
|
||||
- **id** (Number)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
40
docs/resources/delete_images.md
Normal file
40
docs/resources/delete_images.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_delete_images Resource - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_delete_images (Resource)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **image_ids** (List of Number) images ids for deleting
|
||||
- **reason** (String) reason for deleting the images
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **permanently** (Boolean) whether to completely delete the images
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
92
docs/resources/image.md
Normal file
92
docs/resources/image.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_image Resource - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_image (Resource)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **boot_type** (String) Boot type of image bios or uefi
|
||||
- **drivers** (List of String) List of types of compute suitable for image. Example: [ "KVM_X86" ]
|
||||
- **gid** (Number) grid (platform) ID where this template should be create in
|
||||
- **image_type** (String) Image type linux, windows or other
|
||||
- **name** (String) Name of the rescue disk
|
||||
- **url** (String) URL where to download media from
|
||||
|
||||
### Optional
|
||||
|
||||
- **account_id** (Number) AccountId to make the image exclusive
|
||||
- **architecture** (String) binary architecture of this image, one of X86_64 of PPC64_LE
|
||||
- **bootable** (Boolean) Does this image boot OS
|
||||
- **computeci_id** (Number)
|
||||
- **enabled** (Boolean)
|
||||
- **enabled_stacks** (List of String)
|
||||
- **hot_resize** (Boolean) Does this machine supports hot resize
|
||||
- **id** (String) The ID of this resource.
|
||||
- **image_id** (Number) image id
|
||||
- **password** (String) Optional password for the image
|
||||
- **password_dl** (String) password for upload binary media
|
||||
- **permanently** (Boolean) Whether to completely delete the image
|
||||
- **pool_name** (String) pool for image create
|
||||
- **reason** (String)
|
||||
- **sep_id** (Number) storage endpoint provider ID
|
||||
- **shared_with** (List of Number)
|
||||
- **sync** (Boolean) Create image from a media identified by URL (in synchronous mode)
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
- **username** (String) Optional username for the image
|
||||
- **username_dl** (String) username for upload binary media
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **desc** (String)
|
||||
- **guid** (Number)
|
||||
- **history** (List of Object) (see [below for nested schema](#nestedatt--history))
|
||||
- **last_modified** (Number)
|
||||
- **link_to** (Number)
|
||||
- **meta** (List of String) meta
|
||||
- **milestones** (Number)
|
||||
- **provider_name** (String)
|
||||
- **purge_attempts** (Number)
|
||||
- **reference_id** (String)
|
||||
- **res_id** (String)
|
||||
- **res_name** (String)
|
||||
- **rescuecd** (Boolean)
|
||||
- **size** (Number) image size
|
||||
- **status** (String) status
|
||||
- **tech_status** (String) tech atatus
|
||||
- **unc_path** (String) unc path
|
||||
- **version** (String) version
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--history"></a>
|
||||
### Nested Schema for `history`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **guid** (String)
|
||||
- **id** (Number)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
@@ -20,16 +20,19 @@ description: |-
|
||||
- **k8sci_id** (Number) ID of the k8s catalog item to base this instance on.
|
||||
- **name** (String) Name of the cluster.
|
||||
- **rg_id** (Number) Resource group ID that this instance belongs to.
|
||||
- **wg_name** (String) Name for first worker group created with cluster.
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **masters** (Block List, Max: 1) Master node(s) configuration. (see [below for nested schema](#nestedblock--masters))
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
- **workers** (Block List, Max: 1) Worker node(s) configuration. (see [below for nested schema](#nestedblock--workers))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **default_wg_id** (Number) ID of default workers group for this instace.
|
||||
- **kubeconfig** (String) Kubeconfig for cluster access.
|
||||
|
||||
<a id="nestedblock--masters"></a>
|
||||
### Nested Schema for `masters`
|
||||
@@ -42,6 +45,18 @@ Required:
|
||||
- **ram** (Number) Node RAM in MB.
|
||||
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
<a id="nestedblock--workers"></a>
|
||||
### Nested Schema for `workers`
|
||||
|
||||
@@ -18,6 +18,7 @@ description: |-
|
||||
### Required
|
||||
|
||||
- **k8s_id** (Number) ID of k8s instance.
|
||||
- **name** (String) Name of the worker group.
|
||||
|
||||
### Optional
|
||||
|
||||
@@ -26,5 +27,17 @@ description: |-
|
||||
- **id** (String) The ID of this resource.
|
||||
- **num** (Number) Number of worker nodes to create.
|
||||
- **ram** (Number) Worker node RAM in MB.
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
92
docs/resources/virtual_image.md
Normal file
92
docs/resources/virtual_image.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_virtual_image Resource - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_virtual_image (Resource)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **name** (String) name of the virtual image to create
|
||||
- **target_id** (Number) ID of real image to link this virtual image to upon creation
|
||||
|
||||
### Optional
|
||||
|
||||
- **account_id** (Number) AccountId to make the image exclusive
|
||||
- **architecture** (String) binary architecture of this image, one of X86_64 of PPC64_LE
|
||||
- **bootable** (Boolean) Does this image boot OS
|
||||
- **computeci_id** (Number)
|
||||
- **enabled** (Boolean)
|
||||
- **enabled_stacks** (List of String)
|
||||
- **hot_resize** (Boolean) Does this machine supports hot resize
|
||||
- **id** (String) The ID of this resource.
|
||||
- **link_to** (Number)
|
||||
- **password** (String) Optional password for the image
|
||||
- **password_dl** (String) password for upload binary media
|
||||
- **permanently** (Boolean) Whether to completely delete the image
|
||||
- **pool_name** (String) pool for image create
|
||||
- **reason** (String)
|
||||
- **sep_id** (Number) storage endpoint provider ID
|
||||
- **shared_with** (List of Number)
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
- **username** (String) Optional username for the image
|
||||
- **username_dl** (String) username for upload binary media
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **boot_type** (String) Boot type of image bios or uefi
|
||||
- **desc** (String)
|
||||
- **drivers** (List of String) List of types of compute suitable for image. Example: [ "KVM_X86" ]
|
||||
- **gid** (Number) grid (platform) ID where this template should be create in
|
||||
- **guid** (Number)
|
||||
- **history** (List of Object) (see [below for nested schema](#nestedatt--history))
|
||||
- **image_id** (Number) image id
|
||||
- **image_type** (String) Image type linux, windows or other
|
||||
- **last_modified** (Number)
|
||||
- **meta** (List of String) meta
|
||||
- **milestones** (Number)
|
||||
- **provider_name** (String)
|
||||
- **purge_attempts** (Number)
|
||||
- **reference_id** (String)
|
||||
- **res_id** (String)
|
||||
- **res_name** (String)
|
||||
- **rescuecd** (Boolean)
|
||||
- **size** (Number) image size
|
||||
- **status** (String) status
|
||||
- **tech_status** (String) tech atatus
|
||||
- **unc_path** (String) unc path
|
||||
- **url** (String) URL where to download media from
|
||||
- **version** (String) version
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
<a id="nestedatt--history"></a>
|
||||
### Nested Schema for `history`
|
||||
|
||||
Read-Only:
|
||||
|
||||
- **guid** (String)
|
||||
- **id** (Number)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/hashicorp/terraform-plugin-docs v0.5.1
|
||||
github.com/hashicorp/terraform-plugin-sdk v1.16.0
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
|
||||
3
go.sum
3
go.sum
@@ -169,8 +169,9 @@ github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hf
|
||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
|
||||
29
samples/README.md
Normal file
29
samples/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Примеры применения ресурсов terraform-provider-decort
|
||||
Каждый файл снабжен комментариями, которые кратко описывают возможности и параметры ресурса.
|
||||
Для успешной работы необходим установленный terraform.
|
||||
## Ресурсы в примерах
|
||||
- data:
|
||||
- grid
|
||||
- grid_list
|
||||
- image
|
||||
- image_list
|
||||
- image_list_stacks
|
||||
- resources:
|
||||
- image
|
||||
- virtual_image
|
||||
- cdrom_image
|
||||
- delete_images
|
||||
- k8s
|
||||
- k8s_wg
|
||||
|
||||
## Как пользоваться примерами
|
||||
1. Установить terraform
|
||||
2. Установить terraform-provider-decort с помощью команды `terraform init` (выполняется автоматически), либо вручную.
|
||||
3. Заменить параметр *controller_url* на ваш.
|
||||
4. Заменить параметр *oauth2* на ваш.
|
||||
5. Добавить ключи
|
||||
*DECORT_APP_SECRET* и *DECORT_APP_ID*
|
||||
в качестве переменных окружения, либо
|
||||
можно добавить `app_id` и `app_secret`
|
||||
в блок `provider`,что небезопасно, т.к. данные
|
||||
могут быть похищены при передачи файла.
|
||||
38
samples/data_grid/main.tf
Normal file
38
samples/data_grid/main.tf
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение data source grid по id
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "decort_grid" "image" {
|
||||
#id grid для получения информации
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
grid_id = 1
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_grid.image
|
||||
}
|
||||
45
samples/data_grid_list/main.tf
Normal file
45
samples/data_grid_list/main.tf
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение списка grid
|
||||
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
|
||||
data "decort_grid_list" "gl" {
|
||||
#номер страницы для отображения
|
||||
#опциональный параметр, тип - число
|
||||
#если не задан - выводятся все доступные данные
|
||||
#page = 2
|
||||
|
||||
#размер страницы
|
||||
#опциональный параметр, тип - число
|
||||
#если не задан - выводятся все доступные данные
|
||||
#size = 3
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_grid_list.gl
|
||||
}
|
||||
38
samples/data_image/main.tf
Normal file
38
samples/data_image/main.tf
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение образа по id
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "decort_image" "image" {
|
||||
#id образа
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
image_id = 5912
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_image.image
|
||||
}
|
||||
58
samples/data_image_list/main.tf
Normal file
58
samples/data_image_list/main.tf
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение списка образов
|
||||
*/
|
||||
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "decort_image_list" "il" {
|
||||
#номер страницы для отображения
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - выводятся все доступные данные
|
||||
#page = 2
|
||||
|
||||
#размер страницы
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - выводятся все доступные данные
|
||||
#size = 3
|
||||
|
||||
#фильтрация образов по id хранилища
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - выволятся все доступные элементы
|
||||
#sep_id = 123
|
||||
|
||||
#фильтрация образов по id доступных аккаунтов
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - выволятся все доступные элементы
|
||||
#shared_with = 123
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_image_list.il
|
||||
}
|
||||
49
samples/data_image_list_stacks/main.tf
Normal file
49
samples/data_image_list_stacks/main.tf
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение списка stack по id образа
|
||||
*/
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "decort_image_list_stacks" "im" {
|
||||
#id образа
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
image_id = 6040
|
||||
|
||||
#номер страницы для отображения информации
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - отображается вся доступная информация
|
||||
#page = 2
|
||||
|
||||
#количество отображаемых объектов на странице
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#если не задан - отображается вся доступная информация
|
||||
#size = 3
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_image_list_stacks.im
|
||||
}
|
||||
63
samples/resource_delete_images/main.tf
Normal file
63
samples/resource_delete_images/main.tf
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса delete images
|
||||
Ресурс является служебным
|
||||
Его можно использоваться для быстрого удаления нескольких образов
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
resource "decort_delete_images" "my_images" {
|
||||
#массив, содержащий набор id образов для удаления
|
||||
#обязательный параметр
|
||||
#тип - массив чисел
|
||||
image_ids = [6125]
|
||||
|
||||
#параметр удаления
|
||||
#опциональный тип
|
||||
#по-умолчанию - false
|
||||
#тип - булев тип
|
||||
permanently = true
|
||||
|
||||
#причина удаления
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
reason = "test delete"
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_delete_images.my_images
|
||||
}
|
||||
|
||||
/*
|
||||
Применение:
|
||||
1. terraform plan
|
||||
2. terraform apply
|
||||
3. terraform destroy
|
||||
|
||||
|
||||
Примечание:
|
||||
Данный ресурс не поддерживает обновления параметров, поэтому, для переиспользования
|
||||
необходимо удалить старое состояние и повторить шаги выше.
|
||||
*/
|
||||
145
samples/resource_image/main.tf
Normal file
145
samples/resource_image/main.tf
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса image
|
||||
Ресурс позволяет:
|
||||
1. Создавать образ
|
||||
2. Редактировать образ
|
||||
3. Удалять образ
|
||||
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
resource "decort_image" "my_image" {
|
||||
#имя образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#при изменении - изменяет название созданного образа
|
||||
name = "test_image_rename"
|
||||
|
||||
#адрес образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
url = "https://colba.decs.online/index.php/s/G3H7AREngzeKGw2/download"
|
||||
|
||||
#grid id образа
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
gid = 212
|
||||
|
||||
#тип загрузки образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#возможные варианты: "bios" или "uefi"
|
||||
boot_type = "bios"
|
||||
|
||||
#тип образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#возможные варианты - "linux", "windows"
|
||||
image_type = "linux"
|
||||
|
||||
#драйвера
|
||||
#обязательный параметр
|
||||
#тип - массив строк
|
||||
#возможные варианты - ["KVM_X86", "SVA_KVM_X86"], ["KVM_X86"], ["SVA_KVM_X86"]
|
||||
drivers = ["KVM_X86", "SVA_KVM_X86"]
|
||||
|
||||
#id аккаунта владельца образа
|
||||
#опциональный параметр
|
||||
#может быть использован как при создании,
|
||||
#так и при редактировании образа
|
||||
#тип данных - число
|
||||
#account_id = 57252
|
||||
|
||||
#имя пользователя и пароль
|
||||
#опциаональные параметры,
|
||||
#могут быть использованы как при создании образа,
|
||||
#так и при его редактировании
|
||||
#тип - строка
|
||||
#username = "Valera"
|
||||
#password = "123"
|
||||
|
||||
#имя пользователя и пароль для загрузки бинарных данных
|
||||
#опциаональные параметры,
|
||||
#могут быть использованы как при создании образа,
|
||||
#так и при его редактировании
|
||||
#тип - строка
|
||||
#username_dl = "Valera1"
|
||||
#password_dl = "1231"
|
||||
|
||||
#id storage endpoint
|
||||
#опциональный параметр, используется при создании
|
||||
#тип - число
|
||||
#sep_id = 1206
|
||||
|
||||
#пул для создания образа
|
||||
#опциональный тип, используется при создании образа
|
||||
#тип - строка
|
||||
#pool_name = "vmstor"
|
||||
|
||||
#архитектура системы образа
|
||||
#опциаональный параметр, используется при создании
|
||||
#тип - строка
|
||||
#доступные значения: "X86_64"
|
||||
#architecture = "X86_64"
|
||||
|
||||
#доступность образа
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - булево значение
|
||||
#enabled = true
|
||||
|
||||
#настройка доступа образа аккаунтам
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив чисел
|
||||
#пустой маасив - удаление всех доступов, если они были
|
||||
#shared_with = [28096, 57121]
|
||||
|
||||
#установка computeci
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - число
|
||||
#чтобы сбросить, необходимо передать 0
|
||||
#computeci_id = 1
|
||||
|
||||
#доступные стаки
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив строк
|
||||
#для удаления всех доступных стаков, необходимо передать пустой массив
|
||||
#enabled_stacks = ["9"]
|
||||
|
||||
#мгновенное удаление
|
||||
#опциональный параметр, можно использовать перед удалением
|
||||
#тип - булев тип
|
||||
#permanently = true
|
||||
|
||||
#причина удаления
|
||||
#опциональный параметр, можно использовать перед удалением
|
||||
#тип - строка
|
||||
#reason = "test"
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_image.my_image
|
||||
}
|
||||
127
samples/resource_image_cdrom/main.tf
Normal file
127
samples/resource_image_cdrom/main.tf
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса cdrom image
|
||||
Ресурс позволяет:
|
||||
1. Создавать образ
|
||||
2. Редактировать образ
|
||||
3. Удалять образ
|
||||
|
||||
*/
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
resource "decort_cdrom_image" "my_image" {
|
||||
#имя образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#при изменении - изменяет название созданного образа
|
||||
name = "test_image_rename"
|
||||
|
||||
#адрес образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
url = "https://colba.decs.online/index.php/s/G3H7AREngzeKGw2/download"
|
||||
|
||||
#grid id образа
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
gid = 212
|
||||
|
||||
#драйвера
|
||||
#обязательный параметр
|
||||
#тип - массив строк
|
||||
#возможные варианты - ["KVM_X86", "SVA_KVM_X86"], ["KVM_X86"], ["SVA_KVM_X86"]
|
||||
drivers = ["KVM_X86", "SVA_KVM_X86"]
|
||||
|
||||
#id аккаунта владельца образа
|
||||
#опциональный параметр
|
||||
#может быть использован как при создании,
|
||||
#так и при редактировании образа
|
||||
#тип данных - число
|
||||
account_id = 57252
|
||||
|
||||
#имя пользователя и пароль
|
||||
#опциаональные параметры,
|
||||
#могут быть использованы как при создании образа,
|
||||
#так и при его редактировании
|
||||
#тип - строка
|
||||
username = "Valera"
|
||||
password = "123"
|
||||
|
||||
#имя пользователя и пароль для загрузки бинарных данных
|
||||
#опциаональные параметры,
|
||||
#могут быть использованы как при создании образа,
|
||||
#так и при его редактировании
|
||||
#тип - строка
|
||||
#username_dl = "Valera1"
|
||||
#password_dl = "1231"
|
||||
|
||||
#id storage endpoint
|
||||
#опциональный параметр, используется при создании
|
||||
#тип - число
|
||||
#sep_id = 1206
|
||||
|
||||
#пул для создания образа
|
||||
#опциональный тип, используется при создании образа
|
||||
#тип - строка
|
||||
#pool_name = "vmstor"
|
||||
|
||||
#архитектура системы образа
|
||||
#опциаональный параметр, используется при создании
|
||||
#тип - строка
|
||||
#доступные значения: "X86_64"
|
||||
architecture = "X86_64"
|
||||
|
||||
#доступность образа
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - булево значение
|
||||
#enabled = true
|
||||
|
||||
#настройка доступа образа аккаунтам
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив чисел
|
||||
#пустой маасив - удаление всех доступов, если они были
|
||||
#shared_with = [28096, 57121]
|
||||
|
||||
#установка computeci
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - число
|
||||
#чтобы сбросить, необходимо передать 0
|
||||
#computeci_id = 1
|
||||
|
||||
#доступные стаки
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив строк
|
||||
#для удаления всех доступных стаков, необходимо передать пустой массив
|
||||
#enabled_stacks = ["9"]
|
||||
|
||||
#мгновенное удаление
|
||||
#опциональный параметр, можно использовать перед удалением
|
||||
#тип - булев тип
|
||||
#permanently = true
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_cdrom_image.my_image
|
||||
}
|
||||
122
samples/resource_k8s/main.tf
Normal file
122
samples/resource_k8s/main.tf
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурсов k8s cluster
|
||||
Ресурсы позволяет:
|
||||
1. Создавать
|
||||
2. Редактировать
|
||||
3. Удалять
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
source = "terraform.local/local/decort"
|
||||
version = "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
controller_url = "https://mr4.digitalenergy.online"
|
||||
app_id = ""
|
||||
app_secret = ""
|
||||
}
|
||||
|
||||
|
||||
resource "decort_k8s" "cluster" {
|
||||
#имя кластера
|
||||
#обязательный параметр
|
||||
#при изменении - обновдяет имя кластера
|
||||
#тип - строка
|
||||
name = "tftest"
|
||||
|
||||
#id resource group
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
rg_id = 776
|
||||
|
||||
#id catalogue item
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
k8sci_id = 9
|
||||
|
||||
#имя для первой worker group, созданной в кластере
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
wg_name = "workers"
|
||||
|
||||
#настройка мастер node или nodes
|
||||
#опциональный параметр
|
||||
#максимальное кол-во элементов - 1
|
||||
#тип - список нод
|
||||
masters {
|
||||
#кол-во node
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
num = 1
|
||||
|
||||
#кол-во cpu
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
cpu = 2
|
||||
|
||||
|
||||
#кол-во RAM в Мбайтах
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
ram = 2048
|
||||
|
||||
|
||||
#размер диска в Гбайтах
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
disk = 10
|
||||
}
|
||||
|
||||
#настройка worker node или nodes
|
||||
#опциональный параметр
|
||||
#максимальное кол-во элементов - 1
|
||||
#тип - список нод
|
||||
workers {
|
||||
#кол-во node
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
num = 1
|
||||
|
||||
#кол-во cpu
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
cpu = 2
|
||||
|
||||
#кол-во RAM в Мбайтах
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
ram = 2048
|
||||
|
||||
#размер диска в Гбайтах
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
disk = 10
|
||||
}
|
||||
}
|
||||
|
||||
output "test_cluster" {
|
||||
value = decort_k8s.cluster
|
||||
}
|
||||
|
||||
/*
|
||||
output "kubeconfig"{
|
||||
value = decort_k8s.cluster.kubeconfig
|
||||
}
|
||||
|
||||
*/
|
||||
76
samples/resource_k8s_wg/main.tf
Normal file
76
samples/resource_k8s_wg/main.tf
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурсов worker group
|
||||
Ресурсы позволяет:
|
||||
1. Создавать
|
||||
2. Редактировать
|
||||
3. Удалять
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
source = "terraform.local/local/decort"
|
||||
version = "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
controller_url = "https://mr4.digitalenergy.online"
|
||||
app_id = ""
|
||||
app_secret = ""
|
||||
}
|
||||
|
||||
|
||||
resource "decort_k8s_wg" "wg" {
|
||||
#id экземпляра k8s
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
k8s_id = 1234 //это значение должно быть и результат вызова decort_k8s.cluster.id
|
||||
|
||||
#имя worker group
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
name = "workers-2"
|
||||
|
||||
#количество worker node для создания
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#по - умолчанию - 1
|
||||
num = 2
|
||||
|
||||
#количество cpu для 1 worker node
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#по - умолчанию - 1
|
||||
cpu = 1
|
||||
|
||||
#количество RAM для одной worker node в Мбайтах
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#по-умолчанию - 1024
|
||||
ram = 1024
|
||||
|
||||
#размер загрузочного диска для worker node, в Гбайтах
|
||||
#опциональный параметр
|
||||
#тип - число
|
||||
#по - умолчанию - 0
|
||||
#если установлен параметр 0, то размер диска будет равен размеру образа
|
||||
disk = 10
|
||||
}
|
||||
|
||||
|
||||
output "test_wg" {
|
||||
value = decort_k8s_wg.wg
|
||||
}
|
||||
98
samples/resource_virtual_image/main.tf
Normal file
98
samples/resource_virtual_image/main.tf
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса virtual image
|
||||
Ресурс позволяет:
|
||||
1. Создавать образ
|
||||
2. Редактировать образ
|
||||
3. Удалять образ
|
||||
|
||||
*/
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||
/*
|
||||
terraform {
|
||||
required_providers {
|
||||
decort = {
|
||||
version = "1.1"
|
||||
source = "digitalenergy.online/decort/decort"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
provider "decort" {
|
||||
authenticator = "oauth2"
|
||||
#controller_url = <DECORT_CONTROLLER_URL>
|
||||
controller_url = "https://ds1.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
resource "decort_virtual_image" "my_image" {
|
||||
#имя виртуального образа
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
name = "test_vi_im_new_rename"
|
||||
|
||||
#id образа, на основе котрого будет создан виртуальный
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
target_id = 6125
|
||||
|
||||
#изменение связи виртуального образа
|
||||
#опциональный параметр, используется при редактировании ресурса
|
||||
#тип - число
|
||||
#link_to = 6062
|
||||
|
||||
#id аккаунта владельца образа
|
||||
#опциональный параметр
|
||||
#может быть использован при редактировании образа
|
||||
#тип данных - число
|
||||
#account_id = 57252
|
||||
|
||||
#имя пользователя и пароль
|
||||
#опциаональные параметры,
|
||||
#могут быть использованы при редактировании образа
|
||||
#тип - строка
|
||||
#username = "Valera"
|
||||
#password = "123"
|
||||
|
||||
#доступность образа
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - булево значение
|
||||
#enabled = false
|
||||
|
||||
#настройка доступа образа аккаунтам
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив чисел
|
||||
#пустой маасив - удаление всех доступов, если они были
|
||||
#shared_with = [28096, 57121]
|
||||
|
||||
#установка computeci
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - число
|
||||
#чтобы сбросить, необходимо передать 0
|
||||
#computeci_id = 1
|
||||
|
||||
#доступные стаки
|
||||
#опциональный параметр, используется на уже созданном ресурсе
|
||||
#тип - массив строк
|
||||
#для удаления всех доступных стаков, необходимо передать пустой массив
|
||||
#enabled_stacks = ["9"]
|
||||
|
||||
#мгновенное удаление
|
||||
#опциональный параметр, можно использовать перед удалением
|
||||
#тип - булев тип
|
||||
#permanently = true
|
||||
|
||||
#причина удаления
|
||||
#опциональный параметр, можно использовать перед удалением
|
||||
#тип - строка
|
||||
#reason = "test"
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_virtual_image.my_image
|
||||
}
|
||||
Reference in New Issue
Block a user