Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||
|
||||
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
@@ -0,0 +1,4 @@
|
||||
### New features
|
||||
- snapshot\_list datasource
|
||||
- snapshot resource
|
||||
- k8s: extnet\_id parameter
|
||||
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 \
|
||||
--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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
README.md
15
README.md
@@ -10,12 +10,12 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
|
||||
- Работа с Compute instances,
|
||||
- Работа с disks,
|
||||
- Работа с k8s,
|
||||
- Работа с virtual network segments,
|
||||
- Работа с image,
|
||||
- Работа с reource groups,
|
||||
- Работа с VINS,
|
||||
- Работа с pfw,
|
||||
- Работа с accounts.
|
||||
- Работа с accounts,
|
||||
- Работа с snapshots.
|
||||
|
||||
Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||
|
||||
@@ -65,7 +65,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 +107,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`
|
||||
|
||||
Хорошей работы!
|
||||
|
||||
@@ -9,12 +9,12 @@ 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.
|
||||
|
||||
This provider supports Import operations on pre-existing resources.
|
||||
|
||||
@@ -110,6 +110,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")
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
@@ -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,21 @@ 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
|
||||
|
||||
@@ -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,7 @@ func Provider() *schema.Provider {
|
||||
"decort_virtual_image": resourceVirtualImage(),
|
||||
"decort_cdrom_image": resourceCDROMImage(),
|
||||
"decort_delete_images": resourceDeleteImages(),
|
||||
"decort_snapshot": resourceSnapshot(),
|
||||
},
|
||||
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
@@ -123,6 +124,7 @@ func Provider() *schema.Provider {
|
||||
"decort_grid_list": dataSourceGridList(),
|
||||
"decort_image_list": dataSourceImageList(),
|
||||
"decort_image_list_stacks": dataSourceImageListStacks(),
|
||||
"decort_snapshot_list": dataSourceSnapshotList(),
|
||||
// "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,
|
||||
},
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
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,15 @@
|
||||
- image
|
||||
- image_list
|
||||
- image_list_stacks
|
||||
- snapshot_list
|
||||
- resources:
|
||||
- image
|
||||
- virtual_image
|
||||
- cdrom_image
|
||||
- delete_images
|
||||
- k8s
|
||||
- k8s_wg
|
||||
- snapshot
|
||||
|
||||
## Как пользоваться примерами
|
||||
1. Установить terraform
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
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