Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffbcce9897 | ||
|
|
efe79ee85a | ||
|
|
42c91e1549 | ||
|
|
6bc61fb856 | ||
|
|
dbf61d4da1 | ||
|
|
c5953387ae | ||
|
|
bc6789f755 | ||
|
|
0aee28ed2e | ||
|
|
98c4dfe0af | ||
|
|
0fd620eeff | ||
|
|
2f2fa2a544 | ||
|
|
9af980964a | ||
|
|
c110239225 | ||
|
|
413fb4b82b | ||
|
|
b2e1004dbe | ||
|
|
594c876364 | ||
|
|
8a716edac3 | ||
|
|
cda317f4db | ||
|
|
299d606df0 | ||
|
|
3cd8c2e618 | ||
|
|
efea1af92a | ||
|
|
77d8d2e921 | ||
|
|
f1ec6d776a | ||
|
|
ff64840b13 | ||
|
|
13e6849328 | ||
|
|
964e85c34a | ||
|
|
92d96b13c6 | ||
|
|
94f222fe19 | ||
|
|
a3da44f2ad | ||
|
|
ef7fa62e79 | ||
|
|
4bb75fe0d7 |
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 }}
|
||||
@@ -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
|
||||
|
||||
18
CHANGELOG.md
Normal file
18
CHANGELOG.md
Normal file
@@ -0,0 +1,18 @@
|
||||
### Bug fixes
|
||||
- resgroup recreation if quotas unspecified
|
||||
|
||||
### New datasources
|
||||
- vgpu
|
||||
- pcidevice\_list
|
||||
- pcidevice
|
||||
- sep
|
||||
- sep\_list
|
||||
- sep\_disk\_list
|
||||
- sep\_config
|
||||
- sep\_pool
|
||||
- sep\_consumption
|
||||
|
||||
### New resources
|
||||
- pcidevice
|
||||
- sep
|
||||
- sep\_config
|
||||
50
Jenkinsfile-sast
Normal file
50
Jenkinsfile-sast
Normal file
@@ -0,0 +1,50 @@
|
||||
pipeline {
|
||||
agent {
|
||||
kubernetes {
|
||||
yaml '''
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: alpine
|
||||
image: alpine:3.15
|
||||
command:
|
||||
- sleep
|
||||
- infinity
|
||||
'''
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Dependency check') {
|
||||
environment {
|
||||
DEPCHECKDB = credentials('depcheck-postgres')
|
||||
}
|
||||
steps {
|
||||
container('alpine') {
|
||||
sh 'apk update && apk add openjdk11 java-postgresql-jdbc'
|
||||
dependencyCheck additionalArguments: '-f JSON -f HTML -n --enableExperimental\
|
||||
--dbDriverName org.postgresql.Driver \
|
||||
--dbDriverPath /usr/share/java/postgresql-jdbc.jar \
|
||||
--dbUser $DEPCHECKDB_USR \
|
||||
--dbPassword $DEPCHECKDB_PSW \
|
||||
--connectionString jdbc:postgresql://postgres-postgresql.postgres/depcheck', odcInstallation: 'depcheck'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('SonarQube analysis') {
|
||||
environment {
|
||||
SONARSCANNER_HOME = tool 'sonarscanner'
|
||||
}
|
||||
steps {
|
||||
withSonarQubeEnv('sonarqube') {
|
||||
sh '$SONARSCANNER_HOME/bin/sonar-scanner'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('SonarQube quality gate') {
|
||||
steps {
|
||||
waitForQualityGate webhookSecretId: 'sonar-webhook', abortPipeline: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
README.md
18
README.md
@@ -10,12 +10,15 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
|
||||
- Работа с Compute instances,
|
||||
- Работа с disks,
|
||||
- Работа с k8s,
|
||||
- Работа с virtual network segments,
|
||||
- Работа с image,
|
||||
- Работа с reource groups,
|
||||
- Работа с VINS,
|
||||
- Работа с pfw,
|
||||
- Работа с accounts.
|
||||
- Работа с accounts,
|
||||
- Работа с snapshots,
|
||||
- Работа с pcidevice,
|
||||
- Работа с sep,
|
||||
- Работа с vgpu.
|
||||
|
||||
Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
|
||||
@@ -65,7 +68,7 @@ Linux:
|
||||
```
|
||||
Windows:
|
||||
```powershell
|
||||
%APPDATA%\terraform.d\plugins\${host_name}/${namespace}/${type}/${version}/${target}
|
||||
%APPDATA%\terraform.d\plugins\${host_name}\${namespace}\${type}\${version}\${target}
|
||||
```
|
||||
ВНИМАНИЕ: для ОС Windows `%APP_DATA%` является каталогом, в котором будут помещены будущие файлы terraform.
|
||||
Где:
|
||||
@@ -107,8 +110,11 @@ terraform init
|
||||
Более подробно о сборке провайдера можно найти по ссылке: https://learn.hashicorp.com/tutorials/terraform/provider-use?in=terraform/providers
|
||||
|
||||
## Примеры работы
|
||||
Примеры работы можно найти на:
|
||||
- Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
- В папке `samples`
|
||||
Примеры работы можно найти:
|
||||
- На вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
- В папке `samples`
|
||||
|
||||
Схемы к terraform'у доступны:
|
||||
- В папке `docs`
|
||||
|
||||
Хорошей работы!
|
||||
|
||||
12
README_EN.md
12
README_EN.md
@@ -9,12 +9,15 @@ NOTE: provider rc-1.25 is designed for DECORT API 3.7.x. For older API versions
|
||||
- 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.
|
||||
- Work with accounts,
|
||||
- Work with snapshots,
|
||||
- Work with pcidevice.
|
||||
- Work with sep,
|
||||
- Work with vgpu.
|
||||
|
||||
This provider supports Import operations on pre-existing resources.
|
||||
|
||||
@@ -110,6 +113,9 @@ More details about the provider's building process: https://learn.hashicorp.com/
|
||||
|
||||
## Examples and Samples
|
||||
- Examples: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
- Samples: in repository `samples`
|
||||
- Samples: see in repository `samples`
|
||||
|
||||
Terraform schemas in:
|
||||
- See in repository `docs`
|
||||
|
||||
Good work!
|
||||
|
||||
@@ -27,12 +27,14 @@ package decort
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// "time"
|
||||
|
||||
@@ -378,28 +380,31 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v
|
||||
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt))
|
||||
}
|
||||
|
||||
resp, err := config.cc_client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
for i := 0; i < 5; i++ {
|
||||
resp, err := config.cc_client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Debugf("decortAPICall: %s %s\n %s", method, api_name, body)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
resp.Body.Close()
|
||||
log.Debugf("decortAPICall: %s %s\n %s", method, api_name, body)
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return string(body), nil
|
||||
} else {
|
||||
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q. Respone:\n%s",
|
||||
resp.StatusCode, req.URL, params_str, body)
|
||||
}
|
||||
|
||||
/*
|
||||
if resp.StatusCode == StatusServiceUnavailable {
|
||||
return nil, fmt.Errorf("decortAPICall method called for incompatible authorization mode %q.", config.auth_mode_txt)
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return string(body), nil
|
||||
} else {
|
||||
if resp.StatusCode == http.StatusInternalServerError {
|
||||
log.Warnf("got 500, retrying %d/5", i+1)
|
||||
time.Sleep(time.Second * 5)
|
||||
continue
|
||||
}
|
||||
*/
|
||||
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q. Respone:\n%s",
|
||||
resp.StatusCode, req.URL, params_str, body)
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("number of retries exceeded")
|
||||
}
|
||||
|
||||
128
decort/data_source_pcidevice.go
Normal file
128
decort/data_source_pcidevice.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 (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourcePcideviceRead(d *schema.ResourceData, m interface{}) error {
|
||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("ckey", pcidevice.CKey)
|
||||
d.Set("meta", flattenMeta(pcidevice.Meta))
|
||||
d.Set("compute_id", pcidevice.Computeid)
|
||||
d.Set("description", pcidevice.Description)
|
||||
d.Set("guid", pcidevice.Guid)
|
||||
d.Set("hw_path", pcidevice.HwPath)
|
||||
d.Set("rg_id", pcidevice.RgID)
|
||||
d.Set("name", pcidevice.Name)
|
||||
d.Set("stack_id", pcidevice.StackID)
|
||||
d.Set("status", pcidevice.Status)
|
||||
d.Set("system_name", pcidevice.SystemName)
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("device_id").(int)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourcePcideviceSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"device_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"hw_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"system_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourcePcidevice() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourcePcideviceRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourcePcideviceSchemaMake(),
|
||||
}
|
||||
}
|
||||
152
decort/data_source_pcidevice_list.go
Normal file
152
decort/data_source_pcidevice_list.go
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
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 flattenPcideviceList(pl PcideviceList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range pl {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.CKey,
|
||||
"meta": flattenMeta(item.Meta),
|
||||
"compute_id": item.Computeid,
|
||||
"description": item.Description,
|
||||
"guid": item.Guid,
|
||||
"hw_path": item.HwPath,
|
||||
"device_id": item.ID,
|
||||
"rg_id": item.RgID,
|
||||
"name": item.Name,
|
||||
"stack_id": item.StackID,
|
||||
"status": item.Status,
|
||||
"system_name": item.SystemName,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourcePcideviceListRead(d *schema.ResourceData, m interface{}) error {
|
||||
pcideviceList, err := utilityPcideviceListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("items", flattenPcideviceList(pcideviceList))
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourcePcideviceItem() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"hw_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"device_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"system_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourcePcideviceListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "pcidevice list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourcePcideviceItem(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourcePcideviceList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourcePcideviceListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourcePcideviceListSchemaMake(),
|
||||
}
|
||||
}
|
||||
145
decort/data_source_sep.go
Normal file
145
decort/data_source_sep.go
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceSepRead(d *schema.ResourceData, m interface{}) error {
|
||||
desSep, err := utilitySepCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
d.Set("ckey", desSep.Ckey)
|
||||
d.Set("meta", flattenMeta(desSep.Meta))
|
||||
d.Set("consumed_by", desSep.ConsumedBy)
|
||||
d.Set("desc", desSep.Desc)
|
||||
d.Set("gid", desSep.Gid)
|
||||
d.Set("guid", desSep.Guid)
|
||||
d.Set("sep_id", desSep.Id)
|
||||
d.Set("milestones", desSep.Milestones)
|
||||
d.Set("name", desSep.Name)
|
||||
d.Set("obj_status", desSep.ObjStatus)
|
||||
d.Set("provided_by", desSep.ProvidedBy)
|
||||
d.Set("tech_status", desSep.TechStatus)
|
||||
d.Set("type", desSep.Type)
|
||||
data, _ := json.Marshal(desSep.Config)
|
||||
d.Set("config", string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSepCSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "sep type des id",
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"consumed_by": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"obj_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"provided_by": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSep() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepCSchemaMake(),
|
||||
}
|
||||
}
|
||||
77
decort/data_source_sep_config.go
Normal file
77
decort/data_source_sep_config.go
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceSepConfigRead(d *schema.ResourceData, m interface{}) error {
|
||||
sepConfig, err := utilitySepConfigCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
data, _ := json.Marshal(sepConfig)
|
||||
d.Set("config", string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSepConfigSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "sep config json string",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSepConfig() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepConfigRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepConfigSchemaMake(),
|
||||
}
|
||||
}
|
||||
195
decort/data_source_sep_consumption.go
Normal file
195
decort/data_source_sep_consumption.go
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
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 dataSourceSepConsumptionRead(d *schema.ResourceData, m interface{}) error {
|
||||
sepCons, err := utilitySepConsumptionCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
d.Set("type", sepCons.Type)
|
||||
d.Set("total", flattenSepConsumption(sepCons.Total))
|
||||
d.Set("by_pool", flattenSepConsumptionPools(sepCons.ByPool))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenSepConsumptionPools(mp map[string]SepConsumptionInd) []map[string]interface{} {
|
||||
sh := make([]map[string]interface{}, 0)
|
||||
for k, v := range mp {
|
||||
temp := map[string]interface{}{
|
||||
"name": k,
|
||||
"disk_count": v.DiskCount,
|
||||
"disk_usage": v.DiskUsage,
|
||||
"snapshot_count": v.SnapshotCount,
|
||||
"snapshot_usage": v.SnapshotUsage,
|
||||
"usage": v.Usage,
|
||||
"usage_limit": v.UsageLimit,
|
||||
}
|
||||
sh = append(sh, temp)
|
||||
}
|
||||
return sh
|
||||
}
|
||||
|
||||
func flattenSepConsumption(sc SepConsumptionTotal) []map[string]interface{} {
|
||||
sh := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"capacity_limit": sc.CapacityLimit,
|
||||
"disk_count": sc.DiskCount,
|
||||
"disk_usage": sc.DiskUsage,
|
||||
"snapshot_count": sc.SnapshotCount,
|
||||
"snapshot_usage": sc.SnapshotUsage,
|
||||
"usage": sc.Usage,
|
||||
"usage_limit": sc.UsageLimit,
|
||||
}
|
||||
sh = append(sh, temp)
|
||||
return sh
|
||||
}
|
||||
|
||||
func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "sep id",
|
||||
},
|
||||
"by_pool": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "pool name",
|
||||
},
|
||||
"disk_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "number of disks",
|
||||
},
|
||||
"disk_usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "disk usage",
|
||||
},
|
||||
"snapshot_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "number of snapshots",
|
||||
},
|
||||
"snapshot_usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "snapshot usage",
|
||||
},
|
||||
"usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "usage",
|
||||
},
|
||||
"usage_limit": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "usage limit",
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "consumption divided by pool",
|
||||
},
|
||||
"total": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"capacity_limit": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"disk_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "number of disks",
|
||||
},
|
||||
"disk_usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "disk usage",
|
||||
},
|
||||
"snapshot_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "number of snapshots",
|
||||
},
|
||||
"snapshot_usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "snapshot usage",
|
||||
},
|
||||
"usage": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "usage",
|
||||
},
|
||||
"usage_limit": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "usage limit",
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "total consumption",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "sep type",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSepConsumption() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepConsumptionRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepConsumptionSchemaMake(),
|
||||
}
|
||||
}
|
||||
82
decort/data_source_sep_disk_list.go
Normal file
82
decort/data_source_sep_disk_list.go
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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 dataSourceSepDiskListRead(d *schema.ResourceData, m interface{}) error {
|
||||
sepDiskList, err := utilitySepDiskListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", sepDiskList)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSepDiskListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "pool name",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "sep disk list",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceSepDiskList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepDiskListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepDiskListSchemaMake(),
|
||||
}
|
||||
}
|
||||
180
decort/data_source_sep_list.go
Normal file
180
decort/data_source_sep_list.go
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func flattenSepList(sl SepList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range sl {
|
||||
data, _ := json.Marshal(item.Config)
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.Ckey,
|
||||
"meta": flattenMeta(item.Meta),
|
||||
"consumed_by": item.ConsumedBy,
|
||||
"desc": item.Desc,
|
||||
"gid": item.Gid,
|
||||
"guid": item.Guid,
|
||||
"sep_id": item.Id,
|
||||
"milestones": item.Milestones,
|
||||
"name": item.Name,
|
||||
"obj_status": item.ObjStatus,
|
||||
"provided_by": item.ProvidedBy,
|
||||
"tech_status": item.TechStatus,
|
||||
"type": item.Type,
|
||||
"config": string(data),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceSepListRead(d *schema.ResourceData, m interface{}) error {
|
||||
sepList, err := utilitySepListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenSepList(sepList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSepListSchemaMake() 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: "sep list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceSepShortSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceSepShortSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"consumed_by": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"obj_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"provided_by": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSepList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepListSchemaMake(),
|
||||
}
|
||||
}
|
||||
80
decort/data_source_sep_pool.go
Normal file
80
decort/data_source_sep_pool.go
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceSepPoolRead(d *schema.ResourceData, m interface{}) error {
|
||||
sepPool, err := utilitySepPoolCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
data, _ := json.Marshal(sepPool)
|
||||
d.Set("pool", string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSepPoolSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "storage endpoint provider ID",
|
||||
},
|
||||
"pool_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "pool name",
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSepPool() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSepPoolRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSepPoolSchemaMake(),
|
||||
}
|
||||
}
|
||||
120
decort/data_source_snapshot_list.go
Normal file
120
decort/data_source_snapshot_list.go
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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 flattenSnapshotList(gl SnapshotList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, item := range gl {
|
||||
temp := map[string]interface{}{
|
||||
"label": item.Label,
|
||||
"guid": item.Guid,
|
||||
"disks": item.Disks,
|
||||
"timestamp": item.Timestamp,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceSnapshotListRead(d *schema.ResourceData, m interface{}) error {
|
||||
snapshotList, err := utilitySnapshotListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenSnapshotList(snapshotList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceSnapshotListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "ID of the compute instance to create snapshot for.",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "snapshot list",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceSnapshotSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceSnapshotSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "text label for snapshot. Must be unique among this compute snapshots.",
|
||||
},
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "guid of the snapshot",
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "timestamp",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSnapshotList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceSnapshotListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &Timeout30s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSnapshotListSchemaMake(),
|
||||
}
|
||||
}
|
||||
111
decort/data_source_vgpu.go
Normal file
111
decort/data_source_vgpu.go
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Petr Krutov, <petr.krutov@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 (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceVGPURead(d *schema.ResourceData, m interface{}) error {
|
||||
vgpu, err := utilityVGPUCheckPresence(d, m)
|
||||
if vgpu == nil {
|
||||
d.SetId("")
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(vgpu.ID))
|
||||
d.Set("vgpu_id", vgpu.ID)
|
||||
d.Set("account_id", vgpu.AccountID)
|
||||
d.Set("mode", vgpu.Mode)
|
||||
d.Set("pgpu", vgpu.PgpuID)
|
||||
d.Set("profile_id", vgpu.ProfileID)
|
||||
d.Set("ram", vgpu.RAM)
|
||||
d.Set("status", vgpu.Status)
|
||||
d.Set("type", vgpu.Type)
|
||||
d.Set("vm_id", vgpu.VmID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceVGPUSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"vgpu_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"mode": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"pgpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"profile_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"vm_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceVGPU() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Read: dataSourceVGPURead,
|
||||
|
||||
Schema: dataSourceVGPUSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
var Timeout30s = time.Second * 30
|
||||
var Timeout60s = time.Second * 60
|
||||
var Timeout180s = time.Second * 180
|
||||
var Timeout10m = time.Minute * 10
|
||||
var Timeout20m = time.Minute * 20
|
||||
|
||||
//
|
||||
// structures related to /cloudapi/rg/list API
|
||||
@@ -583,12 +583,16 @@ const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete"
|
||||
|
||||
//K8sNodeRecord represents a worker/master group
|
||||
type K8sNodeRecord struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
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
|
||||
@@ -601,11 +605,27 @@ type K8sRecord struct {
|
||||
Masters K8sNodeRecord `json:"masters"`
|
||||
Workers []K8sNodeRecord `json:"workers"`
|
||||
} `json:"k8sGroups"`
|
||||
LbID int `json:"lbId"`
|
||||
Name string `json:"name"`
|
||||
RgID int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
}
|
||||
|
||||
//LbRecord represents load balancer instance
|
||||
type LbRecord struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RgID int `json:"rgId"`
|
||||
VinsID int `json:"vinsId"`
|
||||
ExtNetID int `json:"extnetId"`
|
||||
PrimaryNode struct {
|
||||
BackendIP string `json:"backendIp"`
|
||||
ComputeID int `json:"computeId"`
|
||||
FrontendIP string `json:"frontendIp"`
|
||||
NetworkID int `json:"networkId"`
|
||||
} `json:"primaryNode"`
|
||||
}
|
||||
|
||||
const K8sCreateAPI = "/restmachine/cloudapi/k8s/create"
|
||||
const K8sGetAPI = "/restmachine/cloudapi/k8s/get"
|
||||
const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update"
|
||||
@@ -614,8 +634,13 @@ 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"
|
||||
|
||||
const LbGetAPI = "/restmachine/cloudapi/lb/get"
|
||||
|
||||
//Blasphemous workaround for parsing Result value
|
||||
type TaskResult int
|
||||
|
||||
@@ -792,3 +817,141 @@ type Grid struct {
|
||||
}
|
||||
|
||||
type GridList []Grid
|
||||
|
||||
/////////////////////
|
||||
/// SNAPSHOT API ///
|
||||
/////////////////////
|
||||
|
||||
const snapshotCreateAPI = "/restmachine/cloudapi/compute/snapshotCreate"
|
||||
const snapshotDeleteAPI = "/restmachine/cloudapi/compute/snapshotDelete"
|
||||
const snapshotRollbackAPI = "/restmachine/cloudapi/compute/snapshotRollback"
|
||||
const snapshotListAPI = "/restmachine/cloudapi/compute/snapshotList"
|
||||
|
||||
type Snapshot struct {
|
||||
Disks []int `json:"disks"`
|
||||
Guid string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapshotList []Snapshot
|
||||
|
||||
////////////////
|
||||
/// VGPU API ///
|
||||
////////////////
|
||||
|
||||
const vgpuListAPI = "/restmachine/cloudbroker/vgpu/list"
|
||||
|
||||
type VGPU struct {
|
||||
AccountID int `json:"accountId"`
|
||||
ID int `json:"id"`
|
||||
Mode string `json:"mode"`
|
||||
PgpuID int `json:"pgpuid"`
|
||||
ProfileID int `json:"profileId"`
|
||||
RAM int `json:"ram"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
VmID int `json:"vmid"`
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// PCIDEVICE //
|
||||
/////////////////////////////
|
||||
|
||||
const pcideviceListAPI = "/restmachine/cloudbroker/pcidevice/list"
|
||||
const pcideviceDisableAPI = "/restmachine/cloudbroker/pcidevice/disable"
|
||||
const pcideviceEnableAPI = "/restmachine/cloudbroker/pcidevice/enable"
|
||||
const pcideviceCreateAPI = "/restmachine/cloudbroker/pcidevice/create"
|
||||
const pcideviceDeleteAPI = "/restmachine/cloudbroker/pcidevice/delete"
|
||||
|
||||
type Pcidevice struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Computeid int `json:"computeId"`
|
||||
Description string `json:"description"`
|
||||
Guid int `json:"guid"`
|
||||
HwPath string `json:"hwPath"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RgID int `json:"rgId"`
|
||||
StackID int `json:"stackId"`
|
||||
Status string `json:"status"`
|
||||
SystemName string `json:"systemName"`
|
||||
}
|
||||
|
||||
type PcideviceList []Pcidevice
|
||||
|
||||
///////////////////
|
||||
///// SEP API /////
|
||||
///////////////////
|
||||
const sepAddConsumerNodesAPI = "/restmachine/cloudbroker/sep/addConsumerNodes"
|
||||
const sepDelConsumerNodesAPI = "/restmachine/cloudbroker/sep/delConsumerNodes"
|
||||
const sepAddProviderNodesAPI = "/restmachine/cloudbroker/sep/addProviderNodes"
|
||||
|
||||
const sepConfigFieldEditAPI = "/restmachine/cloudbroker/sep/configFieldEdit"
|
||||
const sepConfigInsertAPI = "/restmachine/cloudbroker/sep/configInsert"
|
||||
const sepConfigValidateAPI = "/restmachine/cloudbroker/sep/configValidate"
|
||||
|
||||
const sepConsumptionAPI = "/restmachine/cloudbroker/sep/consumption"
|
||||
|
||||
const sepDecommissionAPI = "/restmachine/cloudbroker/sep/decommission"
|
||||
|
||||
const sepEnableAPI = "/restmachine/cloudbroker/sep/enable"
|
||||
const sepDisableAPI = "/restmachine/cloudbroker/sep/disable"
|
||||
|
||||
const sepDiskListAPI = "/restmachine/cloudbroker/sep/diskList"
|
||||
|
||||
const sepGetAPI = "/restmachine/cloudbroker/sep/get"
|
||||
const sepGetConfigAPI = "/restmachine/cloudbroker/sep/getConfig"
|
||||
const sepGetPoolAPI = "/restmachine/cloudbroker/sep/getPool"
|
||||
|
||||
const sepCreateAPI = "/restmachine/cloudbroker/sep/create"
|
||||
const sepDeleteAPI = "/restmachine/cloudbroker/sep/delete"
|
||||
const sepListAPI = "/restmachine/cloudbroker/sep/list"
|
||||
|
||||
const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit"
|
||||
|
||||
///Sep Models
|
||||
type SepConsumptionInd struct {
|
||||
DiskCount int `json:"disk_count"`
|
||||
DiskUsage int `json:"disk_usage"`
|
||||
SnapshotCount int `json:"snapshot_count"`
|
||||
SnapshotUsage int `json:"snapshot_usage"`
|
||||
Usage int `json:"usage"`
|
||||
UsageLimit int `json:"usage_limit"`
|
||||
}
|
||||
|
||||
type SepConsumptionTotal struct {
|
||||
CapacityLimit int `json:"capacity_limit"`
|
||||
SepConsumptionInd
|
||||
}
|
||||
|
||||
type SepConsumption struct {
|
||||
Total SepConsumptionTotal `json:"total"`
|
||||
Type string `json:"type"`
|
||||
ByPool map[string]SepConsumptionInd `json:"byPool"`
|
||||
}
|
||||
|
||||
type SepDiskList []int
|
||||
|
||||
type Sep struct {
|
||||
Ckey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
ConsumedBy []int `json:"consumedBy"`
|
||||
Desc string `json:"desc"`
|
||||
Gid int `json:"gid"`
|
||||
Guid int `json:"guid"`
|
||||
Id int `json:"id"`
|
||||
Milestones int `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
ObjStatus string `json:"objStatus"`
|
||||
ProvidedBy []int `json:"providedBy"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
Config SepConfig `json:"config"`
|
||||
}
|
||||
|
||||
type SepConfig map[string]interface{}
|
||||
|
||||
type SepList []Sep
|
||||
type SepPool map[string]interface{}
|
||||
|
||||
@@ -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.",
|
||||
},
|
||||
|
||||
|
||||
@@ -110,6 +110,10 @@ func Provider() *schema.Provider {
|
||||
"decort_virtual_image": resourceVirtualImage(),
|
||||
"decort_cdrom_image": resourceCDROMImage(),
|
||||
"decort_delete_images": resourceDeleteImages(),
|
||||
"decort_snapshot": resourceSnapshot(),
|
||||
"decort_pcidevice": resourcePcidevice(),
|
||||
"decort_sep": resourceSep(),
|
||||
"decort_sep_config": resourceSepConfig(),
|
||||
},
|
||||
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
@@ -123,6 +127,16 @@ func Provider() *schema.Provider {
|
||||
"decort_grid_list": dataSourceGridList(),
|
||||
"decort_image_list": dataSourceImageList(),
|
||||
"decort_image_list_stacks": dataSourceImageListStacks(),
|
||||
"decort_snapshot_list": dataSourceSnapshotList(),
|
||||
"decort_vgpu": dataSourceVGPU(),
|
||||
"decort_pcidevice": dataSourcePcidevice(),
|
||||
"decort_pcidevice_list": dataSourcePcideviceList(),
|
||||
"decort_sep_list": dataSourceSepList(),
|
||||
"decort_sep": dataSourceSep(),
|
||||
"decort_sep_consumption": dataSourceSepConsumption(),
|
||||
"decort_sep_disk_list": dataSourceSepDiskList(),
|
||||
"decort_sep_config": dataSourceSepConfig(),
|
||||
"decort_sep_pool": dataSourceSepPool(),
|
||||
// "decort_pfw": dataSourcePfw(),
|
||||
},
|
||||
|
||||
|
||||
@@ -73,10 +73,11 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
|
||||
//}
|
||||
urlValues.Add("withLB", strconv.FormatBool(true))
|
||||
|
||||
//if extNet, ok := d.GetOk("extnet_id"); ok {
|
||||
//urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
|
||||
//}
|
||||
urlValues.Add("extnetId", strconv.Itoa(0))
|
||||
if extNet, ok := d.GetOk("extnet_id"); ok {
|
||||
urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
|
||||
} else {
|
||||
urlValues.Add("extnetId", "0")
|
||||
}
|
||||
|
||||
//if desc, ok := d.GetOk("desc"); ok {
|
||||
//urlValues.Add("desc", desc.(string))
|
||||
@@ -121,6 +122,21 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
|
||||
|
||||
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||
|
||||
resp, err = controller.decortAPICall("POST", LbGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var lb LbRecord
|
||||
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("extnet_id", lb.ExtNetID)
|
||||
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
|
||||
@@ -151,6 +167,21 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error {
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||
|
||||
resp, err := controller.decortAPICall("POST", LbGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var lb LbRecord
|
||||
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("extnet_id", lb.ExtNetID)
|
||||
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
|
||||
|
||||
urlValues = &url.Values{}
|
||||
urlValues.Add("k8sId", d.Id())
|
||||
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
@@ -165,13 +196,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
|
||||
@@ -255,7 +319,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
"workers": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: nodeK8sSubresourceSchemaMake(),
|
||||
@@ -271,13 +334,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
//Description: "Create k8s with load balancer if true.",
|
||||
//},
|
||||
|
||||
//"extnet_id": {
|
||||
//Type: schema.TypeInt,
|
||||
//Optional: true,
|
||||
//ForceNew: true,
|
||||
//Default: 0,
|
||||
//Description: "ID of the external network to connect workers to.",
|
||||
//},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
|
||||
},
|
||||
|
||||
//"desc": {
|
||||
//Type: schema.TypeString,
|
||||
@@ -285,6 +348,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
//Description: "Text description of this instance.",
|
||||
//},
|
||||
|
||||
"lb_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "IP address of default load balancer.",
|
||||
},
|
||||
|
||||
"default_wg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -314,9 +383,9 @@ func resourceK8s() *schema.Resource {
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout10m,
|
||||
Create: &Timeout20m,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Update: &Timeout20m,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
@@ -101,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))
|
||||
|
||||
@@ -158,7 +193,6 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: 1,
|
||||
Description: "Number of worker nodes to create.",
|
||||
},
|
||||
@@ -195,6 +229,7 @@ func resourceK8sWg() *schema.Resource {
|
||||
|
||||
Create: resourceK8sWgCreate,
|
||||
Read: resourceK8sWgRead,
|
||||
Update: resourceK8sWgUpdate,
|
||||
Delete: resourceK8sWgDelete,
|
||||
Exists: resourceK8sWgExists,
|
||||
|
||||
@@ -203,8 +238,9 @@ func resourceK8sWg() *schema.Resource {
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout10m,
|
||||
Create: &Timeout20m,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout20m,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
263
decort/resource_pcidevice.go
Normal file
263
decort/resource_pcidevice.go
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
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/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourcePcideviceCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string))
|
||||
|
||||
if deviceId, ok := d.GetOk("device_id"); ok {
|
||||
if exists, err := resourcePcideviceExists(d, m); exists {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId(strconv.Itoa(deviceId.(int)))
|
||||
err = resourcePcideviceRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
return errors.New("provided device id does not exist")
|
||||
}
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("hwPath", d.Get("hw_path").(string))
|
||||
urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int)))
|
||||
urlValues.Add("stackId", strconv.Itoa(d.Get("stack_id").(int)))
|
||||
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
urlValues.Add("description", description.(string))
|
||||
}
|
||||
|
||||
pcideviceId, err := controller.decortAPICall("POST", pcideviceCreateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(pcideviceId)
|
||||
d.Set("device_id", pcideviceId)
|
||||
|
||||
err = resourcePcideviceRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceRead(d *schema.ResourceData, m interface{}) error {
|
||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(pcidevice.ID))
|
||||
d.Set("ckey", pcidevice.CKey)
|
||||
d.Set("meta", flattenMeta(pcidevice.Meta))
|
||||
d.Set("compute_id", pcidevice.Computeid)
|
||||
d.Set("description", pcidevice.Description)
|
||||
d.Set("guid", pcidevice.Guid)
|
||||
d.Set("hw_path", pcidevice.HwPath)
|
||||
d.Set("device_id", pcidevice.ID)
|
||||
d.Set("rg_id", pcidevice.RgID)
|
||||
d.Set("name", pcidevice.Name)
|
||||
d.Set("stack_id", pcidevice.StackID)
|
||||
d.Set("status", pcidevice.Status)
|
||||
d.Set("system_name", pcidevice.SystemName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourcePcideviceDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("deviceId", d.Id())
|
||||
urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool)))
|
||||
|
||||
_, err := controller.decortAPICall("POST", pcideviceDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if pcidevice == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func resourcePcideviceEdit(d *schema.ResourceData, m interface{}) error {
|
||||
if d.HasChange("enable") {
|
||||
state := d.Get("enable").(bool)
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
api := ""
|
||||
|
||||
urlValues.Add("deviceId", strconv.Itoa(d.Get("device_id").(int)))
|
||||
|
||||
if state {
|
||||
api = pcideviceEnableAPI
|
||||
} else {
|
||||
api = pcideviceDisableAPI
|
||||
}
|
||||
|
||||
_, err := c.decortAPICall("POST", api, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := resourcePcideviceRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourcePcideviceSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "description, just for information",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"hw_path": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "PCI address of the device",
|
||||
},
|
||||
"device_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of Device",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Resource GROUP",
|
||||
},
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "stackId",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"system_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"force": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Force delete",
|
||||
},
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Enable pci device",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourcePcidevice() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourcePcideviceCreate,
|
||||
Read: resourcePcideviceRead,
|
||||
Update: resourcePcideviceEdit,
|
||||
Delete: resourcePcideviceDelete,
|
||||
Exists: resourcePcideviceExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourcePcideviceSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p
|
||||
package decort
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
@@ -122,6 +123,19 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error {
|
||||
|
||||
d.SetId(api_resp) // rg/create API returns ID of the newly creted resource group on success
|
||||
// rg.ID, _ = strconv.Atoi(api_resp)
|
||||
if !set_quota {
|
||||
resp, err := utilityResgroupCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rg := ResgroupGetResp{}
|
||||
if err := json.Unmarshal([]byte(resp), &rg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("quota", parseQuota(rg.Quota))
|
||||
}
|
||||
|
||||
// re-read newly created RG to make sure schema contains complete and up to date set of specifications
|
||||
return resourceResgroupRead(d, m)
|
||||
@@ -130,7 +144,7 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error {
|
||||
func resourceResgroupRead(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %s",
|
||||
d.Get("name").(string), d.Get("account_id").(int))
|
||||
|
||||
|
||||
rg_facts, err := utilityResgroupCheckPresence(d, m)
|
||||
if rg_facts == "" {
|
||||
// if empty string is returned from utilityResgroupCheckPresence then there is no
|
||||
@@ -165,9 +179,8 @@ func resourceResgroupUpdate(d *schema.ResourceData, m interface{}) error {
|
||||
if attr_new.(int) != attr_old.(int) {
|
||||
return fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing ext_net_id for existing RG is not allowed", d.Id())
|
||||
}
|
||||
|
||||
|
||||
do_general_update := false // will be true if general RG update is necessary (API rg/update)
|
||||
do_general_update := false // will be true if general RG update is necessary (API rg/update)
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
url_values := &url.Values{}
|
||||
@@ -314,18 +327,18 @@ func resourceResgroup() *schema.Resource {
|
||||
},
|
||||
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ValidateFunc: validation.IntAtLeast(1),
|
||||
Description: "Unique ID of the account, which this resource group belongs to.",
|
||||
Description: "Unique ID of the account, which this resource group belongs to.",
|
||||
},
|
||||
|
||||
"def_net_type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "PRIVATE",
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "PRIVATE",
|
||||
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC", "NONE"}, false),
|
||||
Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.",
|
||||
Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.",
|
||||
},
|
||||
|
||||
"def_net_id": {
|
||||
@@ -354,7 +367,7 @@ func resourceResgroup() *schema.Resource {
|
||||
},
|
||||
|
||||
/* commented out, as in this version of provider we use default Grid ID
|
||||
"grid_id": {
|
||||
"grid_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 0, // if 0 is passed, default Grid ID will be used
|
||||
@@ -367,6 +380,7 @@ func resourceResgroup() *schema.Resource {
|
||||
"quota": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: quotaRgSubresourceSchemaMake(),
|
||||
@@ -387,30 +401,30 @@ func resourceResgroup() *schema.Resource {
|
||||
},
|
||||
|
||||
/*
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Current status of this resource group.",
|
||||
},
|
||||
|
||||
"vins": {
|
||||
Type: schema.TypeList, // this is a list of ints
|
||||
Computed: true,
|
||||
MaxItems: LimitMaxVinsPerResgroup,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Current status of this resource group.",
|
||||
},
|
||||
Description: "List of VINs deployed in this resource group.",
|
||||
},
|
||||
|
||||
"computes": {
|
||||
Type: schema.TypeList, // this is a list of ints
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
"vins": {
|
||||
Type: schema.TypeList, // this is a list of ints
|
||||
Computed: true,
|
||||
MaxItems: LimitMaxVinsPerResgroup,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "List of VINs deployed in this resource group.",
|
||||
},
|
||||
|
||||
"computes": {
|
||||
Type: schema.TypeList, // this is a list of ints
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "List of computes deployed in this resource group.",
|
||||
},
|
||||
Description: "List of computes deployed in this resource group.",
|
||||
},
|
||||
*/
|
||||
},
|
||||
}
|
||||
|
||||
560
decort/resource_sep.go
Normal file
560
decort/resource_sep.go
Normal file
@@ -0,0 +1,560 @@
|
||||
/*
|
||||
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"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceSepCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepCreate: called for sep %s", d.Get("name").(string))
|
||||
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
if exists, err := resourceSepExists(d, m); exists {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId(strconv.Itoa(sepId.(int)))
|
||||
err = resourceSepRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
return errors.New("provided sep id does not exist")
|
||||
}
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("name", d.Get("name").(string))
|
||||
urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int)))
|
||||
urlValues.Add("sep_type", d.Get("type").(string))
|
||||
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
urlValues.Add("description", desc.(string))
|
||||
}
|
||||
if configString, ok := d.GetOk("config"); ok {
|
||||
urlValues.Add("config", configString.(string))
|
||||
}
|
||||
if enable, ok := d.GetOk("enable"); ok {
|
||||
urlValues.Add("enable", strconv.FormatBool(enable.(bool)))
|
||||
}
|
||||
|
||||
tstr := d.Get("consumed_by").([]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("consumer_nids", temp)
|
||||
|
||||
tstr = d.Get("provided_by").([]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("provider_nids", temp)
|
||||
|
||||
sepId, err := controller.decortAPICall("POST", sepCreateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(sepId)
|
||||
d.Set("sep_id", sepId)
|
||||
|
||||
err = resourceSepRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(id.String())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepRead(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
|
||||
sep, err := utilitySepCheckPresence(d, m)
|
||||
if sep == nil {
|
||||
d.SetId("")
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("ckey", sep.Ckey)
|
||||
d.Set("meta", flattenMeta(sep.Meta))
|
||||
d.Set("consumed_by", sep.ConsumedBy)
|
||||
d.Set("desc", sep.Desc)
|
||||
d.Set("gid", sep.Gid)
|
||||
d.Set("guid", sep.Guid)
|
||||
d.Set("sep_id", sep.Id)
|
||||
d.Set("milestones", sep.Milestones)
|
||||
d.Set("name", sep.Name)
|
||||
d.Set("obj_status", sep.ObjStatus)
|
||||
d.Set("provided_by", sep.ProvidedBy)
|
||||
d.Set("tech_status", sep.TechStatus)
|
||||
d.Set("type", sep.Type)
|
||||
data, _ := json.Marshal(sep.Config)
|
||||
d.Set("config", string(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
|
||||
sepDes, err := utilitySepCheckPresence(d, m)
|
||||
if sepDes == nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
|
||||
_, err = controller.decortAPICall("POST", sepDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
log.Debugf("resourceSepExists: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
|
||||
sepDes, err := utilitySepCheckPresence(d, m)
|
||||
if sepDes == nil {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func resourceSepEdit(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepEdit: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
c := m.(*ControllerCfg)
|
||||
|
||||
urlValues := &url.Values{}
|
||||
if d.HasChange("decommission") {
|
||||
decommission := d.Get("decommission").(bool)
|
||||
if decommission {
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("clear_physically", strconv.FormatBool(d.Get("clear_physically").(bool)))
|
||||
_, err := c.decortAPICall("POST", sepDecommissionAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if d.HasChange("upd_capacity_limit") {
|
||||
updCapacityLimit := d.Get("upd_capacity_limit").(bool)
|
||||
if updCapacityLimit {
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
_, err := c.decortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if d.HasChange("config") {
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("config", d.Get("config").(string))
|
||||
_, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if d.HasChange("field_edit") {
|
||||
fieldConfig := d.Get("field_edit").([]interface{})
|
||||
field := fieldConfig[0].(map[string]interface{})
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("field_name", field["field_name"].(string))
|
||||
urlValues.Add("field_value", field["field_value"].(string))
|
||||
urlValues.Add("field_type", field["field_type"].(string))
|
||||
|
||||
_, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
err := resourceSepRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepChangeEnabled(d *schema.ResourceDiff, m interface{}) error {
|
||||
var api string
|
||||
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
if d.Get("enable").(bool) {
|
||||
api = sepEnableAPI
|
||||
} else {
|
||||
api = sepDisableAPI
|
||||
}
|
||||
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 resourceSepUpdateNodes(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceSepUpdateNodes: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
t1, t2 := d.GetChange("consumed_by")
|
||||
d1 := t1.([]interface{})
|
||||
d2 := t2.([]interface{})
|
||||
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
|
||||
consumedIds := make([]interface{}, 0)
|
||||
temp := ""
|
||||
api := ""
|
||||
|
||||
if len(d1) > len(d2) {
|
||||
for _, n := range d2 {
|
||||
if !findElInt(d1, n) {
|
||||
consumedIds = append(consumedIds, n)
|
||||
}
|
||||
}
|
||||
api = sepDelConsumerNodesAPI
|
||||
} else {
|
||||
consumedIds = d.Get("consumed_by").([]interface{})
|
||||
api = sepAddConsumerNodesAPI
|
||||
}
|
||||
|
||||
l := len(consumedIds)
|
||||
for i, consumedId := range consumedIds {
|
||||
s := strconv.Itoa(consumedId.(int))
|
||||
if i != (l - 1) {
|
||||
s += ","
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("consumer_nids", temp)
|
||||
_, err := c.decortAPICall("POST", api, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func findElInt(sl []interface{}, el interface{}) bool {
|
||||
for _, e := range sl {
|
||||
if e.(int) == el.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func resourceSepUpdateProviders(d *schema.ResourceDiff, m interface{}) error {
|
||||
log.Debugf("resourceSepUpdateProviders: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
providerIds := d.Get("provided_by").([]interface{})
|
||||
temp := ""
|
||||
l := len(providerIds)
|
||||
for i, providerId := range providerIds {
|
||||
s := strconv.Itoa(providerId.(int))
|
||||
if i != (l - 1) {
|
||||
s += ","
|
||||
}
|
||||
temp = temp + s
|
||||
}
|
||||
temp = "[" + temp + "]"
|
||||
urlValues.Add("provider_nids", temp)
|
||||
_, err := c.decortAPICall("POST", sepAddProviderNodesAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "sep type des id",
|
||||
},
|
||||
"upd_capacity_limit": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Update SEP capacity limit",
|
||||
},
|
||||
"decommission": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "unlink everything that exists from SEP",
|
||||
},
|
||||
"clear_physically": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "clear disks and images physically",
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "sep config string",
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"consumed_by": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "list of consumer nodes IDs",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Description: "sep description",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "grid (platform) ID",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "SEP name",
|
||||
},
|
||||
"obj_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"provided_by": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "list of provider nodes IDs",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "type of storage",
|
||||
},
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "enable SEP after creation",
|
||||
},
|
||||
"field_edit": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"field_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"field_value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"field_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceSep() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceSepCreate,
|
||||
Read: resourceSepRead,
|
||||
Update: resourceSepEdit,
|
||||
Delete: resourceSepDelete,
|
||||
Exists: resourceSepExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourceSepSchemaMake(),
|
||||
|
||||
CustomizeDiff: customdiff.All(
|
||||
customdiff.IfValueChange("enable", func(old, new, meta interface{}) bool {
|
||||
if old.(bool) != new.(bool) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceSepChangeEnabled),
|
||||
customdiff.IfValueChange("consumed_by", 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
|
||||
}, resourceSepUpdateNodes),
|
||||
customdiff.IfValueChange("provided_by", 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
|
||||
}, resourceSepUpdateProviders),
|
||||
),
|
||||
}
|
||||
}
|
||||
197
decort/resource_sep_config.go
Normal file
197
decort/resource_sep_config.go
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
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"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceSepConfigCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepConfigCreate: called for sep id %d", d.Get("sep_id").(int))
|
||||
|
||||
if _, ok := d.GetOk("sep_id"); ok {
|
||||
if exists, err := resourceSepConfigExists(d, m); exists {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
err = resourceSepConfigRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
return errors.New("provided sep id config does not exist")
|
||||
}
|
||||
|
||||
resourceSepConfigRead(d, m)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepConfigRead(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepConfigRead: called for sep id: %d", d.Get("sep_id").(int))
|
||||
|
||||
sepConfig, err := utilitySepConfigCheckPresence(d, m)
|
||||
if sepConfig == nil {
|
||||
d.SetId("")
|
||||
return err
|
||||
}
|
||||
data, _ := json.Marshal(sepConfig)
|
||||
d.Set("config", string(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepConfigDelete(d *schema.ResourceData, m interface{}) error {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepConfigExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
log.Debugf("resourceSepConfigExists: called for sep id: %d", d.Get("sep_id").(int))
|
||||
|
||||
sepDesConfig, err := utilitySepConfigCheckPresence(d, m)
|
||||
if sepDesConfig == nil {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func resourceSepConfigEdit(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSepConfigEdit: called for sep id: %d", d.Get("sep_id").(int))
|
||||
c := m.(*ControllerCfg)
|
||||
|
||||
urlValues := &url.Values{}
|
||||
if d.HasChange("config") {
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("config", d.Get("config").(string))
|
||||
_, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
urlValues = &url.Values{}
|
||||
if d.HasChange("field_edit") {
|
||||
fieldConfig := d.Get("field_edit").([]interface{})
|
||||
field := fieldConfig[0].(map[string]interface{})
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("field_name", field["field_name"].(string))
|
||||
urlValues.Add("field_value", field["field_value"].(string))
|
||||
urlValues.Add("field_type", field["field_type"].(string))
|
||||
|
||||
_, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := resourceSepConfigRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepConfigSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"field_edit": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"field_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"field_value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"field_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceSepConfig() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceSepConfigCreate,
|
||||
Read: resourceSepConfigRead,
|
||||
Update: resourceSepConfigEdit,
|
||||
Delete: resourceSepConfigDelete,
|
||||
Exists: resourceSepConfigExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
Schema: resourceSepConfigSchemaMake(),
|
||||
}
|
||||
}
|
||||
203
decort/resource_snapshot.go
Normal file
203
decort/resource_snapshot.go
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
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"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceSnapshotCreate(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSnapshotCreate: called for snapshot %s", d.Get("label").(string))
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("label", d.Get("label").(string))
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
|
||||
snapshotId, err := controller.decortAPICall("POST", snapshotCreateAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
snapshotId = strings.ReplaceAll(snapshotId, "\"", "")
|
||||
|
||||
d.SetId(snapshotId)
|
||||
d.Set("guid", snapshotId)
|
||||
|
||||
err = resourceSnapshotRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSnapshotRead(d *schema.ResourceData, m interface{}) error {
|
||||
snapshot, err := utilitySnapshotCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("timestamp", snapshot.Timestamp)
|
||||
d.Set("guid", snapshot.Guid)
|
||||
d.Set("disks", snapshot.Disks)
|
||||
d.Set("label", snapshot.Label)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSnapshotDelete(d *schema.ResourceData, m interface{}) error {
|
||||
log.Debugf("resourceSnapshotDelete: called for %s, id: %s", d.Get("label").(string), d.Id())
|
||||
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
urlValues.Add("label", d.Get("label").(string))
|
||||
|
||||
_, err := controller.decortAPICall("POST", snapshotDeleteAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
snapshot, err := utilitySnapshotCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if snapshot == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func resourceSnapshotEdit(d *schema.ResourceData, m interface{}) error {
|
||||
err := resourceSnapshotRead(d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSnapshotRollback(d *schema.ResourceDiff, m interface{}) error {
|
||||
c := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
urlValues.Add("label", d.Get("label").(string))
|
||||
|
||||
_, err := c.decortAPICall("POST", snapshotRollbackAPI, urlValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSnapshotSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "ID of the compute instance to create snapshot for.",
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "text label for snapshot. Must be unique among this compute snapshots.",
|
||||
},
|
||||
"rollback": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "is rollback the snapshot",
|
||||
},
|
||||
"disks": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "guid of the snapshot",
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "timestamp",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceSnapshot() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Create: resourceSnapshotCreate,
|
||||
Read: resourceSnapshotRead,
|
||||
Update: resourceSnapshotEdit,
|
||||
Delete: resourceSnapshotDelete,
|
||||
Exists: resourceSnapshotExists,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &Timeout60s,
|
||||
Read: &Timeout30s,
|
||||
Update: &Timeout60s,
|
||||
Delete: &Timeout60s,
|
||||
Default: &Timeout60s,
|
||||
},
|
||||
|
||||
CustomizeDiff: customdiff.All(
|
||||
customdiff.IfValueChange("rollback", func(old, new, meta interface{}) bool {
|
||||
o := old.(bool)
|
||||
if o != new.(bool) && o == false {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, resourceSnapshotRollback),
|
||||
),
|
||||
|
||||
Schema: resourceSnapshotSchemaMake(),
|
||||
}
|
||||
}
|
||||
63
decort/utility_pcidevice.go
Normal file
63
decort/utility_pcidevice.go
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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 utilityPcideviceCheckPresence(d *schema.ResourceData, m interface{}) (*Pcidevice, error) {
|
||||
pcideviceList, err := utilityPcideviceListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pcideviceId := 0
|
||||
if (d.Get("device_id").(int)) != 0 {
|
||||
pcideviceId = d.Get("device_id").(int)
|
||||
} else {
|
||||
id, _ := strconv.Atoi(d.Id())
|
||||
pcideviceId = id
|
||||
}
|
||||
pcidevice := &Pcidevice{}
|
||||
|
||||
flag := false
|
||||
|
||||
for _, pd := range pcideviceList {
|
||||
if pd.ID == pcideviceId {
|
||||
pcidevice = &pd
|
||||
flag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !flag {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return pcidevice, nil
|
||||
}
|
||||
50
decort/utility_pcidevice_list.go
Normal file
50
decort/utility_pcidevice_list.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityPcideviceListCheckPresence(d *schema.ResourceData, m interface{}) (PcideviceList, error) {
|
||||
pcideviceList := PcideviceList{}
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
pcideviceListRaw, err := controller.decortAPICall("POST", pcideviceListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(pcideviceListRaw), &pcideviceList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pcideviceList, nil
|
||||
}
|
||||
61
decort/utility_sep.go
Normal file
61
decort/utility_sep.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 utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
sep := &Sep{}
|
||||
|
||||
if d.Get("sep_id").(int) == 0 {
|
||||
urlValues.Add("sep_id", d.Id())
|
||||
} else {
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
}
|
||||
|
||||
log.Debugf("utilitySepCheckPresence: load sep")
|
||||
sepRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepRaw), sep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sep, nil
|
||||
}
|
||||
57
decort/utility_sep_config.go
Normal file
57
decort/utility_sep_config.go
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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 utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
sepConfig := SepConfig{}
|
||||
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
|
||||
log.Debugf("utilitySepConfigCheckPresence: load sep config")
|
||||
sepConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepConfigRaw), &sepConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sepConfig, nil
|
||||
}
|
||||
54
decort/utility_sep_consumption.go
Normal file
54
decort/utility_sep_consumption.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) (*SepConsumption, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
sepCons := &SepConsumption{}
|
||||
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
|
||||
sepConsRaw, err := controller.decortAPICall("POST", sepConsumptionAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepConsRaw), sepCons)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sepCons, nil
|
||||
}
|
||||
61
decort/utility_sep_disk_list.go
Normal file
61
decort/utility_sep_disk_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 utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]int, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
sepDiskList := SepDiskList{}
|
||||
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
urlValues.Add("pool_name", poolName.(string))
|
||||
}
|
||||
|
||||
log.Debugf("utilitySepDiskListCheckPresence: load sep")
|
||||
sepDiskListRaw, err := controller.decortAPICall("POST", sepDiskListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepDiskListRaw), &sepDiskList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sepDiskList, nil
|
||||
}
|
||||
61
decort/utility_sep_list.go
Normal file
61
decort/utility_sep_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 utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) {
|
||||
sepList := SepList{}
|
||||
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("utilitySepListCheckPresence: load image list")
|
||||
sepListRaw, err := controller.decortAPICall("POST", sepListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepListRaw), &sepList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sepList, nil
|
||||
}
|
||||
58
decort/utility_sep_pool.go
Normal file
58
decort/utility_sep_pool.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
|
||||
sepPool := SepPool{}
|
||||
|
||||
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||
urlValues.Add("pool_name", d.Get("pool_name").(string))
|
||||
|
||||
log.Debugf("utilitySepDesPoolCheckPresence: load sep")
|
||||
sepPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(sepPoolRaw), &sepPool)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sepPool, nil
|
||||
}
|
||||
55
decort/utility_snapshot.go
Normal file
55
decort/utility_snapshot.go
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilitySnapshotCheckPresence(d *schema.ResourceData, m interface{}) (*Snapshot, error) {
|
||||
snapShotList, err := utilitySnapshotListCheckPresence(d, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
findId := ""
|
||||
|
||||
if (d.Get("guid").(string)) != "" {
|
||||
findId = d.Get("guid").(string)
|
||||
} else {
|
||||
findId = d.Id()
|
||||
}
|
||||
|
||||
for _, s := range snapShotList {
|
||||
if s.Guid == findId {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("snapshot not found")
|
||||
|
||||
}
|
||||
56
decort/utility_snapshot_list.go
Normal file
56
decort/utility_snapshot_list.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>
|
||||
|
||||
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"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilitySnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (SnapshotList, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
|
||||
resp, err := controller.decortAPICall("POST", snapshotListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
snapshotList := SnapshotList{}
|
||||
if err := json.Unmarshal([]byte(resp), &snapshotList); err != nil {
|
||||
//return nil, errors.New(fmt.Sprint("Can not unmarshall data to snapshotList: ", resp, " ", snapshotList))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return snapshotList, nil
|
||||
}
|
||||
74
decort/utility_vgpu.go
Normal file
74
decort/utility_vgpu.go
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Author: Petr Krutov, <petr.krutov@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"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, error) {
|
||||
controller := m.(*ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
urlValues.Add("size", "50")
|
||||
|
||||
var vgpuId int
|
||||
var err error
|
||||
|
||||
if vId, ok := d.GetOk("vgpu_id"); ok {
|
||||
vgpuId = vId.(int)
|
||||
} else {
|
||||
vgpuId, err = strconv.Atoi(d.Id())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for page := 1; ; page++ {
|
||||
urlValues.Set("page", strconv.Itoa(page))
|
||||
resp, err := controller.decortAPICall("POST", vgpuListAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp == "[]" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var vgpus []VGPU
|
||||
if err := json.Unmarshal([]byte(resp), &vgpus); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, vgpu := range vgpus {
|
||||
if vgpu.ID == vgpuId {
|
||||
return &vgpu, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
docs/data-sources/snapshot_list.md
Normal file
50
docs/data-sources/snapshot_list.md
Normal file
@@ -0,0 +1,50 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_snapshot_list Data Source - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_snapshot_list (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **compute_id** (Number) ID of the compute instance to create snapshot for.
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **items** (List of Object) snapshot 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:
|
||||
|
||||
- **disks** (List of Number)
|
||||
- **guid** (String)
|
||||
- **label** (String)
|
||||
- **timestamp** (Number)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ description: |-
|
||||
|
||||
### Optional
|
||||
|
||||
- **extnet_id** (Number) ID of the external network to connect workers to. If omitted network will be chosen by the platfom.
|
||||
- **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))
|
||||
@@ -33,6 +34,7 @@ description: |-
|
||||
|
||||
- **default_wg_id** (Number) ID of default workers group for this instace.
|
||||
- **kubeconfig** (String) Kubeconfig for cluster access.
|
||||
- **lb_ip** (String) IP address of default load balancer.
|
||||
|
||||
<a id="nestedblock--masters"></a>
|
||||
### Nested Schema for `masters`
|
||||
|
||||
@@ -38,5 +38,6 @@ Optional:
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
|
||||
46
docs/resources/snapshot.md
Normal file
46
docs/resources/snapshot.md
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "decort_snapshot Resource - terraform-provider-decort"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# decort_snapshot (Resource)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- **compute_id** (Number) ID of the compute instance to create snapshot for.
|
||||
- **label** (String) text label for snapshot. Must be unique among this compute snapshots.
|
||||
|
||||
### Optional
|
||||
|
||||
- **id** (String) The ID of this resource.
|
||||
- **rollback** (Boolean) is rollback the snapshot
|
||||
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- **disks** (List of Number)
|
||||
- **guid** (String) guid of the snapshot
|
||||
- **timestamp** (Number) timestamp
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- **create** (String)
|
||||
- **default** (String)
|
||||
- **delete** (String)
|
||||
- **read** (String)
|
||||
- **update** (String)
|
||||
|
||||
|
||||
@@ -8,11 +8,27 @@
|
||||
- image
|
||||
- image_list
|
||||
- image_list_stacks
|
||||
- snapshot_list
|
||||
- pcidevice_list
|
||||
- pcidevice
|
||||
- sep
|
||||
- sep_list
|
||||
- sep_disk_list
|
||||
- sep_config
|
||||
- sep_pool
|
||||
- sep_consumption
|
||||
- vgpu
|
||||
- resources:
|
||||
- image
|
||||
- virtual_image
|
||||
- cdrom_image
|
||||
- delete_images
|
||||
- k8s
|
||||
- k8s_wg
|
||||
- snapshot
|
||||
- pcidevice
|
||||
- sep
|
||||
- sep_config
|
||||
|
||||
## Как пользоваться примерами
|
||||
1. Установить terraform
|
||||
|
||||
39
samples/data_pcidevice/main.tf
Normal file
39
samples/data_pcidevice/main.tf
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение информации об устройстве
|
||||
|
||||
*/
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_pcidevice" "pd" {
|
||||
#id устройства
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
device_id = 85
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_pcidevice.pd
|
||||
}
|
||||
34
samples/data_pcidevice_list/main.tf
Normal file
34
samples/data_pcidevice_list/main.tf
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение информации обо всех доступных устройствах
|
||||
|
||||
*/
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_pcidevice_list" "pdl" {}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_pcidevice_list.pdl.items
|
||||
}
|
||||
42
samples/data_sep/main.tf
Normal file
42
samples/data_sep/main.tf
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение данных sep
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep" "sd" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep.sd
|
||||
}
|
||||
|
||||
output "config" {
|
||||
value = jsondecode(data.decort_sep.sd.config)
|
||||
}
|
||||
41
samples/data_sep_config/main.tf
Normal file
41
samples/data_sep_config/main.tf
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение данных конфигурации sep
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep_config" "sc" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep_config.sc
|
||||
}
|
||||
|
||||
output "config" {
|
||||
value = jsondecode(data.decort_config.sc.config)
|
||||
}
|
||||
37
samples/data_sep_consumption/main.tf
Normal file
37
samples/data_sep_consumption/main.tf
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение общих данных об использовании sep
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep_consumption" "scons" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep_consumption.scons
|
||||
}
|
||||
42
samples/data_sep_disk_list/main.tf
Normal file
42
samples/data_sep_disk_list/main.tf
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение данных об используемых sep дисках
|
||||
*/
|
||||
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep_disk_list" "sdl" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
#sep pool name
|
||||
#необязательный параметр
|
||||
#тип - строка
|
||||
#pool_name = "sep_pool"
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep_disk_list.sdl
|
||||
}
|
||||
40
samples/data_sep_list/main.tf
Normal file
40
samples/data_sep_list/main.tf
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение списка sep
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep_list" "sl" {
|
||||
#страница
|
||||
#необязательный параметр
|
||||
#тип - число
|
||||
#page = 3
|
||||
#размер страницы
|
||||
#необязательный параметр
|
||||
#тип - число
|
||||
#size = 2
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep_list.sl
|
||||
}
|
||||
46
samples/data_sep_pool/main.tf
Normal file
46
samples/data_sep_pool/main.tf
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение данных sep pool
|
||||
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep_pool" "sp" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
#sep pool name
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
pool_name = "sep_pool"
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_sep_pool.sp
|
||||
}
|
||||
|
||||
output "pool" {
|
||||
value = jsondecode(data.decort_sep_pool.sp.pool)
|
||||
}
|
||||
40
samples/data_snapshot_list/main.tf
Normal file
40
samples/data_snapshot_list/main.tf
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение списка snapshot
|
||||
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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://mr4.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
|
||||
data "decort_snapshot_list" "sl" {
|
||||
#обязательный параметр
|
||||
#id вычислительной мощности
|
||||
#тип - число
|
||||
compute_id = 24074
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_snapshot_list.sl
|
||||
}
|
||||
38
samples/data_vgpu/main.tf
Normal file
38
samples/data_vgpu/main.tf
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Пример использования
|
||||
Получение данных vgpu
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_vgpu" "vgpu" {
|
||||
#id vgpu
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
vgpu_id = 1111
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = data.decort_vgpu.vgpu
|
||||
}
|
||||
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
|
||||
}
|
||||
85
samples/resource_pcidevice/main.tf
Normal file
85
samples/resource_pcidevice/main.tf
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса pdidevice
|
||||
Ресурс позволяет:
|
||||
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_pcidevice" "pd" {
|
||||
#имя устройства
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
name = "test_device"
|
||||
|
||||
#путь до устройства
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
hw_path = "0000:01:00.0"
|
||||
|
||||
#описание устройства
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
description = "test desc"
|
||||
|
||||
#id ресурсной группы устройства
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
rg_id = 1111
|
||||
|
||||
#id стака устройства
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
stack_id = 11
|
||||
|
||||
#доступность устройства
|
||||
#опциональный параметр
|
||||
#может использоваться на созданном ресурсе
|
||||
#тип - булево значение
|
||||
#enable = false
|
||||
|
||||
#принудительное удаление устройства
|
||||
#опциональный параметр
|
||||
#используется при удалении ресурса
|
||||
#тип - булево значение
|
||||
#force = true
|
||||
|
||||
|
||||
#id устройства
|
||||
#опциональный параметр
|
||||
#позволяет "восстановить" состояние ресурса терраформа на локальной машине
|
||||
#тип - число
|
||||
#device_id = 86
|
||||
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_pcidevice.pd
|
||||
}
|
||||
124
samples/resource_sep/main.tf
Normal file
124
samples/resource_sep/main.tf
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса sep
|
||||
Ресурс позволяет:
|
||||
1. Создавать sep.
|
||||
2. Редактировать sep.
|
||||
3. Удалять sep.
|
||||
4. Конфигурировать sep.
|
||||
|
||||
*/
|
||||
#Расскомментируйте код ниже,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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_sep" "s" {
|
||||
#grid id
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
gid = 212
|
||||
|
||||
#sep name
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
name = "test sep"
|
||||
|
||||
#тип sep
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#возможные значения - des, dorado, tatlin, hitachi
|
||||
type = "des"
|
||||
|
||||
#описание sep
|
||||
#необязательный параметр, используется при создании ресурса
|
||||
#тип - строка
|
||||
desc = "rrrrr"
|
||||
|
||||
#конфигурация sep
|
||||
#необязательный параметр, мб применен при создании или редактировании sep
|
||||
#представляет собой json-строку
|
||||
#тип - строка
|
||||
#config = file("./config.json")
|
||||
|
||||
#изменение поля в конфигурации
|
||||
#необязательный параметр, мб применен на уже созданном sep
|
||||
#тип - объект
|
||||
#внимание, во избежание конфликтов не использовать с полем config
|
||||
/*
|
||||
field_edit {
|
||||
#имя поля
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
field_name = "edgeuser_password"
|
||||
|
||||
#значение поля
|
||||
#обязательный параметр
|
||||
#тип - json строка
|
||||
field_value = "mosk"
|
||||
|
||||
#тип значения
|
||||
#обязательный параметр
|
||||
#тип - строка, возможные значения: list,dict,int,bool,str
|
||||
field_type = "str"
|
||||
}
|
||||
*/
|
||||
|
||||
#доступность sep
|
||||
#необязательный параметр, мб применен на уже созданном ресурсе
|
||||
#тип - булево значение
|
||||
#enable = false
|
||||
|
||||
#использование нодами
|
||||
#необязательный параметр, используется при редактировании ресурса
|
||||
#тип - массив чисел
|
||||
#consumed_by = []
|
||||
|
||||
#обновление лимита объема
|
||||
#необязательный параметр, применяется на уж созданнном ресурсе
|
||||
#тип - булев тип
|
||||
#upd_capacity_limit = true
|
||||
|
||||
#id provided nodes
|
||||
#необязательный параметр, применяется на уже созданном ресурсе
|
||||
#тип - массив чисел
|
||||
#provided_by = [16, 14, 15]
|
||||
|
||||
#отключение nodes
|
||||
#необязательный параметр, применяется на уже созданном ресурсе
|
||||
#тип - булев тип
|
||||
#используется в связке с clear_physically
|
||||
#decommission = true
|
||||
|
||||
#физическое очищение nodes
|
||||
#необязательный параметр, используется при удалении ресурса
|
||||
#тип - булев тип
|
||||
#clear_physically = false
|
||||
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_sep.s
|
||||
}
|
||||
|
||||
output "config" {
|
||||
value = jsondecode(decort_sep.s.config)
|
||||
|
||||
}
|
||||
73
samples/resource_sep_config/main.tf
Normal file
73
samples/resource_sep_config/main.tf
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурс конфигурации sep
|
||||
Ресурс позволяет:
|
||||
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_sep_config" "sc" {
|
||||
#id sep
|
||||
#обязательный параметр
|
||||
#тип - число
|
||||
sep_id = 1111
|
||||
|
||||
#конфигурация
|
||||
#необязательное поле, используется для изменения конфигурации
|
||||
#тип - json-строка
|
||||
#config = file("./config.json")
|
||||
|
||||
#редактироваие поля
|
||||
#неоябазательный параметр, используется при редактировании ресурса
|
||||
#тип - объект
|
||||
/*
|
||||
field_edit {
|
||||
#имя поля
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
field_name = "edgeuser_password"
|
||||
|
||||
#значение поля
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
field_value = "shshs"
|
||||
|
||||
#тип поля
|
||||
#обязательный параметр
|
||||
#тип - строка
|
||||
#возможные значения - int,bool, str, dict, list
|
||||
field_type = "str"
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
output "sep_config" {
|
||||
value = decort_sep_config.sc
|
||||
}
|
||||
|
||||
output "sep_config_json" {
|
||||
value = jsondecode(decort_sep_config.sc.config)
|
||||
}
|
||||
56
samples/resource_snapshot/main.tf
Normal file
56
samples/resource_snapshot/main.tf
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Пример использования
|
||||
Ресурса snapshot
|
||||
Ресурс позволяет:
|
||||
1. Создавать snapshot
|
||||
2. Удалять snapshot
|
||||
3. Откатывать snapshot
|
||||
|
||||
*/
|
||||
|
||||
#Расскомментируйте этот код,
|
||||
#и внесите необходимые правки в версию и путь,
|
||||
#чтобы работать с установленным вручную (не через 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://mr4.digitalenergy.online"
|
||||
#oauth2_url = <DECORT_SSO_URL>
|
||||
oauth2_url = "https://sso.digitalenergy.online"
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
|
||||
resource "decort_snapshot" "s" {
|
||||
#обязательный параметр
|
||||
#id вычислительной мощности
|
||||
#тип - число
|
||||
compute_id = 24074
|
||||
|
||||
#обязательный параметр
|
||||
#наименование snapshot
|
||||
#тип - строка
|
||||
label = "test_ssht_3"
|
||||
|
||||
#опциональный параметр
|
||||
#флаг отката
|
||||
#тип - булев тип
|
||||
#по-уолчанию - false
|
||||
#если флаг был измеен с false на true, то произойдет откат
|
||||
#rollback = false
|
||||
}
|
||||
|
||||
output "test" {
|
||||
value = decort_snapshot.s
|
||||
}
|
||||
7
sonar-project.properties
Normal file
7
sonar-project.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
sonar.projectKey=terraform-provider-decort-sast
|
||||
sonar.dependencyCheck.jsonReportPath=dependency-check-report.json
|
||||
sonar.dependencyCheck.htmlReportPath=dependency-check-report.html
|
||||
|
||||
sonar.exclusions=dependency-check-report.*
|
||||
|
||||
sonar.language=go
|
||||
Reference in New Issue
Block a user