From 272e3853184e4545e873ce0d9349327590304788 Mon Sep 17 00:00:00 2001 From: Tim Tkachev Date: Wed, 26 Jul 2023 13:32:39 +0300 Subject: [PATCH] 4.3.0 --- .gitignore | 2 +- CHANGELOG.md | 55 +- Makefile | 34 +- README.md | 177 +++--- go.mod | 15 +- go.sum | 39 +- internal/controller/controller.go | 81 --- internal/location/location.go | 6 +- internal/provider/data_sources_map.go | 5 + internal/provider/resource_map.go | 2 + .../cloudapi/account/data_source_account.go | 15 +- .../data_source_account_computes_list.go | 59 +- .../data_source_account_deleted_list.go | 9 +- .../account/data_source_account_disks_list.go | 39 +- .../data_source_account_flipgroups_list.go | 49 +- .../account/data_source_account_list.go | 29 +- .../account/data_source_account_rg_list.go | 44 +- .../data_source_account_templates_list.go | 8 +- .../account/data_source_account_vins_list.go | 39 +- internal/service/cloudapi/account/flattens.go | 20 +- .../cloudapi/account/resource_account.go | 139 +---- .../account/utility_account_computes_list.go | 42 +- .../account/utility_account_deleted_list.go | 26 +- .../account/utility_account_disks_list.go | 26 +- .../account/utility_account_flip_groups.go | 34 +- .../cloudapi/account/utility_account_list.go | 28 +- .../account/utility_account_rg_list.go | 30 +- .../account/utility_account_templates_list.go | 6 +- .../account/utility_account_vins_list.go | 26 +- .../data_source_bservice_deleted_list.go | 16 +- .../bservice/data_source_bservice_list.go | 39 +- .../bservice/resource_check_input_values.go | 2 +- .../utility_bservicce_deleted_list.go | 4 +- .../bservice/utility_bservice_list.go | 26 +- .../cloudapi/disks/data_source_disk_list.go | 35 ++ .../data_source_disk_list_types_detailed.go | 5 +- .../disks/data_source_disk_list_unattached.go | 41 +- .../disks/data_source_list_deleted.go | 419 +++++++++++++- internal/service/cloudapi/disks/flattens.go | 8 +- .../disks/resource_check_input_values.go | 4 +- .../cloudapi/disks/utility_disk_list.go | 20 +- .../disks/utility_disk_list_deleted.go | 92 +++ .../disks/utility_disk_list_unattached.go | 21 +- .../disks/utility_disk_types_detailed_list.go | 2 +- .../cloudapi/disks/utility_disk_types_list.go | 2 +- .../extnet/data_source_extnet_list.go | 36 +- internal/service/cloudapi/extnet/flattens.go | 10 +- .../extnet/utility_extnet_computes_list.go | 2 +- .../cloudapi/extnet/utility_extnet_list.go | 20 +- .../flipgroup/data_source_flipgroup.go | 45 +- .../flipgroup/data_source_flipgroup_list.go | 85 +-- .../service/cloudapi/flipgroup/flattens.go | 28 +- .../cloudapi/flipgroup/resource_flipgroup.go | 45 +- .../cloudapi/flipgroup/utility_flipgroup.go | 34 +- .../cloudapi/image/data_source_image_list.go | 64 ++- internal/service/cloudapi/image/flattens.go | 4 +- .../image/resource_check_input_values.go | 4 +- .../cloudapi/image/utility_image_list.go | 50 +- .../cloudapi/k8s/data_source_k8ci_list.go | 175 ++++++ .../service/cloudapi/k8s/data_source_k8s.go | 3 +- .../cloudapi/k8s/data_source_k8s_list.go | 44 ++ internal/service/cloudapi/k8s/flattens.go | 32 +- .../k8s/resource_check_input_values.go | 8 +- internal/service/cloudapi/k8s/resource_k8s.go | 22 +- .../service/cloudapi/k8s/resource_k8s_cp.go | 16 +- internal/service/cloudapi/k8s/utility_k8ci.go | 83 +++ internal/service/cloudapi/k8s/utility_k8s.go | 68 ++- .../cloudapi/kvmvm/data_source_compute.go | 26 +- .../kvmvm/data_source_compute_list.go | 55 ++ internal/service/cloudapi/kvmvm/flattens.go | 35 +- .../kvmvm/resource_check_input_values.go | 12 +- .../cloudapi/kvmvm/resource_compute.go | 129 +++-- .../service/cloudapi/kvmvm/utility_compute.go | 4 +- .../cloudapi/kvmvm/utility_compute_list.go | 32 +- .../kvmvm/utility_compute_pfw_list.go | 2 +- .../kvmvm/utility_compute_user_list.go | 6 +- .../cloudapi/lb/data_source_lb_list.go | 1 + .../lb/data_source_lb_list_deleted.go | 1 + internal/service/cloudapi/lb/flattens.go | 6 +- .../cloudapi/lb/lb_data_subresource.go | 83 +++ .../lb/resource_check_input_values.go | 8 +- .../cloudapi/lb/resource_lb_backend.go | 2 - .../cloudapi/lb/resource_lb_frontend.go | 3 - .../service/cloudapi/lb/utility_lb_list.go | 34 +- .../cloudapi/lb/utility_lb_list_deleted.go | 30 +- .../locations/data_source_locations_list.go | 29 +- .../locations/utility_locations_list.go | 19 +- internal/service/cloudapi/pfw/utility_pfw.go | 2 +- .../service/cloudapi/rg/data_source_rg.go | 14 +- .../cloudapi/rg/data_source_rg_list.go | 45 ++ .../rg/data_source_rg_list_computes.go | 56 +- .../rg/data_source_rg_list_deleted.go | 41 +- .../cloudapi/rg/data_source_rg_list_lb.go | 52 +- .../cloudapi/rg/data_source_rg_list_pfw.go | 7 +- .../cloudapi/rg/data_source_rg_list_vins.go | 36 +- internal/service/cloudapi/rg/flattens.go | 43 +- .../rg/resource_check_input_values.go | 6 +- internal/service/cloudapi/rg/resource_rg.go | 14 +- .../rg/utility_rg_affinity_group_computes.go | 2 +- .../rg/utility_rg_affinity_groups_list.go | 2 +- .../service/cloudapi/rg/utility_rg_list.go | 26 +- .../cloudapi/rg/utility_rg_list_computes.go | 42 +- .../cloudapi/rg/utility_rg_list_deleted.go | 30 +- .../service/cloudapi/rg/utility_rg_list_lb.go | 38 +- .../cloudapi/rg/utility_rg_list_pfw.go | 2 +- .../cloudapi/rg/utility_rg_list_vins.go | 26 +- .../service/cloudapi/snapshot/flattens.go | 4 +- .../cloudapi/snapshot/utility_snapshot.go | 2 +- .../snapshot/utility_snapshot_list.go | 2 +- .../cloudapi/vins/data_source_vins_audits.go | 1 + .../vins/data_source_vins_ext_net_list.go | 1 + .../cloudapi/vins/data_source_vins_ip_list.go | 1 + .../cloudapi/vins/data_source_vins_list.go | 32 +- .../vins/data_source_vins_list_deleted.go | 30 + internal/service/cloudapi/vins/flattens.go | 20 +- .../vins/resource_check_input_values.go | 8 +- .../vins/utility_vins_ext_net_list.go | 2 +- .../cloudapi/vins/utility_vins_ip_list.go | 2 +- .../cloudapi/vins/utility_vins_list.go | 22 +- .../vins/utility_vins_list_deleted.go | 22 +- .../vins/utility_vins_nat_rule_list.go | 2 +- .../data_source_account_deleted_list.go | 2 +- .../service/cloudbroker/account/flattens.go | 72 ++- .../account/utility_account_computes_list.go | 2 +- .../account/utility_account_deleted_list.go | 2 +- .../account/utility_account_disks_list.go | 2 +- .../account/utility_account_flip_groups.go | 2 +- .../account/utility_account_list.go | 2 +- .../account/utility_account_rg_list.go | 2 +- .../account/utility_account_vins_list.go | 2 +- .../service/cloudbroker/disks/flattens.go | 4 +- .../cloudbroker/disks/utility_disk_list.go | 2 +- .../cloudbroker/extnet/data_source_extnet.go | 296 ++++++++++ .../extnet/data_source_extnet_default.go | 80 +++ .../extnet/data_source_extnet_list.go | 255 ++++++++ .../service/cloudbroker/extnet/flattens.go | 161 ++++++ .../cloudbroker/extnet/resource_extnet.go | 542 ++++++++++++++++++ .../cloudbroker/extnet/utility_extnet.go | 288 ++++++++++ internal/service/cloudbroker/grid/flattens.go | 4 +- .../cloudbroker/grid/utility_grid_list.go | 2 +- .../image/data_source_image_list.go | 5 - .../service/cloudbroker/image/flattens.go | 8 +- .../cloudbroker/image/utility_image_list.go | 5 +- .../image/utility_image_list_stacks.go | 2 +- .../cloudbroker/kvmvm/resource_compute.go | 2 - .../cloudbroker/kvmvm/utility_compute.go | 4 +- .../pcidevice/data_source_pcidevice_list.go | 4 +- .../pcidevice/utility_pcidevice.go | 2 +- .../pcidevice/utility_pcidevice_list.go | 6 +- .../cloudbroker/rg/data_source_rg_list.go | 4 +- internal/service/cloudbroker/rg/utility_rg.go | 4 +- .../service/cloudbroker/rg/utility_rg_list.go | 2 +- .../cloudbroker/sep/data_source_sep_list.go | 4 +- .../cloudbroker/sep/utility_sep_list.go | 2 +- .../service/cloudbroker/vgpu/utility_vgpu.go | 2 +- .../cloudbroker/vins/data_source_vins_list.go | 4 +- .../cloudbroker/vins/utility_vins_list.go | 2 +- internal/status/status.go | 2 + samples/cloudapi/data_k8ci_list/main.tf | 77 +++ .../cloudapi/resource_kvmvm/initconfig.tftpl | 14 + samples/cloudapi/resource_kvmvm/main.tf | 10 +- samples/cloudbroker/data_extnet/main.tf | 38 ++ .../cloudbroker/data_extnet_default/main.tf | 35 ++ samples/cloudbroker/data_extnet_list/main.tf | 43 ++ samples/cloudbroker/resource_extnet/main.tf | 68 +++ scripts/install.bat | 87 +++ scripts/install.sh | 68 +++ 167 files changed, 5190 insertions(+), 886 deletions(-) create mode 100644 internal/service/cloudapi/disks/utility_disk_list_deleted.go create mode 100644 internal/service/cloudapi/k8s/data_source_k8ci_list.go create mode 100644 internal/service/cloudapi/k8s/utility_k8ci.go create mode 100644 internal/service/cloudbroker/extnet/data_source_extnet.go create mode 100644 internal/service/cloudbroker/extnet/data_source_extnet_default.go create mode 100644 internal/service/cloudbroker/extnet/data_source_extnet_list.go create mode 100644 internal/service/cloudbroker/extnet/flattens.go create mode 100644 internal/service/cloudbroker/extnet/resource_extnet.go create mode 100644 internal/service/cloudbroker/extnet/utility_extnet.go create mode 100644 samples/cloudapi/data_k8ci_list/main.tf create mode 100644 samples/cloudapi/resource_kvmvm/initconfig.tftpl create mode 100644 samples/cloudbroker/data_extnet/main.tf create mode 100644 samples/cloudbroker/data_extnet_default/main.tf create mode 100644 samples/cloudbroker/data_extnet_list/main.tf create mode 100644 samples/cloudbroker/resource_extnet/main.tf create mode 100644 scripts/install.bat create mode 100755 scripts/install.sh diff --git a/.gitignore b/.gitignore index 6e92c2a..37fbf2b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ decort/vendor/ examples/ url_scrapping/ terraform-provider-decort* -.vscode/ \ No newline at end of file +.vscode/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 78ff476..db12000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,51 @@ -## Version 4.2.4 +## Version 4.3.0 -## Bug Fixes -- Fixed incorrect network validation in decort_kvmvm resource -- Fixed inability to remove all networks at once in decort_kvmvm resource -- Deleted "check__ips" (duplicate) field in decort_extnet data source +## Features +- CloudBroker (requires admin privileges): + - Created "decort_cb_extnet" resource - used to create and manage Extnet instances + - Created "decort_cb_extnet" data source - used to read information about Extnet instance + - Created "decort_cb_extnet_list" data source - used to read information about multiple Extnet instances +- CloudAPI: + - Updated resource_compute: added "custom_fields" and "with_default_vins" parameters: + - Set "with_default_vins" to false to create compute without any attached networks. This parameter is ignored if any network block is specified + - Added ability to create stateless computes (SVA_KVM_X86) + - Created "decort_k8ci_list" data source - used to read information about available K8CI instances + - Updated resources && data sources to platform version 3.8.7, which includes: + - Added new optional fields to all list data sources, used to filter results, which are: + - decort_account_list + - decort_bservice_list + - decort_kvmvm_list + - decort_disk_list + - decort_extnet_list + - decort_flipgroup_list + - decort_image_list + - decort_k8s_list + - decort_k8s_list_deleted + - decort_rg_list + - decort_vins_list + - decort_account_deleted_list + - decort_account_computes_list + - decort_account_disks_list + - decort_account_flipgroups_list + - decort_account_rg_list + - decort_account_vins_list + - decort_disk_list_deleted + - decort_disk_list_unattached + - decort_lb_list + - decort_lb_list_deleted + - decort_rg_list_computes + - decort_rg_list_deleted + - decort_rg_list_lb + - decort_rg_list_pfw + - decort_rg_list_vins + - decort_vins_list_deleted + - Added "cu_dm" field to resgroup and account resource limits and consumed units + - Added "reference_id" field to compute snapshots model + - Added "stateless_sep_id" and "stateless_sep_type" fields to compute models +- Misc: + - Added darwin_arm64, linux_arm64 as release build targets + - Every release starting from version 4.3.0 will have installers included in the archive + - install.sh - used on linux, darwin and bsd systems + - install.bat - used on windows machines + - Updated samples + - Updated README diff --git a/Makefile b/Makefile index 60b9c5a..93fac6c 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,31 @@ TEST?=$$(go list ./... | grep -v 'vendor') -HOSTNAME=digitalenergy.online +HOSTNAME=basis NAMESPACE=decort NAME=terraform-provider-decort BINDIR = ./bin ZIPDIR = ./zip -#BINARY=terraform-provider-${NAME} -BINARY=${NAME}.exe +BINARY=${NAME} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} MAINPATH = ./cmd/decort/ -VERSION=4.2.4 +VERSION=4.3.0 #OS_ARCH=darwin_amd64 -OS_ARCH=windows_amd64 -#OS_ARCH=linux_amd64 +# OS_ARCH=windows_amd64 +OS_ARCH=linux_amd64 -FILES= ${BINARY}_${VERSION}_darwin_amd64\ +FILES = ${BINARY}_${VERSION}_darwin_amd64\ + ${BINARY}_${VERSION}_darwin_arm64\ ${BINARY}_${VERSION}_freebsd_386\ ${BINARY}_${VERSION}_freebsd_amd64\ ${BINARY}_${VERSION}_freebsd_arm\ ${BINARY}_${VERSION}_linux_386\ ${BINARY}_${VERSION}_linux_amd64\ ${BINARY}_${VERSION}_linux_arm\ + ${BINARY}_${VERSION}_linux_arm64\ ${BINARY}_${VERSION}_openbsd_386\ ${BINARY}_${VERSION}_openbsd_amd64\ ${BINARY}_${VERSION}_solaris_amd64\ - ${BINARY}_${VERSION}_windows_386 \ - ${BINARY}_${VERSION}_windows_amd64\ + ${BINARY}_${VERSION}_windows_386.exe\ + ${BINARY}_${VERSION}_windows_amd64.exe\ BINS = $(addprefix bin/, $(FILES)) @@ -50,6 +51,7 @@ release: $(FILES) $(FILES) : $(BINDIR) $(ZIPDIR) $(BINS) zip -r $(ZIPDIR)/$@.zip $(BINDIR)/$@ + zip -rj $(ZIPDIR)/$@.zip scripts/install.bat scripts/install.sh $(BINDIR): mkdir $@ @@ -59,25 +61,27 @@ $(ZIPDIR): $(BINS): GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64 $(MAINPATH) + GOOS=darwin GOARCH=arm64 go build -o ./bin/${BINARY}_${VERSION}_darwin_arm64 $(MAINPATH) GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386 $(MAINPATH) GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64 $(MAINPATH) GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm $(MAINPATH) GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386 $(MAINPATH) GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64 $(MAINPATH) GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm $(MAINPATH) + GOOS=linux GOARCH=arm64 go build -o ./bin/${BINARY}_${VERSION}_linux_arm64 ${MAINPATH} GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386 $(MAINPATH) GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64 $(MAINPATH) GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64 $(MAINPATH) - GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386 $(MAINPATH) - GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64 $(MAINPATH) + GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386.exe $(MAINPATH) + GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64.exe $(MAINPATH) install: build mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH} -test: - go test -i $(TEST) || exit 1 - echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 +test: + go test -i $(TEST) || exit 1 + echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 -testacc: +testacc: TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m diff --git a/README.md b/README.md index 735eee8..6ca4017 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Terraform provider для платформы Digital Energy Cloud Orchestration | Версия DECORT API | Версия провайдера Terraform | | ------ | ------ | +| 3.8.7 | 4.3.x | | 3.8.6 | 4.x.x | | 3.8.5 | 3.4.x | | 3.8.0 - 3.8.4 | 3.3.1 | @@ -33,9 +34,6 @@ Terraform provider для платформы Digital Energy Cloud Orchestration - Работа с pfw, - Работа с accounts, - Работа с snapshots, -- Работа с pcidevice, -- Работа с sep, -- Работа с vgpu, - Работа с bservice, - Работа с extnets, - Работа с locations, @@ -43,99 +41,125 @@ Terraform provider для платформы Digital Energy Cloud Orchestration Вики проекта: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -## Начало - -Старт возможен по двум путям: - -1. Установка через собранные пакеты. -2. Ручная установка. - -### Установка через собранные пакеты. - -1. Скачайте и установите terraform по ссылке: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started -2. Создайте файл `main.tf` и добавьте в него следующий блок. +## Установка +Начиная с версии провайдера `4.3.0` в релизном архиве находятся скрипты-инсталляторы. +Чтобы выполнить установку, необходимо: +1. Перейти по адресу: https://repository.basistech.ru/BASIS/terraform-provider-decort/releases +2. Выбрать необходимую версию провайдера подходящую под операционную систему. +3. Скачать архив. +4. Распаковать архив. +5. Выполнить скрипт установщика, `install.sh` или `install.bat` для Windows.
+*Для запуска `install.sh` не забудьте изменить права доступа к файлу* +```bash +chmod u+x install.sh +``` +6. Дождаться сообщения об успешной установке. Установщик выведет актуальный блок конфигурации провайдера, скопируйте его +```bash +DECORT provider version 4.3.0 has been successfully installed +Copy this provider configuration to main.tf file: +terraform { + required_providers { + decort = { + version = "4.3.0" + source = "basis/decort/decort" + } + } +} +``` +7. После этого, создайте файл `main.tf` в рабочей директории, которая может находится в любом удобном для пользователя месте. +В данном примере, рабочая директория с файлом main.tf находится по пути: +```bash +~/work/tfdir/main.tf +``` +8. Вставьте в `main.tf` блок конфигурации провайдера, который был выведен на экран установщиком: +```terraform +terraform { + required_providers { + decort = { + version = "4.3.0" + source = "basis/decort/decort" + } + } +} +``` +9. Добавьте в файл блок с инициализацией провайдера. ```terraform provider "decort" { - authenticator = "oauth2" - #controller_url = - controller_url = "https://ds1.digitalenergy.online" - #oauth2_url = + authenticator = "oauth2" + controller_url = "https://mr4.digitalenergy.online" oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } ``` -3. Выполните команду - -``` -terraform init -``` - -Провайдер автоматически будет установлен на ваш компьютер из terraform registry. - -### Ручная установка - -1. Скачайте и установите Go по ссылке: https://go.dev/dl/ -2. Скачайте и установите terraform по ссылке: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started -3. Склонируйте репозиторий с провайдером, выполнив команду: - -```bash -git clone https://repository.basistech.ru/BASIS/terraform-provider-decort -``` - -4. Перейдите в скачанную папку с провайдером и выполните команду - +10. В консоли выполните команду ```bash -go build -o terraform-provider-decort -``` - -Если вы знаете как устроен _makefile_, то можно изменить в файле `Makefile` параметры под вашу ОС и выполнить команду - -```bash -make build +terraform init ``` -5. Полученный файл необходимо поместить: - Linux: - +11. В случае успешной установки, Terraform инициализирует провайдер и будет готов к дальнейшей работе. + +## Установка из релизов +Terraform провайдер DECORT имеет скомпилированные релизные версии, которые расположены по адресу: [Релизы](https://repository.basistech.ru/BASIS/terraform-provider-decort/releases). +Чтобы выполнить установку из релиза, необходимо: +1. Перейти по адресу: https://repository.basistech.ru/BASIS/terraform-provider-decort/releases +2. Выбрать необходимую версию провайдера подходящую под операционную систему. +3. Скачать архив. +4. Распаковать архив. +5. Полученный файл (в директории `bin/`) необходимо поместить: +Linux: ```bash ~/.terraform.d/plugins/${host_name}/${namespace}/${type}/${version}/${target} ``` - Windows: - ```powershell %APPDATA%\terraform.d\plugins\${host_name}\${namespace}\${type}\${version}\${target} ``` - -ВНИМАНИЕ: для ОС Windows `%APP_DATA%` является каталогом, в котором будут помещены будущие файлы terraform. Где: - -- host_name - имя хоста, держателя провайдера, например, digitalenergy.online -- namespace - пространство имен хоста, например decort +- host_name - имя хоста, держателя провайдера, например, basis +- namespace - пространство имен хоста, например decort - type - тип провайдера, может совпадать с пространством имен, например, decort -- version - версия провайдера, например 1.2 -- target - версия ОС, например windows_amd64 +- version - версия провайдера, например 4.3.0 +- target - архитектура операционной системы, например windows_amd64 -6. После этого, создайте файл `main.tf`. -7. Добавьте в него следующий блок +В примере ниже используется путь до провайдера на машине с ОС Linux: +```bash +~/.terraform.d/plugins/basis/decort/decort/4.3.0/linux_amd64/tf-provider + ^ ^ ^ ^ ^ ^ + host_name | | | | | | + | | | | | + namespace | | | | | + | | | | + type | | | | + | | | + version | | | + | | + target | | + | + исполняемый файл | +``` + +6. После этого, создайте файл `main.tf` в рабочей директории, которая может находится в любом удобном для пользователя месте. +В данном примере, рабочая директория с файлом main.tf находится по пути: +```bash +~/work/tfdir/main.tf +``` +7. Добавьте в `main.tf` следующий блок ```terraform terraform { required_providers { decort = { - version = "1.2" - source = "digitalenergy.online/decort/decort" + version = "4.3.0" + source = "basis/decort/decort" } } } ``` - -В поле `version` указывается версия провайдера. -Обязательный параметр -Тип поля - строка -ВНИМАНИЕ: Версии в блоке и в репозитории, в который был помещен провайдер должны совпадать! +В поле `version` указывается версия провайдера. +
+**ВНИМАНИЕ: Версии в блоке и в пути к исполняемому файлу провайдера должны совпадать!** В поле `source` помещается путь до репозитория с версией вида: @@ -143,17 +167,24 @@ terraform { ${host_name}/${namespace}/${type} ``` -ВНИМАНИЕ: все параметры должны совпадать с путем репозитория, в котором помещен провайдер. +**ВНИМАНИЕ: Версии в блоке и в пути к исполняемому файлу провайдера должны совпадать!** -8. В консоле выполнить команду +8. Добавьте в файл блок с инициализацией провайдера. +```terraform +provider "decort" { + authenticator = "oauth2" + controller_url = "https://mr4.digitalenergy.online" + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} +``` +9. В консоли выполните команду ```bash terraform init ``` -9. Если все прошло хорошо - ошибок не будет. - -Более подробно о сборке провайдера можно найти по ссылке: https://learn.hashicorp.com/tutorials/terraform/provider-use?in=terraform/providers +10. В случае успешной установки, Terraform инициализирует провайдер и будет готов к дальнейшей работе. ## Примеры работы @@ -162,8 +193,4 @@ terraform init - На вики проекта: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki - В папке `samples` -Схемы к terraform'у доступны: - -- В папке `docs` - Хорошей работы! diff --git a/go.mod b/go.mod index 1235256..7cb6839 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,8 @@ require ( github.com/hashicorp/terraform-plugin-docs v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/sirupsen/logrus v1.9.0 - golang.org/x/net v0.5.0 - repository.basistech.ru/BASIS/decort-golang-sdk v1.4.7 + golang.org/x/net v0.12.0 + repository.basistech.ru/BASIS/decort-golang-sdk v1.5.1 ) require ( @@ -21,9 +21,10 @@ require ( github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/fatih/color v1.13.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.11.2 // indirect + github.com/go-playground/validator/v10 v10.14.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -48,7 +49,7 @@ require ( github.com/hashicorp/yamux v0.1.1 // indirect github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.13 // indirect - github.com/leodido/go-urn v1.2.1 // indirect + github.com/leodido/go-urn v1.2.4 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/mitchellh/cli v1.1.5 // indirect @@ -66,9 +67,9 @@ require ( github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect github.com/vmihailenco/tagparser v0.1.2 // indirect github.com/zclconf/go-cty v1.12.1 // indirect - golang.org/x/crypto v0.5.0 // indirect - golang.org/x/sys v0.4.0 // indirect - golang.org/x/text v0.6.0 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect google.golang.org/grpc v1.51.0 // indirect diff --git a/go.sum b/go.sum index 18fb683..0c6ed97 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= @@ -53,8 +55,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= +github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= +github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -152,8 +154,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -191,7 +193,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= @@ -208,14 +210,19 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -242,8 +249,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -258,8 +265,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -286,8 +293,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -297,8 +304,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -332,5 +339,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -repository.basistech.ru/BASIS/decort-golang-sdk v1.4.7 h1:1lHhvOsMX5iFQ4z2qmVT7cORbCr+hTeEH9Lk1E2liYE= -repository.basistech.ru/BASIS/decort-golang-sdk v1.4.7/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= +repository.basistech.ru/BASIS/decort-golang-sdk v1.5.1 h1:6uvGmrmMaHRU+RV2G6xLX4tjecqalDG5PwvBv5J2LUM= +repository.basistech.ru/BASIS/decort-golang-sdk v1.5.1/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE= diff --git a/internal/controller/controller.go b/internal/controller/controller.go index feb673c..00be789 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -22,7 +22,6 @@ package controller import ( "bytes" - "context" "crypto/tls" "fmt" "io/ioutil" @@ -30,7 +29,6 @@ import ( "net/url" "strconv" "strings" - "time" // "time" @@ -373,82 +371,3 @@ func (config *ControllerCfg) CloudBroker() *cloudbroker.CloudBroker { client, _ := config.caller.(*decort.DecortClient) return client.CloudBroker() } - -func (config *ControllerCfg) DecortAPICall(ctx context.Context, method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam - // This is a convenience wrapper around standard HTTP request methods that is aware of the - // authorization mode for which the provider was initialized and compiles request accordingly. - - if config.cc_client == nil { - // this should never happen if ClientConfig was properly called prior to decortAPICall - return "", fmt.Errorf("decortAPICall method called with unconfigured DECORT cloud controller HTTP client.") - } - - // Example: to create api_params, one would generally do the following: - // - // data := []byte(`{"machineId": "2638"}`) - // api_params := bytes.NewBuffer(data)) - // - // Or: - // - // params := url.Values{} - // params.Add("machineId", "2638") - // params.Add("username", "u") - // params.Add("password", "b") - // req, _ := http.NewRequest(method, url, strings.NewReader(params.Encode())) - // - - if config.auth_mode_code == MODE_UNDEF { - return "", fmt.Errorf("decortAPICall method called for unknown authorization mode.") - } - - if config.auth_mode_code == MODE_LEGACY { - url_values.Add("authkey", config.legacy_sid) - } - params_str := url_values.Encode() - - req, err := http.NewRequest(method, config.controller_url+api_name, strings.NewReader(params_str)) - if err != nil { - return "", err - } - - req = req.WithContext(ctx) - - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - req.Header.Set("Content-Length", strconv.Itoa(len(params_str))) - req.Header.Set("Accept", "application/json") - - if config.auth_mode_code == MODE_OAUTH2 || config.auth_mode_code == MODE_JWT { - req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt)) - } - - var resp *http.Response - var body []byte - 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 - } - resp.Body.Close() - log.Debugf("decortAPICall: %s %s\n %s", method, api_name, body) - - 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 "", 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) -} diff --git a/internal/location/location.go b/internal/location/location.go index 10a772d..b44bab5 100644 --- a/internal/location/location.go +++ b/internal/location/location.go @@ -41,13 +41,13 @@ func UtilityLocationGetDefaultGridID(ctx context.Context, m interface{}) (int, e return 0, err } - if len(locList) == 0 { + if len(locList.Data) == 0 { DefaultGridID = 0 return 0, fmt.Errorf("utilityLocationGetDefaultGridID: retrieved 0 length locations list") } - DefaultGridID = int(locList[0].GID) - log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList[0].Name) + DefaultGridID = int(locList.Data[0].GID) + log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList.Data[0].Name) return DefaultGridID, nil } diff --git a/internal/provider/data_sources_map.go b/internal/provider/data_sources_map.go index 6e820f1..bb63ddd 100644 --- a/internal/provider/data_sources_map.go +++ b/internal/provider/data_sources_map.go @@ -38,6 +38,7 @@ import ( cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" + cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid" cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" @@ -65,6 +66,7 @@ func newDataSourcesMap() map[string]*schema.Resource { "decort_k8s_wg": k8s.DataSourceK8sWg(), "decort_k8s_wg_list": k8s.DataSourceK8sWgList(), "decort_k8s_computes": k8s.DataSourceK8sComputes(), + "decort_k8ci_list": k8s.DataSourceK8CIList(), "decort_vins": vins.DataSourceVins(), "decort_vins_list": vins.DataSourceVinsList(), "decort_vins_audits": vins.DataSourceVinsAudits(), @@ -132,6 +134,9 @@ func newDataSourcesMap() map[string]*schema.Resource { "decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(), "decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(), "decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(), + "decort_cb_extnet": cb_extnet.DataSourceExtnetCB(), + "decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(), + "decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(), "decort_cb_disk": cb_disks.DataSourceDisk(), "decort_cb_disk_list": cb_disks.DataSourceDiskList(), "decort_cb_image": cb_image.DataSourceImage(), diff --git a/internal/provider/resource_map.go b/internal/provider/resource_map.go index 206835e..0042e38 100644 --- a/internal/provider/resource_map.go +++ b/internal/provider/resource_map.go @@ -37,6 +37,7 @@ import ( cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" + cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" @@ -73,6 +74,7 @@ func newResourcesMap() map[string]*schema.Resource { "decort_flipgroup": flipgroup.ResourceFlipgroup(), "decort_cb_account": cb_account.ResourceAccount(), + "decort_cb_extnet": cb_extnet.ResourceExtnetCB(), "decort_cb_disk": cb_disks.ResourceDisk(), "decort_cb_image": cb_image.ResourceImage(), "decort_cb_virtual_image": cb_image.ResourceVirtualImage(), diff --git a/internal/service/cloudapi/account/data_source_account.go b/internal/service/cloudapi/account/data_source_account.go index 0407ddd..da681df 100644 --- a/internal/service/cloudapi/account/data_source_account.go +++ b/internal/service/cloudapi/account/data_source_account.go @@ -41,6 +41,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) +// TODO: resources (additional ds / additional request inside body (?)) func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { acc, err := utilityAccountCheckPresence(ctx, d, m) if err != nil { @@ -268,13 +269,13 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "resources": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: resourcesSchemaMake(), - }, - }, + // "resources": { + // Type: schema.TypeList, + // Computed: true, + // Elem: &schema.Resource{ + // Schema: resourcesSchemaMake(), + // }, + // }, "ckey": { Type: schema.TypeString, Computed: true, diff --git a/internal/service/cloudapi/account/data_source_account_computes_list.go b/internal/service/cloudapi/account/data_source_account_computes_list.go index 8eacd93..16c8639 100644 --- a/internal/service/cloudapi/account/data_source_account_computes_list.go +++ b/internal/service/cloudapi/account/data_source_account_computes_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountComputesList(acl account.ListComputes) []map[string]interface{} { +func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, acc := range acl { + for _, acc := range acl.Data { temp := map[string]interface{}{ "account_id": acc.AccountID, "account_name": acc.AccountName, @@ -82,6 +82,7 @@ func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceDa id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountComputesList(accountComputesList)) + d.Set("entry_count", accountComputesList.EntryCount) return nil } @@ -93,6 +94,56 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "compute_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by compute ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by compute name", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by RG name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -182,6 +233,10 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/data_source_account_deleted_list.go b/internal/service/cloudapi/account/data_source_account_deleted_list.go index ec02d9b..6549888 100644 --- a/internal/service/cloudapi/account/data_source_account_deleted_list.go +++ b/internal/service/cloudapi/account/data_source_account_deleted_list.go @@ -50,10 +50,17 @@ func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceDat id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountList(accountDeletedList)) + d.Set("entry_count", accountDeletedList.EntryCount) return nil } +func dataSourceAccountDeletedListSchemaMake() map[string]*schema.Schema { + temp := dataSourceAccountListSchemaMake() + delete(temp, "status") + return temp +} + func DataSourceAccountDeletedList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, @@ -65,6 +72,6 @@ func DataSourceAccountDeletedList() *schema.Resource { Default: &constants.Timeout60s, }, - Schema: dataSourceAccountListSchemaMake(), + Schema: dataSourceAccountDeletedListSchemaMake(), } } diff --git a/internal/service/cloudapi/account/data_source_account_disks_list.go b/internal/service/cloudapi/account/data_source_account_disks_list.go index e528e94..df74f26 100644 --- a/internal/service/cloudapi/account/data_source_account_disks_list.go +++ b/internal/service/cloudapi/account/data_source_account_disks_list.go @@ -41,9 +41,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} { +func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, ad := range adl { + for _, ad := range adl.Data { temp := map[string]interface{}{ "disk_id": ad.ID, "disk_name": ad.Name, @@ -68,6 +68,7 @@ func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountDisksList(accountDisksList)) + d.Set("entry_count", accountDisksList.EntryCount) return nil } @@ -79,6 +80,36 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "disk_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by disk ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by disk name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by disk max size", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by disk type", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -116,6 +147,10 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/data_source_account_flipgroups_list.go b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go index 369b053..59a2476 100644 --- a/internal/service/cloudapi/account/data_source_account_flipgroups_list.go +++ b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]interface{} { +func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, afg := range afgl { + for _, afg := range afgl.Data { temp := map[string]interface{}{ "account_id": afg.AccountID, "client_type": afg.ClientType, @@ -83,6 +83,7 @@ func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.Resource id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) + d.Set("entry_count", accountFlipGroupsList.EntryCount) return nil } @@ -94,6 +95,46 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "vins_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ViNS name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "by_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by flipgroup ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -187,6 +228,10 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/data_source_account_list.go b/internal/service/cloudapi/account/data_source_account_list.go index cbb5d7f..eabe070 100644 --- a/internal/service/cloudapi/account/data_source_account_list.go +++ b/internal/service/cloudapi/account/data_source_account_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountList(al account.ListAccounts) []map[string]interface{} { +func flattenAccountList(al *account.ListAccounts) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, acc := range al { + for _, acc := range al.Data { temp := map[string]interface{}{ "acl": flattenRgAcl(acc.ACL), "created_time": acc.CreatedTime, @@ -84,12 +84,33 @@ func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m in id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountList(accountList)) + d.Set("entry_count", accountList.EntryCount) return nil } func dataSourceAccountListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "acl": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ACL", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -164,6 +185,10 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/data_source_account_rg_list.go b/internal/service/cloudapi/account/data_source_account_rg_list.go index ecad119..d36f0b3 100644 --- a/internal/service/cloudapi/account/data_source_account_rg_list.go +++ b/internal/service/cloudapi/account/data_source_account_rg_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountRGList(argl account.ListRG) []map[string]interface{} { +func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, arg := range argl { + for _, arg := range argl.Data { temp := map[string]interface{}{ "computes": flattenAccRGComputes(arg.Computes), "resources": flattenAccRGResources(arg.Resources), @@ -125,6 +125,7 @@ func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountRGList(accountRGList)) + d.Set("entry_count", accountRGList.EntryCount) return nil } @@ -136,6 +137,41 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "vm_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by VM ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, "items": { Type: schema.TypeList, Computed: true, @@ -311,6 +347,10 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/data_source_account_templates_list.go b/internal/service/cloudapi/account/data_source_account_templates_list.go index c33bc1e..9cd114b 100644 --- a/internal/service/cloudapi/account/data_source_account_templates_list.go +++ b/internal/service/cloudapi/account/data_source_account_templates_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountTemplatesList(atl account.ListTemplates) []map[string]interface{} { +func flattenAccountTemplatesList(atl *account.ListTemplates) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, at := range atl { + for _, at := range atl.Data { temp := map[string]interface{}{ "unc_path": at.UNCPath, "account_id": at.AccountID, @@ -83,6 +83,10 @@ func dataSourceAccountTemplatesListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "include_deleted": { + Type: schema.TypeBool, + Optional: true, + }, "items": { Type: schema.TypeList, Computed: true, diff --git a/internal/service/cloudapi/account/data_source_account_vins_list.go b/internal/service/cloudapi/account/data_source_account_vins_list.go index d9b0973..81f9857 100644 --- a/internal/service/cloudapi/account/data_source_account_vins_list.go +++ b/internal/service/cloudapi/account/data_source_account_vins_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenAccountVinsList(avl account.ListVINS) []map[string]interface{} { +func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, av := range avl { + for _, av := range avl.Data { temp := map[string]interface{}{ "account_id": av.AccountID, "account_name": av.AccountName, @@ -79,6 +79,7 @@ func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenAccountVinsList(accountVinsList)) + d.Set("entry_count", accountVinsList.EntryCount) return nil } @@ -90,6 +91,36 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the account", }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -167,6 +198,10 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/account/flattens.go b/internal/service/cloudapi/account/flattens.go index c043f5d..e7693e9 100644 --- a/internal/service/cloudapi/account/flattens.go +++ b/internal/service/cloudapi/account/flattens.go @@ -7,7 +7,7 @@ import ( func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error { d.Set("dc_location", acc.DCLocation) - d.Set("resources", flattenAccResources(acc.Resources)) + // d.Set("resources", flattenAccResources(acc.Resources)) d.Set("ckey", acc.CKey) d.Set("acl", flattenAccAcl(acc.ACL)) d.Set("company", acc.Company) @@ -95,15 +95,15 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{} } -func flattenAccResources(r account.Resources) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - temp := map[string]interface{}{ - "current": flattenAccResource(r.Current), - "reserved": flattenAccResource(r.Reserved), - } - res = append(res, temp) - return res -} +// func flattenAccResources(r account.Resources) []map[string]interface{} { +// res := make([]map[string]interface{}, 0) +// temp := map[string]interface{}{ +// "current": flattenAccResource(r.Current), +// "reserved": flattenAccResource(r.Reserved), +// } +// res = append(res, temp) +// return res +// } func flattenAccountSeps(seps map[string]map[string]account.DiskUsage) []map[string]interface{} { res := make([]map[string]interface{}, 0) diff --git a/internal/service/cloudapi/account/resource_account.go b/internal/service/cloudapi/account/resource_account.go index b35bfc8..ce88494 100644 --- a/internal/service/cloudapi/account/resource_account.go +++ b/internal/service/cloudapi/account/resource_account.go @@ -47,129 +47,8 @@ import ( ) func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceAccountCreate") - - c := m.(*controller.ControllerCfg) - req := account.CreateRequest{} - - req.Name = d.Get("account_name").(string) - req.Username = d.Get("username").(string) - - if emailaddress, ok := d.GetOk("emailaddress"); ok { - req.EmailAddress = emailaddress.(string) - } - if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok { - req.SendAccessEmails = sendAccessEmails.(bool) - } - - if resLimits, ok := d.GetOk("resource_limits"); ok { - resLimit := resLimits.([]interface{})[0] - resLimitConv := resLimit.(map[string]interface{}) - if resLimitConv["cu_m"] != nil { - maxMemCap := int(resLimitConv["cu_m"].(float64)) - if maxMemCap == 0 { - req.MaxMemoryCapacity = -1 - } else { - req.MaxMemoryCapacity = int64(maxMemCap) - } - } - if resLimitConv["cu_d"] != nil { - maxDiskCap := int(resLimitConv["cu_d"].(float64)) - if maxDiskCap == 0 { - req.MaxVDiskCapacity = -1 - } else { - req.MaxVDiskCapacity = int64(maxDiskCap) - } - } - if resLimitConv["cu_c"] != nil { - maxCPUCap := int(resLimitConv["cu_c"].(float64)) - if maxCPUCap == 0 { - req.MaxCPUCapacity = -1 - } else { - req.MaxCPUCapacity = int64(maxCPUCap) - } - - } - if resLimitConv["cu_i"] != nil { - maxNumPublicIP := int(resLimitConv["cu_i"].(float64)) - if maxNumPublicIP == 0 { - req.MaxNumPublicIP = -1 - } else { - req.MaxNumPublicIP = int64(maxNumPublicIP) - } - - } - if resLimitConv["cu_np"] != nil { - maxNP := int(resLimitConv["cu_np"].(float64)) - if maxNP == 0 { - req.MaxNetworkPeerTransfer = -1 - } else { - req.MaxNetworkPeerTransfer = int64(maxNP) - } - - } - if resLimitConv["gpu_units"] != nil { - gpuUnits := int(resLimitConv["gpu_units"].(float64)) - if gpuUnits == 0 { - req.GPUUnits = -1 - } else { - req.GPUUnits = int64(gpuUnits) - } - } - } - - accountId, err := c.CloudAPI().Account().Create(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(strconv.FormatUint(accountId, 10)) - d.Set("account_id", accountId) - - if enable, ok := d.GetOk("enable"); ok { - reqSwitch := account.DisableEnableRequest{ - AccountID: accountId, - } - enable := enable.(bool) - - if enable { - - _, err := c.CloudAPI().Account().Enable(ctx, reqSwitch) - if err != nil { - return diag.FromErr(err) - - } else { - - _, err := c.CloudAPI().Account().Disable(ctx, reqSwitch) - if err != nil { - return diag.FromErr(err) - } - - } - } - } - - if users, ok := d.GetOk("users"); ok { - addedUsers := users.([]interface{}) - - if len(addedUsers) > 0 { - for _, user := range addedUsers { - userConv := user.(map[string]interface{}) - - req := account.AddUserRequest{ - AccountID: accountId, - UserID: userConv["user_id"].(string), - AccessType: strings.ToUpper(userConv["access_type"].(string)), - } - _, err := c.CloudAPI().Account().AddUser(ctx, req) - if err != nil { - return diag.FromErr(err) - } - } - } - } - - return resourceAccountRead(ctx, d, m) + return diag.Errorf( + "Only users with admin privileges are able to create accounts. Contact your platform administrator.\nUse 'terraform import decort_account. ' command to import existing account configuration") } func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { @@ -629,13 +508,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "resources": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: resourcesSchemaMake(), - }, - }, + // "resources": { + // Type: schema.TypeList, + // Computed: true, + // Elem: &schema.Resource{ + // Schema: resourcesSchemaMake(), + // }, + // }, "ckey": { Type: schema.TypeString, Computed: true, diff --git a/internal/service/cloudapi/account/utility_account_computes_list.go b/internal/service/cloudapi/account/utility_account_computes_list.go index dbbab77..48bc44a 100644 --- a/internal/service/cloudapi/account/utility_account_computes_list.go +++ b/internal/service/cloudapi/account/utility_account_computes_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListComputes, error) { +func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListComputes, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -52,6 +52,46 @@ func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.Reso AccountID: id, } + if compute_id, ok := d.GetOk("compute_id"); ok { + req.ComputeID = uint64(compute_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if rg_name, ok := d.GetOk("rg_name"); ok { + req.RGName = rg_name.(string) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + + if extnet_name, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extnet_name.(string) + } + + if extnet_id, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnet_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + log.Debugf("utilityAccountComputesListCheckPresence: load account list") accountComputesList, err := c.CloudAPI().Account().ListComputes(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/account/utility_account_deleted_list.go b/internal/service/cloudapi/account/utility_account_deleted_list.go index 1738e82..1612afc 100644 --- a/internal/service/cloudapi/account/utility_account_deleted_list.go +++ b/internal/service/cloudapi/account/utility_account_deleted_list.go @@ -42,23 +42,29 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) { +func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) { c := m.(*controller.ControllerCfg) - var ( - pageVal uint64 = 0 - sizeVal uint64 = 0 - ) + + req := account.ListDeletedRequest{} if page, ok := d.GetOk("page"); ok { - pageVal = uint64(page.(int)) + req.Page = uint64(page.(int)) } + if size, ok := d.GetOk("size"); ok { - sizeVal = uint64(size.(int)) + req.Size = uint64(size.(int)) + } + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if acl, ok := d.GetOk("acl"); ok { + req.ACL = acl.(string) } - req := account.ListDeletedRequest{ - Page: pageVal, - Size: sizeVal, + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) } log.Debugf("utilityAccountDeletedListCheckPresence: load") diff --git a/internal/service/cloudapi/account/utility_account_disks_list.go b/internal/service/cloudapi/account/utility_account_disks_list.go index b6cb9ff..c8a7728 100644 --- a/internal/service/cloudapi/account/utility_account_disks_list.go +++ b/internal/service/cloudapi/account/utility_account_disks_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListDisks, error) { +func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListDisks, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -51,6 +51,30 @@ func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.Resourc AccountID: id, } + if disk_id, ok := d.GetOk("disk_id"); ok { + req.DiskID = uint64(disk_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if disk_max_size, ok := d.GetOk("disk_max_size"); ok { + req.DiskMaxSize = uint64(disk_max_size.(int)) + } + + if typeVal, ok := d.GetOk("type"); ok { + req.Type = typeVal.(string) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + accountDisksList, err := c.CloudAPI().Account().ListDisks(ctx, req) if err != nil { return nil, err diff --git a/internal/service/cloudapi/account/utility_account_flip_groups.go b/internal/service/cloudapi/account/utility_account_flip_groups.go index 590c58f..aa30fdc 100644 --- a/internal/service/cloudapi/account/utility_account_flip_groups.go +++ b/internal/service/cloudapi/account/utility_account_flip_groups.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListFLIPGroups, error) { +func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListFLIPGroups, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -52,6 +52,38 @@ func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.Re AccountID: id, } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if vins_id, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vins_id.(int)) + } + + if vins_name, ok := d.GetOk("vins_name"); ok { + req.VINSName = vins_name.(string) + } + + if extnet_id, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnet_id.(int)) + } + + if by_ip, ok := d.GetOk("by_ip"); ok { + req.ByIP = by_ip.(string) + } + + if flipgroup_id, ok := d.GetOk("flipgroup_id"); ok { + req.FLIPGroupID = uint64(flipgroup_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + log.Debugf("utilityAccountFlipGroupsListCheckPresence") accountFlipGroupsList, err := c.CloudAPI().Account().ListFLIPGroups(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/account/utility_account_list.go b/internal/service/cloudapi/account/utility_account_list.go index 1c70087..4bf9527 100644 --- a/internal/service/cloudapi/account/utility_account_list.go +++ b/internal/service/cloudapi/account/utility_account_list.go @@ -42,23 +42,31 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) { +func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) { c := m.(*controller.ControllerCfg) - var ( - pageVal uint64 = 0 - sizeVal uint64 = 0 - ) + req := account.ListRequest{} if page, ok := d.GetOk("page"); ok { - pageVal = uint64(page.(int)) + req.Page = uint64(page.(int)) } if size, ok := d.GetOk("size"); ok { - sizeVal = uint64(size.(int)) + req.Size = uint64(size.(int)) } - req := account.ListRequest{ - Page: pageVal, - Size: sizeVal, + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if acl, ok := d.GetOk("acl"); ok { + req.ACL = acl.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) } log.Debugf("utilityAccountListCheckPresence: load account list") diff --git a/internal/service/cloudapi/account/utility_account_rg_list.go b/internal/service/cloudapi/account/utility_account_rg_list.go index ee901b8..5765010 100644 --- a/internal/service/cloudapi/account/utility_account_rg_list.go +++ b/internal/service/cloudapi/account/utility_account_rg_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListRG, error) { +func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListRG, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -52,6 +52,34 @@ func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceDa AccountID: id, } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if vins_id, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vins_id.(int)) + } + + if vm_id, ok := d.GetOk("vm_id"); ok { + req.VMID = uint64(vm_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + log.Debugf("utilityAccountRGListCheckPresence: load account list") accountRGList, err := c.CloudAPI().Account().ListRG(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/account/utility_account_templates_list.go b/internal/service/cloudapi/account/utility_account_templates_list.go index d5ae29a..29c4866 100644 --- a/internal/service/cloudapi/account/utility_account_templates_list.go +++ b/internal/service/cloudapi/account/utility_account_templates_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListTemplates, error) { +func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListTemplates, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -52,6 +52,10 @@ func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.Res AccountID: id, } + if include_deleted, ok := d.GetOk("include_deleted"); ok { + req.IncludeDeleted = include_deleted.(bool) + } + log.Debugf("utilityAccountTemplatesListCheckPresence: load") accountTemplatesList, err := c.CloudAPI().Account().ListTemplates(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/account/utility_account_vins_list.go b/internal/service/cloudapi/account/utility_account_vins_list.go index 1f2a29d..a5b21aa 100644 --- a/internal/service/cloudapi/account/utility_account_vins_list.go +++ b/internal/service/cloudapi/account/utility_account_vins_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListVINS, error) { +func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListVINS, error) { c := m.(*controller.ControllerCfg) var id uint64 @@ -52,6 +52,30 @@ func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.Resource AccountID: id, } + if vins_id, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vins_id.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + log.Debugf("utilityAccountVinsListCheckPresence: load account list") accountVinsList, err := c.CloudAPI().Account().ListVINS(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go index a99013c..ebedd71 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go @@ -50,10 +50,24 @@ func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.Resour id := uuid.New() d.SetId(id.String()) d.Set("items", flattenBasicServiceList(basicServiceDeletedList)) + d.Set("entry_count", basicServiceDeletedList.EntryCount) return nil } +func dataSourceBasicServiceDeletedListSchemaMake() map[string]*schema.Schema { + temp := dataSourceBasicServiceListSchemaMake() + + delete(temp, "by_id") + delete(temp, "name") + delete(temp, "rg_name") + delete(temp, "status") + delete(temp, "tech_status") + delete(temp, "account_name") + + return temp +} + func DataSourceBasicServiceDeletedList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, @@ -65,6 +79,6 @@ func DataSourceBasicServiceDeletedList() *schema.Resource { Default: &constants.Timeout60s, }, - Schema: dataSourceBasicServiceListSchemaMake(), + Schema: dataSourceBasicServiceDeletedListSchemaMake(), } } diff --git a/internal/service/cloudapi/bservice/data_source_bservice_list.go b/internal/service/cloudapi/bservice/data_source_bservice_list.go index 19ba43d..225d74f 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenBasicServiceList(bsl bservice.ListBasicServices) []map[string]interface{} { +func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, bs := range bsl { + for _, bs := range bsl.Data { temp := map[string]interface{}{ "account_id": bs.AccountID, "account_name": bs.AccountName, @@ -83,12 +83,43 @@ func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenBasicServiceList(basicServiceList)) + d.Set("entry_count", basicServiceList.EntryCount) return nil } func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by bservice name", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by resource group name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech status", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by account name", + }, "account_id": { Type: schema.TypeInt, Optional: true, @@ -208,6 +239,10 @@ func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/bservice/resource_check_input_values.go b/internal/service/cloudapi/bservice/resource_check_input_values.go index 16f7e2b..67f3753 100644 --- a/internal/service/cloudapi/bservice/resource_check_input_values.go +++ b/internal/service/cloudapi/bservice/resource_check_input_values.go @@ -20,5 +20,5 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool rgId := uint64(d.Get("rg_id").(int)) - return len(rgList.FilterByID(rgId)) != 0, nil + return len(rgList.FilterByID(rgId).Data) != 0, nil } diff --git a/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go index 3b321ee..31d4eaa 100644 --- a/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go +++ b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go @@ -42,9 +42,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) { +func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) { c := m.(*controller.ControllerCfg) - req := bservice.ListRequest{} + req := bservice.ListDeletedRequest{} if accountId, ok := d.GetOk("account_id"); ok { req.AccountID = uint64(accountId.(int)) diff --git a/internal/service/cloudapi/bservice/utility_bservice_list.go b/internal/service/cloudapi/bservice/utility_bservice_list.go index e143af7..5e1c662 100644 --- a/internal/service/cloudapi/bservice/utility_bservice_list.go +++ b/internal/service/cloudapi/bservice/utility_bservice_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) { +func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) { c := m.(*controller.ControllerCfg) req := bservice.ListRequest{} @@ -59,6 +59,30 @@ func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.Resourc req.Size = uint64(size.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if rg_name, ok := d.GetOk("rg_name"); ok { + req.RGName = rg_name.(string) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if acc_name, ok := d.GetOk("account_name"); ok { + req.AccountName = acc_name.(string) + } + log.Debugf("utilityBasicServiceListCheckPresence") basicServiceList, err := c.CloudAPI().BService().List(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/disks/data_source_disk_list.go b/internal/service/cloudapi/disks/data_source_disk_list.go index b6d6d82..10bf786 100644 --- a/internal/service/cloudapi/disks/data_source_disk_list.go +++ b/internal/service/cloudapi/disks/data_source_disk_list.go @@ -50,12 +50,43 @@ func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m inter id := uuid.New() d.SetId(id.String()) d.Set("items", flattenDiskList(diskList)) + d.Set("entry_count", diskList.EntryCount) return nil } func dataSourceDiskListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by max disk size", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "shared": { + Type: schema.TypeBool, + Optional: true, + Description: "Find by shared field", + }, "account_id": { Type: schema.TypeInt, Optional: true, @@ -434,6 +465,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/disks/data_source_disk_list_types_detailed.go b/internal/service/cloudapi/disks/data_source_disk_list_types_detailed.go index e46e274..abda74f 100644 --- a/internal/service/cloudapi/disks/data_source_disk_list_types_detailed.go +++ b/internal/service/cloudapi/disks/data_source_disk_list_types_detailed.go @@ -38,12 +38,13 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenDiskListTypesDetailed(tld []interface{}) []map[string]interface{} { +func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, typeListDetailed := range tld { + for _, typeListDetailed := range tld.Data { toMap := typeListDetailed.(map[string]interface{}) temp := map[string]interface{}{ "pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})), diff --git a/internal/service/cloudapi/disks/data_source_disk_list_unattached.go b/internal/service/cloudapi/disks/data_source_disk_list_unattached.go index 509de1e..b76a2c0 100644 --- a/internal/service/cloudapi/disks/data_source_disk_list_unattached.go +++ b/internal/service/cloudapi/disks/data_source_disk_list_unattached.go @@ -50,6 +50,7 @@ func dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceDat id := uuid.New() d.SetId(id.String()) d.Set("items", flattenDiskListUnattached(diskListUnattached)) + d.Set("entry_count", diskListUnattached.EntryCount) return nil } @@ -71,12 +72,46 @@ func DataSourceDiskListUnattached() *schema.Resource { func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by max disk size", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, "account_id": { Type: schema.TypeInt, Optional: true, Description: "ID of the account the disks belong to", }, - + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type of the disks", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -401,6 +436,10 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/disks/data_source_list_deleted.go b/internal/service/cloudapi/disks/data_source_list_deleted.go index caeef49..f9527e0 100644 --- a/internal/service/cloudapi/disks/data_source_list_deleted.go +++ b/internal/service/cloudapi/disks/data_source_list_deleted.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -42,7 +43,7 @@ import ( ) func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - diskList, err := utilityDiskListCheckPresence(ctx, d, m) + diskList, err := utilityDiskListDeletedCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -50,10 +51,424 @@ func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenDiskList(diskList)) + d.Set("entry_count", diskList.EntryCount) return nil } +func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by disk ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by disk name", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by max disk size", + }, + "shared": { + Type: schema.TypeBool, + Optional: true, + Description: "Find shared disks", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the account the disks belong to", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type of the disks", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the subscriber '(account') to whom this disk belongs", + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + // "boot_partition": { + // Type: schema.TypeInt, + // Computed: true, + // Description: "Number of disk partitions", + // }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeString, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Created time", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Deleted time", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Description: "Description of disk", + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Time of final deletion", + }, + "devicename": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the device", + }, + // "disk_path": { + // Type: schema.TypeString, + // Computed: true, + // Description: "Disk path", + // }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the grid (platform)", + }, + // "guid": { + // Type: schema.TypeInt, + // Computed: true, + // Description: "Disk ID on the storage side", + // }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Image ID", + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "IDs of images using the disk", + }, + "iotune": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of bytes to read per second", + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of bytes to read", + }, + "read_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of io read operations per second", + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of io read operations", + }, + "size_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Size of io operations", + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Total size bytes per second", + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum total size of bytes per second", + }, + "total_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Total number of io operations per second", + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum total number of io operations per second", + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of bytes to write per second", + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of bytes to write per second", + }, + "write_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of write operations per second", + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of write operations per second", + }, + }, + }, + }, + // "iqn": { + // Type: schema.TypeString, + // Computed: true, + // Description: "Disk IQN", + // }, + // "login": { + // Type: schema.TypeString, + // Computed: true, + // Description: "Login to access the disk", + // }, + "machine_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Machine ID", + }, + "machine_name": { + Type: schema.TypeString, + Computed: true, + Description: "Machine name", + }, + // "milestones": { + // Type: schema.TypeInt, + // Computed: true, + // Description: "Milestones", + // }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of disk", + }, + "order": { + Type: schema.TypeInt, + Computed: true, + Description: "Disk order", + }, + "params": { + Type: schema.TypeString, + Computed: true, + Description: "Disk params", + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the parent disk", + }, + // "passwd": { + // Type: schema.TypeString, + // Computed: true, + // Description: "Password to access the disk", + // }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the pci slot to which the disk is connected", + }, + "pool": { + Type: schema.TypeString, + Computed: true, + Description: "Pool for disk location", + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + // "purge_attempts": { + // Type: schema.TypeInt, + // Computed: true, + // Description: "Number of deletion attempts", + // }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Time of the last deletion attempt", + }, + // "reality_device_number": { + // Type: schema.TypeInt, + // Computed: true, + // Description: "Reality device number", + // }, + // "reference_id": { + // Type: schema.TypeString, + // Computed: true, + // Description: "ID of the reference to the disk", + // }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Resource ID", + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the resource", + }, + "role": { + Type: schema.TypeString, + Computed: true, + Description: "Disk role", + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Storage endpoint provider ID to create disk", + }, + "sep_type": { + Type: schema.TypeString, + Computed: true, + Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform", + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Size in GB", + }, + "size_used": { + Type: schema.TypeFloat, + Computed: true, + Description: "Number of used space, in GB", + }, + "snapshots": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the snapshot", + }, + "label": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the snapshot", + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Reference to the snapshot", + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + Description: "The set snapshot ID", + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + Description: "The set time of the snapshot", + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + Description: "Snapshot time", + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Disk status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "Technical status of the disk", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + Description: "Virtual Machine ID (Deprecated)", + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + func DataSourceDiskListDeleted() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, @@ -64,6 +479,6 @@ func DataSourceDiskListDeleted() *schema.Resource { Default: &constants.Timeout60s, }, - Schema: dataSourceDiskListSchemaMake(), + Schema: dataSourceDiskDeletedListSchemaMake(), } } diff --git a/internal/service/cloudapi/disks/flattens.go b/internal/service/cloudapi/disks/flattens.go index 08bffd9..da25603 100644 --- a/internal/service/cloudapi/disks/flattens.go +++ b/internal/service/cloudapi/disks/flattens.go @@ -16,9 +16,9 @@ func flattenDiskSnapshot(d *schema.ResourceData, snapshot disks.ItemSnapshot) { d.Set("snap_set_time", snapshot.SnapSetTime) } -func flattenDiskListUnattached(ul disks.ListDisksUnattached) []map[string]interface{} { +func flattenDiskListUnattached(ul *disks.ListDisksUnattached) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, unattachedDisk := range ul { + for _, unattachedDisk := range ul.Data { unattachedDiskAcl, _ := json.Marshal(unattachedDisk.ACL) tmp := map[string]interface{}{ "_ckey": unattachedDisk.CKey, @@ -136,9 +136,9 @@ func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} { return res } -func flattenDiskList(dl disks.ListDisks) []map[string]interface{} { +func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, disk := range dl { + for _, disk := range dl.Data { diskAcl, _ := json.Marshal(disk.ACL) temp := map[string]interface{}{ "account_id": disk.AccountID, diff --git a/internal/service/cloudapi/disks/resource_check_input_values.go b/internal/service/cloudapi/disks/resource_check_input_values.go index 939d22a..bfc4722 100644 --- a/internal/service/cloudapi/disks/resource_check_input_values.go +++ b/internal/service/cloudapi/disks/resource_check_input_values.go @@ -19,7 +19,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) return false, err } - return len(accountList.FilterByID(accountId)) != 0, nil + return len(accountList.FilterByID(accountId).Data) != 0, nil } func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -32,5 +32,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, return false, err } - return len(locationList.FilterByGID(gid)) != 0, nil + return len(locationList.FilterByGID(gid).Data) != 0, nil } diff --git a/internal/service/cloudapi/disks/utility_disk_list.go b/internal/service/cloudapi/disks/utility_disk_list.go index df7a9fc..420e30e 100644 --- a/internal/service/cloudapi/disks/utility_disk_list.go +++ b/internal/service/cloudapi/disks/utility_disk_list.go @@ -43,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ListDisks, error) { +func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) { c := m.(*controller.ControllerCfg) req := disks.ListRequest{} @@ -59,6 +59,24 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m if accountId, ok := d.GetOk("accountId"); ok { req.AccountID = uint64(accountId.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if account_name, ok := d.GetOk("account_name"); ok { + req.AccountName = account_name.(string) + } + if disk_max_size, ok := d.GetOk("disk_max_size"); ok { + req.DiskMaxSize = int64(disk_max_size.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if shared, ok := d.GetOk("shared"); ok { + req.Shared = shared.(bool) + } log.Debugf("utilityDiskListCheckPresence: load disk list") diskList, err := c.CloudAPI().Disks().List(ctx, req) diff --git a/internal/service/cloudapi/disks/utility_disk_list_deleted.go b/internal/service/cloudapi/disks/utility_disk_list_deleted.go new file mode 100644 index 0000000..d44d17b --- /dev/null +++ b/internal/service/cloudapi/disks/utility_disk_list_deleted.go @@ -0,0 +1,92 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package disks + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityDiskListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) { + c := m.(*controller.ControllerCfg) + req := disks.ListDeletedRequest{} + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if typev, ok := d.GetOk("type"); ok { + req.Type = typev.(string) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_name, ok := d.GetOk("account_name"); ok { + req.AccountName = account_name.(string) + } + + if disk_max_size, ok := d.GetOk("disk_max_size"); ok { + req.DiskMaxSize = int64(disk_max_size.(int)) + } + + if shared, ok := d.GetOk("shared"); ok { + req.Shared = shared.(bool) + } + + log.Debugf("utilityDiskListDeletedCheckPresence: load disk list") + diskList, err := c.CloudAPI().Disks().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return diskList, nil +} diff --git a/internal/service/cloudapi/disks/utility_disk_list_unattached.go b/internal/service/cloudapi/disks/utility_disk_list_unattached.go index c856a0b..42fa395 100644 --- a/internal/service/cloudapi/disks/utility_disk_list_unattached.go +++ b/internal/service/cloudapi/disks/utility_disk_list_unattached.go @@ -9,12 +9,31 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ListDisksUnattached, error) { +func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisksUnattached, error) { c := m.(*controller.ControllerCfg) req := disks.ListUnattachedRequest{} + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } if accountId, ok := d.GetOk("accountId"); ok { req.AccountID = uint64(accountId.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if account_name, ok := d.GetOk("account_name"); ok { + req.AccountName = account_name.(string) + } + if disk_max_size, ok := d.GetOk("disk_max_size"); ok { + req.DiskMaxSize = int64(disk_max_size.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } log.Debugf("utilityDiskListUnattachedCheckPresence: load disk Unattached list") unattachedList, err := c.CloudAPI().Disks().ListUnattached(ctx, req) diff --git a/internal/service/cloudapi/disks/utility_disk_types_detailed_list.go b/internal/service/cloudapi/disks/utility_disk_types_detailed_list.go index ade8e21..e5e2633 100644 --- a/internal/service/cloudapi/disks/utility_disk_types_detailed_list.go +++ b/internal/service/cloudapi/disks/utility_disk_types_detailed_list.go @@ -41,7 +41,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]interface{}, error) { +func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) { c := m.(*controller.ControllerCfg) req := disks.ListTypesRequest{ Detailed: true, diff --git a/internal/service/cloudapi/disks/utility_disk_types_list.go b/internal/service/cloudapi/disks/utility_disk_types_list.go index 05cbb47..f37a371 100644 --- a/internal/service/cloudapi/disks/utility_disk_types_list.go +++ b/internal/service/cloudapi/disks/utility_disk_types_list.go @@ -41,7 +41,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]interface{}, error) { +func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) { c := m.(*controller.ControllerCfg) req := disks.ListTypesRequest{ Detailed: false, diff --git a/internal/service/cloudapi/extnet/data_source_extnet_list.go b/internal/service/cloudapi/extnet/data_source_extnet_list.go index 4a179d4..5d877f8 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet_list.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_list.go @@ -50,6 +50,7 @@ func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m int id := uuid.New() d.SetId(id.String()) d.Set("items", flattenExtnetList(extnetList)) + d.Set("entry_count", extnetList.EntryCount) return nil } @@ -59,7 +60,36 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { "account_id": { Type: schema.TypeInt, Optional: true, - Description: "filter by account ID", + Description: "Find by account ID", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "network": { + Type: schema.TypeString, + Optional: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VLAN ID", + }, + "vnfdev_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VnfDEV ID", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", }, "page": { Type: schema.TypeInt, @@ -91,6 +121,10 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/extnet/flattens.go b/internal/service/cloudapi/extnet/flattens.go index ec5969a..4bd7e76 100644 --- a/internal/service/cloudapi/extnet/flattens.go +++ b/internal/service/cloudapi/extnet/flattens.go @@ -9,7 +9,7 @@ import ( func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) { d.Set("ckey", e.CKey) d.Set("meta", flattens.FlattenMeta(e.Meta)) - d.Set("check_ips", e.CheckIps) + d.Set("check_ips", e.CheckIPs) d.Set("default", e.Default) d.Set("default_qos", flattenExtnetDefaultQos(e.DefaultQOS)) d.Set("desc", e.Description) @@ -105,9 +105,9 @@ func flattenExtnetsComputes(ecs extnet.ListExtNetExtends) []map[string]interface return res } -func flattenExtnetComputesList(ecl extnet.ListExtNetComputes) []map[string]interface{} { +func flattenExtnetComputesList(ecl *extnet.ListExtNetComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, ec := range ecl { + for _, ec := range ecl.Data { temp := map[string]interface{}{ "account_id": ec.AccountID, "account_name": ec.AccountName, @@ -122,9 +122,9 @@ func flattenExtnetComputesList(ecl extnet.ListExtNetComputes) []map[string]inter return res } -func flattenExtnetList(el extnet.ListExtNets) []map[string]interface{} { +func flattenExtnetList(el *extnet.ListExtNets) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, e := range el { + for _, e := range el.Data { temp := map[string]interface{}{ "net_id": e.ID, "ipcidr": e.IPCIDR, diff --git a/internal/service/cloudapi/extnet/utility_extnet_computes_list.go b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go index c00654a..b7d486a 100644 --- a/internal/service/cloudapi/extnet/utility_extnet_computes_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (extnet.ListExtNetComputes, error) { +func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNetComputes, error) { c := m.(*controller.ControllerCfg) req := extnet.ListComputesRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudapi/extnet/utility_extnet_list.go b/internal/service/cloudapi/extnet/utility_extnet_list.go index 92cb7cf..ee45ea2 100644 --- a/internal/service/cloudapi/extnet/utility_extnet_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_list.go @@ -42,13 +42,31 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (extnet.ListExtNets, error) { +func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNets, error) { c := m.(*controller.ControllerCfg) req := extnet.ListRequest{} if accountId, ok := d.GetOk("account_id"); ok { req.AccountID = uint64(accountId.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if network, ok := d.GetOk("network"); ok { + req.Network = network.(string) + } + if vlan_id, ok := d.GetOk("vlan_id"); ok { + req.VLANID = uint64(vlan_id.(int)) + } + if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok { + req.VNFDevID = uint64(vnfdev_id.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } if page, ok := d.GetOk("page"); ok { req.Page = uint64(page.(int)) } diff --git a/internal/service/cloudapi/flipgroup/data_source_flipgroup.go b/internal/service/cloudapi/flipgroup/data_source_flipgroup.go index ddc1ae3..8d93f60 100644 --- a/internal/service/cloudapi/flipgroup/data_source_flipgroup.go +++ b/internal/service/cloudapi/flipgroup/data_source_flipgroup.go @@ -66,10 +66,6 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, Computed: true, }, - "account_name": { - Type: schema.TypeString, - Computed: true, - }, "client_ids": { Type: schema.TypeList, Computed: true, @@ -77,13 +73,6 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, }, }, - "client_names": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, "client_type": { Type: schema.TypeString, Computed: true, @@ -96,26 +85,10 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "created_by": { - Type: schema.TypeString, - Computed: true, - }, - "created_time": { - Type: schema.TypeInt, - Computed: true, - }, "default_gw": { Type: schema.TypeString, Computed: true, }, - "deleted_by": { - Type: schema.TypeString, - Computed: true, - }, - "deleted_time": { - Type: schema.TypeInt, - Computed: true, - }, "desc": { Type: schema.TypeString, Computed: true, @@ -148,30 +121,18 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "network": { + "status": { Type: schema.TypeString, Computed: true, }, - "rg_id": { + "net_mask": { Type: schema.TypeInt, Computed: true, }, - "rg_name": { + "ckey": { Type: schema.TypeString, Computed: true, }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "updated_by": { - Type: schema.TypeString, - Computed: true, - }, - "updated_time": { - Type: schema.TypeInt, - Computed: true, - }, } } diff --git a/internal/service/cloudapi/flipgroup/data_source_flipgroup_list.go b/internal/service/cloudapi/flipgroup/data_source_flipgroup_list.go index 4962ec8..b81ea25 100644 --- a/internal/service/cloudapi/flipgroup/data_source_flipgroup_list.go +++ b/internal/service/cloudapi/flipgroup/data_source_flipgroup_list.go @@ -53,12 +53,48 @@ func dataSourceFlipgroupList(ctx context.Context, d *schema.ResourceData, m inte d.SetId(id.String()) d.Set("items", flattenFlipgroupList(fg_list)) + d.Set("entry_count", fg_list.EntryCount) return nil } func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Name", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "vins_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ViNS name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ExtNetID", + }, + "by_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP-address", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -82,10 +118,6 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, Computed: true, }, - "account_name": { - Type: schema.TypeString, - Computed: true, - }, "client_ids": { Type: schema.TypeList, Computed: true, @@ -93,13 +125,6 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, }, }, - "client_names": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, "client_type": { Type: schema.TypeString, Computed: true, @@ -112,26 +137,10 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "created_by": { - Type: schema.TypeString, - Computed: true, - }, - "created_time": { - Type: schema.TypeInt, - Computed: true, - }, "default_gw": { Type: schema.TypeString, Computed: true, }, - "deleted_by": { - Type: schema.TypeString, - Computed: true, - }, - "deleted_time": { - Type: schema.TypeInt, - Computed: true, - }, "desc": { Type: schema.TypeString, Computed: true, @@ -164,33 +173,25 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "network": { + "status": { Type: schema.TypeString, Computed: true, }, - "rg_id": { + "net_mask": { Type: schema.TypeInt, Computed: true, }, - "rg_name": { + "ckey": { Type: schema.TypeString, Computed: true, }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "updated_by": { - Type: schema.TypeString, - Computed: true, - }, - "updated_time": { - Type: schema.TypeInt, - Computed: true, - }, }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } } diff --git a/internal/service/cloudapi/flipgroup/flattens.go b/internal/service/cloudapi/flipgroup/flattens.go index 1dae226..a95ccfd 100644 --- a/internal/service/cloudapi/flipgroup/flattens.go +++ b/internal/service/cloudapi/flipgroup/flattens.go @@ -38,19 +38,13 @@ import ( "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup" ) -func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) { +func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) { d.Set("account_id", fg.AccountID) - d.Set("account_name", fg.AccountName) d.Set("client_ids", fg.ClientIDs) - d.Set("client_names", fg.ClientNames) d.Set("client_type", fg.ClientType) d.Set("conn_id", fg.ConnID) d.Set("conn_type", fg.ConnType) - d.Set("created_by", fg.CreatedBy) - d.Set("created_time", fg.CreatedTime) d.Set("default_gw", fg.DefaultGW) - d.Set("deleted_by", fg.DeletedBy) - d.Set("deleted_time", fg.DeletedTime) d.Set("desc", fg.Description) d.Set("gid", fg.GID) d.Set("guid", fg.GUID) @@ -60,30 +54,19 @@ func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) { d.Set("name", fg.Name) d.Set("net_id", fg.NetID) d.Set("net_type", fg.NetType) - d.Set("network", fg.Network) - d.Set("rg_id", fg.RGID) - d.Set("rg_name", fg.RGName) d.Set("status", fg.Status) - d.Set("updated_by", fg.UpdatedBy) - d.Set("updated_time", fg.UpdatedTime) } -func flattenFlipgroupList(fg_list flipgroup.ListFLIPGroups) []map[string]interface{} { +func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, fg := range fg_list { + for _, fg := range fg_list.Data { temp := map[string]interface{}{ "account_id": fg.AccountID, - "account_name": fg.AccountName, "client_ids": fg.ClientIDs, - "client_names": fg.ClientNames, "client_type": fg.ClientType, "conn_id": fg.ConnID, "conn_type": fg.ConnType, - "created_by": fg.CreatedBy, - "created_time": fg.CreatedTime, "default_gw": fg.DefaultGW, - "deleted_by": fg.DeletedBy, - "deleted_time": fg.DeletedTime, "desc": fg.Description, "gid": fg.GID, "guid": fg.GUID, @@ -93,12 +76,7 @@ func flattenFlipgroupList(fg_list flipgroup.ListFLIPGroups) []map[string]interfa "name": fg.Name, "net_id": fg.NetID, "net_type": fg.NetType, - "network": fg.Network, - "rg_id": fg.RGID, - "rg_name": fg.RGName, "status": fg.Status, - "updated_by": fg.UpdatedBy, - "updated_time": fg.UpdatedTime, } res = append(res, temp) } diff --git a/internal/service/cloudapi/flipgroup/resource_flipgroup.go b/internal/service/cloudapi/flipgroup/resource_flipgroup.go index cd669b9..7add9b7 100644 --- a/internal/service/cloudapi/flipgroup/resource_flipgroup.go +++ b/internal/service/cloudapi/flipgroup/resource_flipgroup.go @@ -205,17 +205,6 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, Computed: true, }, - "account_name": { - Type: schema.TypeString, - Computed: true, - }, - "client_names": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, "conn_id": { Type: schema.TypeInt, Computed: true, @@ -224,26 +213,10 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "created_by": { - Type: schema.TypeString, - Computed: true, - }, - "created_time": { - Type: schema.TypeInt, - Computed: true, - }, "default_gw": { Type: schema.TypeString, Computed: true, }, - "deleted_by": { - Type: schema.TypeString, - Computed: true, - }, - "deleted_time": { - Type: schema.TypeInt, - Computed: true, - }, "gid": { Type: schema.TypeInt, Computed: true, @@ -256,30 +229,18 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, Computed: true, }, - "network": { + "status": { Type: schema.TypeString, Computed: true, }, - "rg_id": { + "net_mask": { Type: schema.TypeInt, Computed: true, }, - "rg_name": { + "ckey": { Type: schema.TypeString, Computed: true, }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "updated_by": { - Type: schema.TypeString, - Computed: true, - }, - "updated_time": { - Type: schema.TypeInt, - Computed: true, - }, } } diff --git a/internal/service/cloudapi/flipgroup/utility_flipgroup.go b/internal/service/cloudapi/flipgroup/utility_flipgroup.go index aba9f98..0151443 100644 --- a/internal/service/cloudapi/flipgroup/utility_flipgroup.go +++ b/internal/service/cloudapi/flipgroup/utility_flipgroup.go @@ -45,7 +45,7 @@ import ( log "github.com/sirupsen/logrus" ) -func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.ItemFLIPGroup, warn *dc.Warnings) { +func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.RecordFLIPGroup, warn *dc.Warnings) { addedClients := make([]interface{}, 0) removedClients := make([]interface{}, 0) @@ -127,7 +127,7 @@ func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *con } } -func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ItemFLIPGroup, error) { +func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.RecordFLIPGroup, error) { c := m.(*controller.ControllerCfg) req := flipgroup.GetRequest{} @@ -146,10 +146,38 @@ func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, return fg, err } -func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (flipgroup.ListFLIPGroups, error) { +func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ListFLIPGroups, error) { c := m.(*controller.ControllerCfg) req := flipgroup.ListRequest{} + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if vinsId, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vinsId.(int)) + } + + if vinsName, ok := d.GetOk("vins_name"); ok { + req.VINSName = vinsName.(string) + } + + if extNetId, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extNetId.(int)) + } + + if byIp, ok := d.GetOk("by_ip"); ok { + req.ByIP = byIp.(string) + } + + if rgId, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rgId.(int)) + } + + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if page, ok := d.GetOk("page"); ok { req.Page = uint64(page.(int)) } diff --git a/internal/service/cloudapi/image/data_source_image_list.go b/internal/service/cloudapi/image/data_source_image_list.go index 79a500e..b1fea5c 100644 --- a/internal/service/cloudapi/image/data_source_image_list.go +++ b/internal/service/cloudapi/image/data_source_image_list.go @@ -49,16 +49,72 @@ func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m inte id := uuid.New() d.SetId(id.String()) d.Set("items", flattenImageList(imageList)) + d.Set("entry_count", imageList.EntryCount) return nil } func dataSourceImageListSchemaMake() map[string]*schema.Schema { rets := map[string]*schema.Schema{ - "account_id": { + "sep_id": { Type: schema.TypeInt, Optional: true, - Description: "optional account ID to include account images", + Description: "Filter by Storage Endpoint ID", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "architecture": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by architecture", + }, + "type_image": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by image type", + }, + "image_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by image size", + }, + "sep_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by SEP name", + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by pool", + }, + "public": { + Type: schema.TypeBool, + Optional: true, + Description: "Find public/private images", + }, + "hot_resize": { + Type: schema.TypeBool, + Optional: true, + Description: "Find hot resizable images", + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + Description: "Find bootable images", }, "page": { Type: schema.TypeInt, @@ -78,6 +134,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema { Schema: dataSourceImageSchemaMake(), }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return rets diff --git a/internal/service/cloudapi/image/flattens.go b/internal/service/cloudapi/image/flattens.go index a2393c7..bd47fed 100644 --- a/internal/service/cloudapi/image/flattens.go +++ b/internal/service/cloudapi/image/flattens.go @@ -58,9 +58,9 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) { d.Set("version", img.Version) } -func flattenImageList(il image.ListImages) []map[string]interface{} { +func flattenImageList(il *image.ListImages) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, img := range il { + for _, img := range il.Data { temp := map[string]interface{}{ "account_id": img.AccountID, "architecture": img.Architecture, diff --git a/internal/service/cloudapi/image/resource_check_input_values.go b/internal/service/cloudapi/image/resource_check_input_values.go index d670d28..8d34576 100644 --- a/internal/service/cloudapi/image/resource_check_input_values.go +++ b/internal/service/cloudapi/image/resource_check_input_values.go @@ -19,7 +19,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) return false, err } - return len(accounts.FilterByID(accountId)) != 0, nil + return len(accounts.FilterByID(accountId).Data) != 0, nil } func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -32,5 +32,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, return false, err } - return len(locationList.FilterByGID(gid)) != 0, nil + return len(locationList.FilterByGID(gid).Data) != 0, nil } diff --git a/internal/service/cloudapi/image/utility_image_list.go b/internal/service/cloudapi/image/utility_image_list.go index aeebd2d..a4c1b71 100644 --- a/internal/service/cloudapi/image/utility_image_list.go +++ b/internal/service/cloudapi/image/utility_image_list.go @@ -42,12 +42,56 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListImages, error) { +func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) { c := m.(*controller.ControllerCfg) req := image.ListRequest{} - if accountId, ok := d.GetOk("account_id"); ok { - req.AccountID = uint64(accountId.(int)) + if sep_id, ok := d.GetOk("sep_id"); ok { + req.SEPID = uint64(sep_id.(int)) + } + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if architecture, ok := d.GetOk("architecture"); ok { + req.Architecture = architecture.(string) + } + + if type_image, ok := d.GetOk("type_image"); ok { + req.TypeImage = type_image.(string) + } + + if image_size, ok := d.GetOk("image_size"); ok { + req.ImageSize = uint64(image_size.(int)) + } + + if sep_name, ok := d.GetOk("sep_name"); ok { + req.SEPName = sep_name.(string) + } + + if pool, ok := d.GetOk("pool"); ok { + req.Pool = pool.(string) + } + + if public, ok := d.GetOk("public"); ok { + req.Public = public.(bool) + } + + if hot_resize, ok := d.GetOk("hot_resize"); ok { + req.HotResize = hot_resize.(bool) + } + + if bootable, ok := d.GetOk("bootable"); ok { + req.Bootable = bootable.(bool) } if page, ok := d.GetOk("page"); ok { diff --git a/internal/service/cloudapi/k8s/data_source_k8ci_list.go b/internal/service/cloudapi/k8s/data_source_k8ci_list.go new file mode 100644 index 0000000..ad68111 --- /dev/null +++ b/internal/service/cloudapi/k8s/data_source_k8ci_list.go @@ -0,0 +1,175 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8CIListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + list, err := utilityK8CIListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(uuid.New().String()) + flattenK8CIList(d, list) + d.Set("entry_count", list.EntryCount) + + return nil +} + +func dataSourceK8CIListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "worker_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by worker driver", + }, + "master_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by master driver", + }, + "network_plugin": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by network plugin", + }, + "include_disabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Include deleted k8cis in result", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "k8ci_id": { + Type: schema.TypeInt, + Computed: true, + Description: "K8CI ID", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI name", + }, + "lb_image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "LB Image ID", + }, + "network_plugins": { + Type: schema.TypeList, + Computed: true, + Description: "List of available network plugins", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI Status", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func DataSourceK8CIList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8CIListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8CIListSchemaMake(), + } +} diff --git a/internal/service/cloudapi/k8s/data_source_k8s.go b/internal/service/cloudapi/k8s/data_source_k8s.go index 8d019fe..98550f6 100644 --- a/internal/service/cloudapi/k8s/data_source_k8s.go +++ b/internal/service/cloudapi/k8s/data_source_k8s.go @@ -4,6 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -60,7 +61,7 @@ func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{ } curK8s := k8s.ItemK8SCluster{} - for _, k8sCluster := range k8sList { + for _, k8sCluster := range k8sList.Data { if k8sCluster.ID == cluster.ID { curK8s = k8sCluster } diff --git a/internal/service/cloudapi/k8s/data_source_k8s_list.go b/internal/service/cloudapi/k8s/data_source_k8s_list.go index 60dd22c..72e16d5 100644 --- a/internal/service/cloudapi/k8s/data_source_k8s_list.go +++ b/internal/service/cloudapi/k8s/data_source_k8s_list.go @@ -135,6 +135,46 @@ func k8sWorkersGroupsSchemaMake() map[string]*schema.Schema { func createK8sListSchema() map[string]*schema.Schema { return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP address", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "lb_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by LB ID", + }, + "bservice_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by BService ID", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, "includedeleted": { Type: schema.TypeBool, Optional: true, @@ -276,6 +316,10 @@ func createK8sListSchema() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } } diff --git a/internal/service/cloudapi/k8s/flattens.go b/internal/service/cloudapi/k8s/flattens.go index d1f4621..03387f3 100644 --- a/internal/service/cloudapi/k8s/flattens.go +++ b/internal/service/cloudapi/k8s/flattens.go @@ -37,9 +37,34 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8ci" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s" ) +func flattenK8CIItems(list *k8ci.ListK8CI) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, item := range list.Data { + temp := map[string]interface{}{ + "k8ci_id": item.ID, + "name": item.Name, + "lb_image_id": item.LBImageID, + "network_plugins": item.NetworkPlugins, + "status": item.Status, + "desc": item.Description, + "created_time": item.CreatedTime, + "version": item.Version, + } + + res = append(res, temp) + } + + return res +} + +func flattenK8CIList(d *schema.ResourceData, list *k8ci.ListK8CI) { + d.Set("items", flattenK8CIItems(list)) +} + func flattenK8sDataComputes(d *schema.ResourceData, cluster *k8s.RecordK8S) { d.Set("k8s_id", cluster.ID) d.Set("masters", flattenMasterComputes(cluster)) @@ -262,9 +287,9 @@ func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface return res } -func flattenK8sItems(k8sItems k8s.ListK8SClusters) []map[string]interface{} { +func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range k8sItems { + for _, item := range k8sItems.Data { temp := map[string]interface{}{ "account_id": item.AccountID, "account_name": item.Name, @@ -299,8 +324,9 @@ func flattenK8sItems(k8sItems k8s.ListK8SClusters) []map[string]interface{} { return res } -func flattenK8sList(d *schema.ResourceData, k8sItems k8s.ListK8SClusters) { +func flattenK8sList(d *schema.ResourceData, k8sItems *k8s.ListK8SClusters) { d.Set("items", flattenK8sItems(k8sItems)) + d.Set("entry_count", k8sItems.EntryCount) } func flattenResourceK8sCP(d *schema.ResourceData, k8s k8s.RecordK8S, masters []compute.RecordCompute) { diff --git a/internal/service/cloudapi/k8s/resource_check_input_values.go b/internal/service/cloudapi/k8s/resource_check_input_values.go index c00d090..fe79eda 100644 --- a/internal/service/cloudapi/k8s/resource_check_input_values.go +++ b/internal/service/cloudapi/k8s/resource_check_input_values.go @@ -21,7 +21,7 @@ func existK8sID(ctx context.Context, d *schema.ResourceData, m interface{}) (boo return false, err } - return len(k8sList.FilterByID(k8sID)) != 0, nil + return len(k8sList.FilterByID(k8sID).Data) != 0, nil } func existK8sCIID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -34,7 +34,7 @@ func existK8sCIID(ctx context.Context, d *schema.ResourceData, m interface{}) (b return false, err } - return len(k8sciList.FilterByID(k8sciID)) != 0, nil + return len(k8sciList.FilterByID(k8sciID).Data) != 0, nil } func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -47,7 +47,7 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool return false, err } - return len(rgList.FilterByID(rgID)) != 0, nil + return len(rgList.FilterByID(rgID).Data) != 0, nil } func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -65,5 +65,5 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) ( return false, err } - return len(extNetList.FilterByID(extNetID)) != 0, nil + return len(extNetList.FilterByID(extNetID).Data) != 0, nil } diff --git a/internal/service/cloudapi/k8s/resource_k8s.go b/internal/service/cloudapi/k8s/resource_k8s.go index 092b520..9350b1a 100644 --- a/internal/service/cloudapi/k8s/resource_k8s.go +++ b/internal/service/cloudapi/k8s/resource_k8s.go @@ -267,7 +267,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) return diag.FromErr(err) } curK8s := k8s.ItemK8SCluster{} - for _, k8sCluster := range k8sList { + for _, k8sCluster := range k8sList.Data { if k8sCluster.ID == cluster.ID { curK8s = k8sCluster } @@ -299,17 +299,19 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) flattenResourceK8s(d, *cluster, masterComputeList, workersComputeList) - lbGetReq := lb.GetRequest{ - LBID: cluster.LBID, - } + if d.Get("with_lb").(bool) || cluster.LBID != 0 { + lbGetReq := lb.GetRequest{ + LBID: cluster.LBID, + } - lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq) - if err != nil { - return diag.FromErr(err) - } + lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq) + if err != nil { + return diag.FromErr(err) + } - d.Set("extnet_id", lb.ExtNetID) - d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + d.Set("extnet_id", lb.ExtNetID) + d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + } kubeconfigReq := k8s.GetConfigRequest{ K8SID: cluster.ID, diff --git a/internal/service/cloudapi/k8s/resource_k8s_cp.go b/internal/service/cloudapi/k8s/resource_k8s_cp.go index 9dbfcff..72be59d 100644 --- a/internal/service/cloudapi/k8s/resource_k8s_cp.go +++ b/internal/service/cloudapi/k8s/resource_k8s_cp.go @@ -267,7 +267,7 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{ } curK8s := k8s.ItemK8SCluster{} - for _, k8sCluster := range k8sList { + for _, k8sCluster := range k8sList.Data { if k8sCluster.ID == cluster.ID { curK8s = k8sCluster } @@ -302,13 +302,15 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{ LBID: cluster.LBID, } - lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq) - if err != nil { - return diag.FromErr(err) - } + if d.Get("with_lb").(bool) || cluster.LBID != 0 { + lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq) + if err != nil { + return diag.FromErr(err) + } - d.Set("extnet_id", lb.ExtNetID) - d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + d.Set("extnet_id", lb.ExtNetID) + d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + } kubeconfigReq := k8s.GetConfigRequest{ K8SID: cluster.ID, diff --git a/internal/service/cloudapi/k8s/utility_k8ci.go b/internal/service/cloudapi/k8s/utility_k8ci.go new file mode 100644 index 0000000..4fad406 --- /dev/null +++ b/internal/service/cloudapi/k8s/utility_k8ci.go @@ -0,0 +1,83 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8ci" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8CIListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) { + c := m.(*controller.ControllerCfg) + + req := k8ci.ListRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if worker_driver, ok := d.GetOk("worker_driver"); ok { + req.WorkerDriver = worker_driver.(string) + } + if master_driver, ok := d.GetOk("master_driver"); ok { + req.MasterDriver = master_driver.(string) + } + if network_plugin, ok := d.GetOk("network_plugin"); ok { + req.NetworkPlugins = network_plugin.(string) + } + if include_disabled, ok := d.GetOk("include_disabled"); ok { + req.IncludeDisabled = include_disabled.(bool) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + resList, err := c.CloudAPI().K8CI().List(ctx, req) + if err != nil { + return nil, err + } + + return resList, nil +} diff --git a/internal/service/cloudapi/k8s/utility_k8s.go b/internal/service/cloudapi/k8s/utility_k8s.go index 5c80e80..c86b0f1 100644 --- a/internal/service/cloudapi/k8s/utility_k8s.go +++ b/internal/service/cloudapi/k8s/utility_k8s.go @@ -223,12 +223,44 @@ func utilityDataK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m return k8s, nil } -func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SClusters, error) { +func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) { c := m.(*controller.ControllerCfg) req := k8s.ListRequest{ IncludeDeleted: false, } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if lb_id, ok := d.GetOk("lb_id"); ok { + req.LBID = uint64(lb_id.(int)) + } + + if bservice_id, ok := d.GetOk("bservice_id"); ok { + req.BasicServiceID = uint64(bservice_id.(int)) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + k8sList, err := c.CloudAPI().K8S().List(ctx, req) if err != nil { return nil, err @@ -237,10 +269,42 @@ func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m return k8sList, nil } -func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SClusters, error) { +func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) { c := m.(*controller.ControllerCfg) req := k8s.ListDeletedRequest{} + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if lb_id, ok := d.GetOk("lb_id"); ok { + req.LBID = uint64(lb_id.(int)) + } + + if bservice_id, ok := d.GetOk("bservice_id"); ok { + req.BasicServiceID = uint64(bservice_id.(int)) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + k8sList, err := c.CloudAPI().K8S().ListDeleted(ctx, req) if err != nil { return nil, err diff --git a/internal/service/cloudapi/kvmvm/data_source_compute.go b/internal/service/cloudapi/kvmvm/data_source_compute.go index f9193e0..0901174 100644 --- a/internal/service/cloudapi/kvmvm/data_source_compute.go +++ b/internal/service/cloudapi/kvmvm/data_source_compute.go @@ -214,6 +214,10 @@ func computeSnapshotsSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, + "reference_id": { + Type: schema.TypeInt, + Computed: true, + }, "res_id": { Type: schema.TypeString, Computed: true, @@ -634,20 +638,8 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema { Computed: true, }, "custom_fields": { - Type: schema.TypeList, + Type: schema.TypeString, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "key": { - Type: schema.TypeString, - Computed: true, - }, - "val": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, }, "deleted_by": { Type: schema.TypeString, @@ -827,6 +819,14 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, + "stateless_sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_type": { + Type: schema.TypeString, + Computed: true, + }, } } diff --git a/internal/service/cloudapi/kvmvm/data_source_compute_list.go b/internal/service/cloudapi/kvmvm/data_source_compute_list.go index 27b627d..32f38e4 100644 --- a/internal/service/cloudapi/kvmvm/data_source_compute_list.go +++ b/internal/service/cloudapi/kvmvm/data_source_compute_list.go @@ -56,6 +56,7 @@ func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m in id := uuid.New() d.SetId(id.String()) d.Set("items", flattenComputeList(result)) + d.Set("entry_count", computeList.EntryCount) return nil } @@ -334,6 +335,56 @@ func itemComputeSchemaMake() map[string]*schema.Schema { func dataSourceComputeListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by AccountID", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by resgroup name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by RGID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by tech status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Find by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by Extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by Extnet ID", + }, "includedeleted": { Type: schema.TypeBool, Optional: true, @@ -359,6 +410,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema { Schema: itemComputeSchemaMake(), }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/kvmvm/flattens.go b/internal/service/cloudapi/kvmvm/flattens.go index 5d1a835..85a09ac 100644 --- a/internal/service/cloudapi/kvmvm/flattens.go +++ b/internal/service/cloudapi/kvmvm/flattens.go @@ -147,9 +147,9 @@ func flattenListACL(listAcl compute.ListACL) []map[string]interface{} { return res } -func flattenComputeList(computes compute.ListComputes) []map[string]interface{} { +func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, compute := range computes { + for _, compute := range computes.Data { customFields, _ := json.Marshal(compute.CustomFields) devices, _ := json.Marshal(compute.Devices) temp := map[string]interface{}{ @@ -265,7 +265,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{} { res := make([]map[string]interface{}, 0, len(interfaces)) - //index := 0 + for _, network := range interfaces { temp := map[string]interface{}{ "net_id": network.NetID, @@ -316,7 +316,6 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er d.Set("computeci_id", computeRec.ComputeCIID) d.Set("created_by", computeRec.CreatedBy) d.Set("created_time", computeRec.CreatedTime) - d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields)) d.Set("deleted_by", computeRec.DeletedBy) d.Set("deleted_time", computeRec.DeletedTime) d.Set("description", computeRec.Description) @@ -442,6 +441,7 @@ func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interfa "guid": snapshot.GUID, "label": snapshot.Label, "res_id": snapshot.ResID, + "reference_id": snapshot.ReferenceID, "snap_set_guid": snapshot.SnapSetGUID, "snap_set_time": snapshot.SnapSetTime, "timestamp": snapshot.TimeStamp, @@ -503,18 +503,11 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf return res } -func flattenCustomFields(customFileds map[string]interface{}) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - for key, val := range customFileds { - value, _ := json.Marshal(val) - temp := map[string]interface{}{ - "key": key, - "val": string(value), - } - res = append(res, temp) - } - return res +func flattenCustomFields(customFields map[string]interface{}) string { + encoded, _ := json.Marshal(customFields) + return string(encoded) } + func flattenOsUsers(osUsers compute.ListOSUser) []map[string]interface{} { res := make([]map[string]interface{}, 0) for _, user := range osUsers { @@ -609,9 +602,9 @@ func flattenComputeAudits(computeAudits compute.ListAudits) []map[string]interfa return res } -func flattenPfwList(computePfws compute.ListPFWs) []map[string]interface{} { +func flattenPfwList(computePfws *compute.ListPFWs) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, computePfw := range computePfws { + for _, computePfw := range computePfws.Data { temp := map[string]interface{}{ "pfw_id": computePfw.ID, "local_ip": computePfw.LocalIP, @@ -626,10 +619,10 @@ func flattenPfwList(computePfws compute.ListPFWs) []map[string]interface{} { return res } -func flattenUserList(d *schema.ResourceData, userList compute.RecordACL) { - d.Set("account_acl", flattenListACL(userList.AccountACL)) - d.Set("compute_acl", flattenListACL(userList.ComputeACL)) - d.Set("rg_acl", flattenListACL(userList.RGACL)) +func flattenUserList(d *schema.ResourceData, userList *compute.ListUsers) { + d.Set("account_acl", flattenListACL(userList.Data.AccountACL)) + d.Set("compute_acl", flattenListACL(userList.Data.ComputeACL)) + d.Set("rg_acl", flattenListACL(userList.Data.RGACL)) } func flattenComputeGetAudits(computeAudits compute.ListShortAudits) []map[string]interface{} { diff --git a/internal/service/cloudapi/kvmvm/resource_check_input_values.go b/internal/service/cloudapi/kvmvm/resource_check_input_values.go index 367931a..f776d45 100644 --- a/internal/service/cloudapi/kvmvm/resource_check_input_values.go +++ b/internal/service/cloudapi/kvmvm/resource_check_input_values.go @@ -57,7 +57,7 @@ func existRgID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool return false, err } - return len(rgList.FilterByID(rgId)) != 0, nil + return len(rgList.FilterByID(rgId).Data) != 0, nil } func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -70,11 +70,11 @@ func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) (b return false, err } - return len(imageList.FilterByID(imageId)) != 0, nil + return len(imageList.FilterByID(imageId).Data) != 0, nil } -func existVinsIdInList(vinsId uint64, vinsList vins.ListVINS) bool { - for _, vins := range vinsList { +func existVinsIdInList(vinsId uint64, vinsList *vins.ListVINS) bool { + for _, vins := range vinsList.Data { if vinsId == vins.ID { return true } @@ -83,8 +83,8 @@ func existVinsIdInList(vinsId uint64, vinsList vins.ListVINS) bool { return false } -func existExtNetIdInList(extId uint64, extList extnet.ListExtNets) bool { - for _, ext := range extList { +func existExtNetIdInList(extId uint64, extList *extnet.ListExtNets) bool { + for _, ext := range extList.Data { if extId == ext.ID { return true } diff --git a/internal/service/cloudapi/kvmvm/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go index 2dae70c..9ec4893 100644 --- a/internal/service/cloudapi/kvmvm/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -4,7 +4,7 @@ Authors: Petr Krutov, Stanislav Solovev, Kasim Baybikov, -Tim Tkachev, +Tim Tkachev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -128,23 +128,32 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf createReqPPC.IS = IS.(string) createReqX86.IS = IS.(string) } + + if !d.Get("with_default_vins").(bool) { + createReqX86.Interfaces = make([]kvmx86.Interface, 0) + } + if networks, ok := d.GetOk("network"); ok { if networks.(*schema.Set).Len() > 0 { ns := networks.(*schema.Set).List() - defaultNetwork := ns[0].(map[string]interface{}) - createReqPPC.NetType = defaultNetwork["net_type"].(string) - createReqPPC.NetID = uint64(defaultNetwork["net_id"].(int)) + interfaces := make([]kvmx86.Interface, 0) + for _, elem := range ns { + netInterfaceVal := elem.(map[string]interface{}) + reqInterface := kvmx86.Interface{ + NetType: netInterfaceVal["net_type"].(string), + NetID: uint64(netInterfaceVal["net_id"].(int)), + } - createReqX86.NetType = defaultNetwork["net_type"].(string) - createReqX86.NetID = uint64(defaultNetwork["net_id"].(int)) + ipaddr, ipSet := netInterfaceVal["ip_address"] + if ipSet { + reqInterface.IPAddr = ipaddr.(string) + } - ipaddr, ipSet := defaultNetwork["ip_address"] // "ip_address" key is optional - if ipSet { - createReqPPC.IPAddr = ipaddr.(string) - createReqX86.IPAddr = ipaddr.(string) + interfaces = append(interfaces, reqInterface) } + createReqX86.Interfaces = interfaces } } @@ -181,6 +190,18 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf createReqX86.RAM = uint64(d.Get("ram").(int)) createReqX86.ImageID = uint64(d.Get("image_id").(int)) + createReqX86.Driver = driver + + if custom_fields, ok := d.GetOk("custom_fields"); ok { + val := custom_fields.(string) + val = strings.ReplaceAll(val, "\\", "") + val = strings.ReplaceAll(val, "\n", "") + val = strings.ReplaceAll(val, "\t", "") + val = strings.TrimSpace(val) + + createReqX86.CustomFields = val + } + log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86") apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86) if err != nil { @@ -222,16 +243,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } } - argVal, ok = d.GetOk("network") - if ok && argVal.(*schema.Set).Len() > 0 { - log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len()) - err = utilityComputeNetworksConfigure(ctx, d, m, false, true, computeId) - if err != nil { - log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", computeId, err) - cleanup = true - return diag.FromErr(err) - } - } // Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface), // now we need to start it before we report the sequence complete @@ -573,11 +584,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf switch networkData["net_type"].(string) { case "VINS": if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok { - return diag.Errorf("resourceComputeUpdate: can't update compute because vins ID %d is not allowed or does not exist", vinsId) + return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId) } case "EXTNET": if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok { - return diag.Errorf("resourceComputeUpdate: can't update compute because extnet ID %d is not allowed or does not exist", extNetId) + return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId) } default: @@ -1334,6 +1345,35 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf } } + if d.HasChange("custom_fields") { + val := d.Get("custom_fields").(string) + val = strings.ReplaceAll(val, "\\", "") + val = strings.ReplaceAll(val, "\n", "") + val = strings.ReplaceAll(val, "\t", "") + val = strings.TrimSpace(val) + + if len(val) > 0 { + req := compute.SetCustomFieldsRequest{ + ComputeID: computeRec.ID, + CustomFields: val, + } + + _, err := c.CloudAPI().Compute().SetCustomFields(ctx, req) + if err != nil { + return diag.FromErr(err) + } + } else { + req := compute.DeleteCustomFieldsRequest{ + ComputeID: computeRec.ID, + } + + _, err := c.CloudAPI().Compute().DeleteCustomFields(ctx, req) + if err != nil { + return diag.FromErr(err) + } + } + } + // we may reuse dataSourceComputeRead here as we maintain similarity // between Compute resource and Compute data source schemas defer resourceComputeRead(ctx, d, m) @@ -1554,7 +1594,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Required: true, Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.", }, - "rg_id": { Type: schema.TypeInt, Required: true, @@ -1562,50 +1601,43 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { ValidateFunc: validation.IntAtLeast(1), Description: "ID of the resource group where this compute should be deployed.", }, - "driver": { Type: schema.TypeString, Required: true, ForceNew: true, StateFunc: statefuncs.StateFuncToUpper, - ValidateFunc: validation.StringInSlice([]string{"KVM_X86", "KVM_PPC"}, false), // observe case while validating + ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating Description: "Hardware architecture of this compute instance.", }, - "cpu": { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute), Description: "Number of CPUs to allocate to this compute instance.", }, - "ram": { Type: schema.TypeInt, Required: true, ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute), Description: "Amount of RAM in MB to allocate to this compute instance.", }, - "image_id": { Type: schema.TypeInt, Required: true, //ForceNew: true, //REDEPLOY Description: "ID of the OS image to base this compute instance on.", }, - "boot_disk_size": { Type: schema.TypeInt, Optional: true, Computed: true, Description: "This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image.", }, - "affinity_label": { Type: schema.TypeString, Optional: true, Description: "Set affinity label for compute", }, - "affinity_rules": { Type: schema.TypeList, Optional: true, @@ -1642,7 +1674,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { }, }, }, - "anti_affinity_rules": { Type: schema.TypeList, Optional: true, @@ -1679,7 +1710,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { }, }, }, - "disks": { Type: schema.TypeList, Optional: true, @@ -1687,6 +1717,22 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Schema: disksSubresourceSchemaMake(), }, }, + "custom_fields": { + Type: schema.TypeString, + Optional: true, + }, + "stateless": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Compute will be stateless (SVA_KVM_X86) if set to True", + }, + "with_default_vins": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Create compute with default resgroup ViNS (true) or without any interfaces (false). This parameter is ignored if network block is specified", + }, "boot_disk": { Type: schema.TypeSet, Computed: true, @@ -1862,7 +1908,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Optional: true, Description: "compute purpose", }, - // The rest are Compute properties, which are "computed" once it is created "account_id": { Type: schema.TypeInt, @@ -1917,22 +1962,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema { Type: schema.TypeInt, Computed: true, }, - "custom_fields": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "key": { - Type: schema.TypeString, - Computed: true, - }, - "val": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, "deleted_by": { Type: schema.TypeString, Computed: true, diff --git a/internal/service/cloudapi/kvmvm/utility_compute.go b/internal/service/cloudapi/kvmvm/utility_compute.go index 001f5b8..6fce42b 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute.go +++ b/internal/service/cloudapi/kvmvm/utility_compute.go @@ -44,14 +44,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func matchComputes(computeList compute.ListComputes) compute.ListComputes { +func matchComputes(computeList *compute.ListComputes) *compute.ListComputes { matched, _ := regexp.Compile("[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+") result := computeList.FilterFunc(func(ic compute.ItemCompute) bool { res := matched.Match([]byte(ic.Name)) return !res }) - return result + return &result } func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error { diff --git a/internal/service/cloudapi/kvmvm/utility_compute_list.go b/internal/service/cloudapi/kvmvm/utility_compute_list.go index b5e3f1b..652a5ac 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute_list.go +++ b/internal/service/cloudapi/kvmvm/utility_compute_list.go @@ -40,10 +40,40 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListComputes, error) { +func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListComputes, error) { c := m.(*controller.ControllerCfg) req := compute.ListRequest{} + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if rgName, ok := d.GetOk("rg_name"); ok { + req.RGName = rgName.(string) + } + if rgId, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rgId.(int)) + } + if techStatus, ok := d.GetOk("tech_status"); ok { + req.TechStatus = techStatus.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if ipAddress, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ipAddress.(string) + } + if extNetName, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extNetName.(string) + } + if extnetId, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnetId.(int)) + } if includeDeleted, ok := d.GetOk("includedeleted"); ok { req.IncludeDeleted = includeDeleted.(bool) } diff --git a/internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go b/internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go index 308a862..7b11630 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go +++ b/internal/service/cloudapi/kvmvm/utility_compute_pfw_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListPFWs, error) { +func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListPFWs, error) { c := m.(*controller.ControllerCfg) req := compute.PFWListRequest{ ComputeID: uint64(d.Get("compute_id").(int)), diff --git a/internal/service/cloudapi/kvmvm/utility_compute_user_list.go b/internal/service/cloudapi/kvmvm/utility_compute_user_list.go index 684471f..71c9d4f 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute_user_list.go +++ b/internal/service/cloudapi/kvmvm/utility_compute_user_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordACL, error) { +func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListUsers, error) { c := m.(*controller.ControllerCfg) req := compute.UserListRequest{ ComputeID: uint64(d.Get("compute_id").(int)), @@ -48,8 +48,8 @@ func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.Resource computeUserList, err := c.CloudAPI().Compute().UserList(ctx, req) if err != nil { - return *computeUserList, err + return computeUserList, err } - return *computeUserList, err + return computeUserList, err } diff --git a/internal/service/cloudapi/lb/data_source_lb_list.go b/internal/service/cloudapi/lb/data_source_lb_list.go index f4efdce..7547cc1 100644 --- a/internal/service/cloudapi/lb/data_source_lb_list.go +++ b/internal/service/cloudapi/lb/data_source_lb_list.go @@ -49,6 +49,7 @@ func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interfa id := uuid.New() d.SetId(id.String()) d.Set("items", flattenLBList(lbList)) + d.Set("entry_count", lbList.EntryCount) return nil } diff --git a/internal/service/cloudapi/lb/data_source_lb_list_deleted.go b/internal/service/cloudapi/lb/data_source_lb_list_deleted.go index d4b0f15..23be1b4 100644 --- a/internal/service/cloudapi/lb/data_source_lb_list_deleted.go +++ b/internal/service/cloudapi/lb/data_source_lb_list_deleted.go @@ -49,6 +49,7 @@ func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenLBList(lbList)) + d.Set("entry_count", lbList.EntryCount) return nil } diff --git a/internal/service/cloudapi/lb/flattens.go b/internal/service/cloudapi/lb/flattens.go index 96bba63..c23265f 100644 --- a/internal/service/cloudapi/lb/flattens.go +++ b/internal/service/cloudapi/lb/flattens.go @@ -241,9 +241,9 @@ func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} { return temp } -func flattenLBList(lbl lb.ListLB) []map[string]interface{} { - res := make([]map[string]interface{}, 0, len(lbl)) - for _, lb := range lbl { +func flattenLBList(lbl *lb.ListLB) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(lbl.Data)) + for _, lb := range lbl.Data { temp := map[string]interface{}{ "ha_mode": lb.HAMode, "backends": flattenLBBackends(lb.Backends), diff --git a/internal/service/cloudapi/lb/lb_data_subresource.go b/internal/service/cloudapi/lb/lb_data_subresource.go index 4e00cfb..e279992 100644 --- a/internal/service/cloudapi/lb/lb_data_subresource.go +++ b/internal/service/cloudapi/lb/lb_data_subresource.go @@ -45,6 +45,41 @@ func dsLBSchemaMake() map[string]*schema.Schema { func dsLBListDeletedSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by Account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by TechStatus", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by FrontIP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by BackIP", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -62,11 +97,55 @@ func dsLBListDeletedSchemaMake() map[string]*schema.Schema { Schema: dsLBItemSchemaMake(), }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } } func dsLBListSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by Account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by TechStatus", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Status", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by FrontIP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by BackIP", + }, "includedeleted": { Type: schema.TypeBool, Optional: true, @@ -89,6 +168,10 @@ func dsLBListSchemaMake() map[string]*schema.Schema { Schema: dsLBItemSchemaMake(), }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } } diff --git a/internal/service/cloudapi/lb/resource_check_input_values.go b/internal/service/cloudapi/lb/resource_check_input_values.go index 3318685..6c48dc1 100644 --- a/internal/service/cloudapi/lb/resource_check_input_values.go +++ b/internal/service/cloudapi/lb/resource_check_input_values.go @@ -22,7 +22,7 @@ func existLBID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool return false, err } - return len(lbList.FilterByID(lbId)) != 0, nil + return len(lbList.FilterByID(lbId).Data) != 0, nil } func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -36,7 +36,7 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool return false, err } - return len(rgList.FilterByID(rgId)) != 0, nil + return len(rgList.FilterByID(rgId).Data) != 0, nil } func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -50,7 +50,7 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) ( return false, err } - return len(extNetList.FilterByID(extNetID)) != 0, nil + return len(extNetList.FilterByID(extNetID).Data) != 0, nil } func existViNSID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -64,5 +64,5 @@ func existViNSID(ctx context.Context, d *schema.ResourceData, m interface{}) (bo return false, err } - return len(vinsList.FilterByID(vinsID)) != 0, nil + return len(vinsList.FilterByID(vinsID).Data) != 0, nil } diff --git a/internal/service/cloudapi/lb/resource_lb_backend.go b/internal/service/cloudapi/lb/resource_lb_backend.go index 5b63881..69c1462 100644 --- a/internal/service/cloudapi/lb/resource_lb_backend.go +++ b/internal/service/cloudapi/lb/resource_lb_backend.go @@ -198,8 +198,6 @@ func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - //TODO: перенести servers сюда - return resourceLBBackendRead(ctx, d, m) } diff --git a/internal/service/cloudapi/lb/resource_lb_frontend.go b/internal/service/cloudapi/lb/resource_lb_frontend.go index 0ddf525..233bae8 100644 --- a/internal/service/cloudapi/lb/resource_lb_frontend.go +++ b/internal/service/cloudapi/lb/resource_lb_frontend.go @@ -120,9 +120,6 @@ func resourceLBFrontendDelete(ctx context.Context, d *schema.ResourceData, m int } func resourceLBFrontendEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - - //TODO: перенести bindings сюда - return nil } diff --git a/internal/service/cloudapi/lb/utility_lb_list.go b/internal/service/cloudapi/lb/utility_lb_list.go index dcee79d..63299a1 100644 --- a/internal/service/cloudapi/lb/utility_lb_list.go +++ b/internal/service/cloudapi/lb/utility_lb_list.go @@ -42,10 +42,42 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (lb.ListLB, error) { +func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) { c := m.(*controller.ControllerCfg) req := lb.ListRequest{} + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if front_ip, ok := d.GetOk("front_ip"); ok { + req.FrontIP = front_ip.(string) + } + + if back_ip, ok := d.GetOk("back_ip"); ok { + req.BackIP = back_ip.(string) + } + if includedeleted, ok := d.GetOk("includedeleted"); ok { req.IncludeDeleted = includedeleted.(bool) } diff --git a/internal/service/cloudapi/lb/utility_lb_list_deleted.go b/internal/service/cloudapi/lb/utility_lb_list_deleted.go index d7eced9..e4a49b9 100644 --- a/internal/service/cloudapi/lb/utility_lb_list_deleted.go +++ b/internal/service/cloudapi/lb/utility_lb_list_deleted.go @@ -42,10 +42,38 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (lb.ListLB, error) { +func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) { c := m.(*controller.ControllerCfg) req := lb.ListDeletedRequest{} + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if front_ip, ok := d.GetOk("front_ip"); ok { + req.FrontIP = front_ip.(string) + } + + if back_ip, ok := d.GetOk("back_ip"); ok { + req.BackIP = back_ip.(string) + } + if page, ok := d.GetOk("page"); ok { req.Page = uint64(page.(int)) } diff --git a/internal/service/cloudapi/locations/data_source_locations_list.go b/internal/service/cloudapi/locations/data_source_locations_list.go index a4ccade..715c2d6 100644 --- a/internal/service/cloudapi/locations/data_source_locations_list.go +++ b/internal/service/cloudapi/locations/data_source_locations_list.go @@ -43,9 +43,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" ) -func flattenLocationsList(ll locations.ListLocations) []map[string]interface{} { +func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, l := range ll { + for _, l := range ll.Data { temp := map[string]interface{}{ "ckey": l.CKey, "meta": flattens.FlattenMeta(l.Meta), @@ -72,12 +72,33 @@ func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m d.SetId(id.String()) d.Set("items", flattenLocationsList(locations)) + d.Set("entry_count", locations.EntryCount) return nil } func dataSourceLocationsListSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ + "flag": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by flag", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "location_code": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by location code", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -137,6 +158,10 @@ func dataSourceLocationsListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } } diff --git a/internal/service/cloudapi/locations/utility_locations_list.go b/internal/service/cloudapi/locations/utility_locations_list.go index b0385cc..e45f0f0 100644 --- a/internal/service/cloudapi/locations/utility_locations_list.go +++ b/internal/service/cloudapi/locations/utility_locations_list.go @@ -42,17 +42,34 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (locations.ListLocations, error) { +func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*locations.ListLocations, error) { c := m.(*controller.ControllerCfg) req := locations.ListRequest{} if page, ok := d.GetOk("page"); ok { req.Page = uint64(page.(int)) } + if size, ok := d.GetOk("size"); ok { req.Size = uint64(size.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if flag, ok := d.GetOk("flag"); ok { + req.Flag = flag.(string) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if location_code, ok := d.GetOk("location_code"); ok { + req.LocationCode = location_code.(string) + } + log.Debugf("utilityLocationsListCheckPresence: load locations list") locationsList, err := c.CloudAPI().Locations().List(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/pfw/utility_pfw.go b/internal/service/cloudapi/pfw/utility_pfw.go index 71a4b60..b2e4533 100644 --- a/internal/service/cloudapi/pfw/utility_pfw.go +++ b/internal/service/cloudapi/pfw/utility_pfw.go @@ -59,7 +59,7 @@ func utilityPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m inte return nil, err } - for _, pfw := range pfws { + for _, pfw := range pfws.Data { if pfw.ID == uint64(id) { return &pfw, nil } diff --git a/internal/service/cloudapi/rg/data_source_rg.go b/internal/service/cloudapi/rg/data_source_rg.go index 0cffa9b..e857eb4 100644 --- a/internal/service/cloudapi/rg/data_source_rg.go +++ b/internal/service/cloudapi/rg/data_source_rg.go @@ -81,7 +81,7 @@ func resourcesSchemaMake() map[string]*schema.Schema { Computed: true, }, "disk_size_max": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Computed: true, }, "extips": { @@ -223,6 +223,10 @@ func resourceLimitsSchemaMake() map[string]*schema.Schema { Type: schema.TypeFloat, Computed: true, }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, "cu_i": { Type: schema.TypeFloat, Computed: true, @@ -254,14 +258,6 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Optional: true, }, - - "resources": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: resourcesSchemaMake(), - }, - }, "account_id": { Type: schema.TypeInt, Computed: true, diff --git a/internal/service/cloudapi/rg/data_source_rg_list.go b/internal/service/cloudapi/rg/data_source_rg_list.go index a42b5de..3005083 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list.go +++ b/internal/service/cloudapi/rg/data_source_rg_list.go @@ -50,12 +50,53 @@ func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interfa id := uuid.New() d.SetId(id.String()) d.Set("items", flattenRgList(rgList)) + d.Set("entry_count", rgList.EntryCount) return nil } func dataSourceRgListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by account ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "created_after": { + Type: schema.TypeInt, + Optional: true, + Description: "Find RGs created after specific time (unix timestamp)", + }, + "created_before": { + Type: schema.TypeInt, + Optional: true, + Description: "Find RGs created before specific time (unix timestamp)", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "lock_status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by lock status", + }, "includedeleted": { Type: schema.TypeBool, Optional: true, @@ -222,6 +263,10 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/rg/data_source_rg_list_computes.go b/internal/service/cloudapi/rg/data_source_rg_list_computes.go index b24a40a..12d5d9d 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list_computes.go +++ b/internal/service/cloudapi/rg/data_source_rg_list_computes.go @@ -50,6 +50,8 @@ func dataSourceRgListComputesRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenRgListComputes(listComputes)) + d.Set("entry_count", listComputes.EntryCount) + return nil } @@ -92,12 +94,56 @@ func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the RG", }, - "reason": { + "compute_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by compute ID", + }, + "name": { Type: schema.TypeString, Optional: true, - Description: "reason for action", + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "FIlter by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", }, - "items": { Type: schema.TypeList, Computed: true, @@ -204,6 +250,10 @@ func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res diff --git a/internal/service/cloudapi/rg/data_source_rg_list_deleted.go b/internal/service/cloudapi/rg/data_source_rg_list_deleted.go index f6af819..21d54ca 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list_deleted.go +++ b/internal/service/cloudapi/rg/data_source_rg_list_deleted.go @@ -50,12 +50,48 @@ func dataSourceRgListDeletedRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenRgList(rgList)) + d.Set("entry_count", rgList.EntryCount) return nil } func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by account name", + }, + "created_after": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created after certain point in time (unix timestamp)", + }, + "created_before": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created before certain point in time (unix timestamp)", + }, + "lock_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by lock status", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -66,7 +102,6 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema { Optional: true, Description: "Page size", }, - "items": { Type: schema.TypeList, Computed: true, @@ -208,6 +243,10 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/rg/data_source_rg_list_lb.go b/internal/service/cloudapi/rg/data_source_rg_list_lb.go index 10ea4c5..ff0f62d 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list_lb.go +++ b/internal/service/cloudapi/rg/data_source_rg_list_lb.go @@ -49,6 +49,8 @@ func dataSourceRgListLbRead(ctx context.Context, d *schema.ResourceData, m inter d.SetId(strconv.Itoa(d.Get("rg_id").(int))) d.Set("items", flattenRgListLb(listLb)) + d.Set("entry_count", listLb.EntryCount) + return nil } @@ -244,7 +246,51 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the RG", }, - + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by frontend IP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by backend IP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, "items": { Type: schema.TypeList, Computed: true, @@ -368,6 +414,10 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res diff --git a/internal/service/cloudapi/rg/data_source_rg_list_pfw.go b/internal/service/cloudapi/rg/data_source_rg_list_pfw.go index 7caa6bd..6125843 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list_pfw.go +++ b/internal/service/cloudapi/rg/data_source_rg_list_pfw.go @@ -49,6 +49,8 @@ func dataSourceRgListPfwRead(ctx context.Context, d *schema.ResourceData, m inte d.SetId(strconv.Itoa(d.Get("rg_id").(int))) d.Set("items", flattenRgListPfw(listPfw)) + d.Set("entry_count", listPfw.EntryCount) + return nil } @@ -59,7 +61,6 @@ func dataSourceRgListPfwSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the RG", }, - "items": { Type: schema.TypeList, Computed: true, @@ -100,6 +101,10 @@ func dataSourceRgListPfwSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res diff --git a/internal/service/cloudapi/rg/data_source_rg_list_vins.go b/internal/service/cloudapi/rg/data_source_rg_list_vins.go index fabf6dd..18cd063 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list_vins.go +++ b/internal/service/cloudapi/rg/data_source_rg_list_vins.go @@ -49,6 +49,8 @@ func dataSourceRgListVinsRead(ctx context.Context, d *schema.ResourceData, m int d.SetId(strconv.Itoa(d.Get("rg_id").(int))) d.Set("items", flattenRgListVins(listVins)) + d.Set("entry_count", listVins.EntryCount) + return nil } @@ -59,12 +61,36 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema { Required: true, Description: "ID of the RG", }, - "reason": { + "name": { Type: schema.TypeString, Optional: true, - Description: "Reason for action", + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Filter by ViNS ID", + }, + "page": { + Type: schema.TypeInt, + Required: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Required: true, + Description: "Page size", }, - "items": { Type: schema.TypeList, Computed: true, @@ -137,6 +163,10 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res diff --git a/internal/service/cloudapi/rg/flattens.go b/internal/service/cloudapi/rg/flattens.go index 0e56a79..48f19c9 100644 --- a/internal/service/cloudapi/rg/flattens.go +++ b/internal/service/cloudapi/rg/flattens.go @@ -92,7 +92,7 @@ func flattenResgroup(d *schema.ResourceData, details rg.RecordResourceGroup) err d.Set("def_net_type", details.DefNetType) d.Set("name", details.Name) - d.Set("resources", flattenRgResource(details.Resources)) + // d.Set("resources", flattenRgResource(details.Resources)) d.Set("account_name", details.AccountName) d.Set("acl", flattenRgAcl(details.ACL)) d.Set("vms", details.Computes) @@ -157,19 +157,8 @@ func flattenResource(resource rg.Resource) []map[string]interface{} { return res } -func flattenRgResource(itemResource rg.Resources) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - temp := map[string]interface{}{ - "current": flattenResource(itemResource.Current), - "reserved": flattenResource(itemResource.Reserved), - } - - res = append(res, temp) - return res -} - func flattenRg(d *schema.ResourceData, itemRg rg.RecordResourceGroup) { - d.Set("resources", flattenRgResource(itemRg.Resources)) + // d.Set("resources", flattenRgResource(itemRg.Resources)) d.Set("account_id", itemRg.AccountID) d.Set("account_name", itemRg.AccountName) d.Set("acl", flattenRgAcl(itemRg.ACL)) @@ -218,9 +207,9 @@ func flattenRgAudits(rgAudits rg.ListAudits) []map[string]interface{} { return res } -func flattenRgList(rgl rg.ListResourceGroups) []map[string]interface{} { +func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, rg := range rgl { + for _, rg := range rgl.Data { temp := map[string]interface{}{ "account_acl": flattenRgAcl(rg.ACL), "account_id": rg.AccountID, @@ -282,13 +271,13 @@ func flattenRgResourceLimits(rl rg.ResourceLimits) []map[string]interface{} { "cu_d": rl.CUD, "cu_i": rl.CUI, "cu_m": rl.CUM, + "cu_dm": rl.CUDM, "cu_np": rl.CUNP, "gpu_units": rl.GPUUnits, } res = append(res, temp) return res - } func flattenRules(list rg.ListRules) []map[string]interface{} { @@ -309,9 +298,9 @@ func flattenRules(list rg.ListRules) []map[string]interface{} { return res } -func flattenRgListComputes(lc rg.ListComputes) []map[string]interface{} { +func flattenRgListComputes(lc *rg.ListComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, compute := range lc { + for _, compute := range lc.Data { temp := map[string]interface{}{ "account_id": compute.AccountID, "account_name": compute.AccountName, @@ -437,9 +426,9 @@ func flattenNode(node rg.RecordNode) []map[string]interface{} { return res } -func flattenRgListLb(listLb rg.ListLB) []map[string]interface{} { +func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, lb := range listLb { + for _, lb := range listLb.Data { temp := map[string]interface{}{ "ha_mode": lb.HAMode, "acl": lb.ACL, @@ -472,9 +461,9 @@ func flattenRgListLb(listLb rg.ListLB) []map[string]interface{} { return res } -func flattenRgListPfw(listPfw rg.ListPortForwards) []map[string]interface{} { +func flattenRgListPfw(listPfw *rg.ListPortForwards) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, pfw := range listPfw { + for _, pfw := range listPfw.Data { temp := map[string]interface{}{ "public_port_end": pfw.PublicPortEnd, "public_port_start": pfw.PublicPortStart, @@ -491,9 +480,9 @@ func flattenRgListPfw(listPfw rg.ListPortForwards) []map[string]interface{} { return res } -func flattenRgListVins(lv rg.ListVINS) []map[string]interface{} { +func flattenRgListVins(lv *rg.ListVINS) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, vins := range lv { + for _, vins := range lv.Data { temp := map[string]interface{}{ "account_id": vins.AccountID, "account_name": vins.AccountName, @@ -519,7 +508,7 @@ func flattenRgListVins(lv rg.ListVINS) []map[string]interface{} { return res } -func flattenRgAffinityGroupComputes(list rg.ListAffinityGroups) []map[string]interface{} { +func flattenRgAffinityGroupComputes(list rg.ListAffinityGroupsComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) for _, item := range list { @@ -548,9 +537,9 @@ func flattenRgAffinityGroupsGet(list []uint64) []map[string]interface{} { return res } -func flattenRgListGroups(list map[string][]uint64) []map[string]interface{} { +func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for groupKey, groupVal := range list { + for groupKey, groupVal := range list.Data { temp := map[string]interface{}{ "label": groupKey, "ids": groupVal, diff --git a/internal/service/cloudapi/rg/resource_check_input_values.go b/internal/service/cloudapi/rg/resource_check_input_values.go index e5a9462..a18484a 100644 --- a/internal/service/cloudapi/rg/resource_check_input_values.go +++ b/internal/service/cloudapi/rg/resource_check_input_values.go @@ -53,7 +53,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) return false, err } - return len(accountList.FilterByID(accountId)) != 0, nil + return len(accountList.FilterByID(accountId).Data) != 0, nil } func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -67,7 +67,7 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, return false, err } - return len(locationList.FilterByGID(gid)) != 0, nil + return len(locationList.FilterByGID(gid).Data) != 0, nil } func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -83,5 +83,5 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) ( return false, err } - return len(listExtNet.FilterByID(extNetId)) != 0, nil + return len(listExtNet.FilterByID(extNetId).Data) != 0, nil } diff --git a/internal/service/cloudapi/rg/resource_rg.go b/internal/service/cloudapi/rg/resource_rg.go index b10997d..8ee9089 100644 --- a/internal/service/cloudapi/rg/resource_rg.go +++ b/internal/service/cloudapi/rg/resource_rg.go @@ -772,13 +772,13 @@ func ResourceRgSchemaMake() map[string]*schema.Schema { Computed: true, Description: "Name of the account, which this resource group belongs to.", }, - "resources": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: resourcesSchemaMake(), - }, - }, + // "resources": { + // Type: schema.TypeList, + // Computed: true, + // Elem: &schema.Resource{ + // Schema: resourcesSchemaMake(), + // }, + // }, "acl": { Type: schema.TypeList, diff --git a/internal/service/cloudapi/rg/utility_rg_affinity_group_computes.go b/internal/service/cloudapi/rg/utility_rg_affinity_group_computes.go index 481c209..68c12c5 100644 --- a/internal/service/cloudapi/rg/utility_rg_affinity_group_computes.go +++ b/internal/service/cloudapi/rg/utility_rg_affinity_group_computes.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroups, error) { +func utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroupsComputes, error) { c := m.(*controller.ControllerCfg) req := rg.AffinityGroupComputesRequest{ RGID: uint64(d.Get("rg_id").(int)), diff --git a/internal/service/cloudapi/rg/utility_rg_affinity_groups_list.go b/internal/service/cloudapi/rg/utility_rg_affinity_groups_list.go index 2f61129..fbd7080 100644 --- a/internal/service/cloudapi/rg/utility_rg_affinity_groups_list.go +++ b/internal/service/cloudapi/rg/utility_rg_affinity_groups_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgAffinityGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (map[string][]uint64, error) { +func utilityRgAffinityGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListAffinityGroups, error) { c := m.(*controller.ControllerCfg) req := rg.AffinityGroupsListRequest{ RGID: uint64(d.Get("rg_id").(int)), diff --git a/internal/service/cloudapi/rg/utility_rg_list.go b/internal/service/cloudapi/rg/utility_rg_list.go index 50aae56..4791ddd 100644 --- a/internal/service/cloudapi/rg/utility_rg_list.go +++ b/internal/service/cloudapi/rg/utility_rg_list.go @@ -42,10 +42,34 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListResourceGroups, error) { +func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) { c := m.(*controller.ControllerCfg) req := rg.ListRequest{} + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if accountName, ok := d.GetOk("account_name"); ok { + req.AccountName = accountName.(string) + } + if createdAfter, ok := d.GetOk("created_after"); ok { + req.CreatedAfter = uint64(createdAfter.(int)) + } + if createdBefore, ok := d.GetOk("created_before"); ok { + req.CreatedBefore = uint64(createdBefore.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if lockStatus, ok := d.GetOk("lock_status"); ok { + req.LockStatus = lockStatus.(string) + } if size, ok := d.GetOk("size"); ok { req.Size = uint64(size.(int)) } diff --git a/internal/service/cloudapi/rg/utility_rg_list_computes.go b/internal/service/cloudapi/rg/utility_rg_list_computes.go index 4c30ab1..d3c66df 100644 --- a/internal/service/cloudapi/rg/utility_rg_list_computes.go +++ b/internal/service/cloudapi/rg/utility_rg_list_computes.go @@ -40,14 +40,50 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListComputes, error) { +func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListComputes, error) { c := m.(*controller.ControllerCfg) req := rg.ListComputesRequest{ RGID: uint64(d.Get("rg_id").(int)), } - if reason, ok := d.GetOk("reason"); ok { - req.Reason = reason.(string) + if compute_id, ok := d.GetOk("compute_id"); ok { + req.ComputeID = uint64(compute_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + + if extnet_name, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extnet_name.(string) + } + + if extnet_id, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnet_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) } listComputes, err := c.CloudAPI().RG().ListComputes(ctx, req) diff --git a/internal/service/cloudapi/rg/utility_rg_list_deleted.go b/internal/service/cloudapi/rg/utility_rg_list_deleted.go index 402ae21..2044f76 100644 --- a/internal/service/cloudapi/rg/utility_rg_list_deleted.go +++ b/internal/service/cloudapi/rg/utility_rg_list_deleted.go @@ -40,10 +40,38 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListResourceGroups, error) { +func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) { c := m.(*controller.ControllerCfg) req := rg.ListDeletedRequest{} + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if account_name, ok := d.GetOk("account_name"); ok { + req.AccountName = account_name.(string) + } + + if created_after, ok := d.GetOk("created_after"); ok { + req.CreatedAfter = uint64(created_after.(int)) + } + + if created_before, ok := d.GetOk("created_before"); ok { + req.CreatedBefore = uint64(created_before.(int)) + } + + if lock_status, ok := d.GetOk("lock_status"); ok { + req.LockStatus = lock_status.(string) + } + if size, ok := d.GetOk("size"); ok { req.Size = uint64(size.(int)) } diff --git a/internal/service/cloudapi/rg/utility_rg_list_lb.go b/internal/service/cloudapi/rg/utility_rg_list_lb.go index 69f7093..54ed90a 100644 --- a/internal/service/cloudapi/rg/utility_rg_list_lb.go +++ b/internal/service/cloudapi/rg/utility_rg_list_lb.go @@ -40,12 +40,48 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListLB, error) { +func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListLB, error) { c := m.(*controller.ControllerCfg) req := rg.ListLBRequest{ RGID: uint64(d.Get("rg_id").(int)), } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if front_ip, ok := d.GetOk("front_ip"); ok { + req.FrontIP = front_ip.(string) + } + + if back_ip, ok := d.GetOk("back_ip"); ok { + req.BackIP = back_ip.(string) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + listLb, err := c.CloudAPI().RG().ListLB(ctx, req) if err != nil { return nil, err diff --git a/internal/service/cloudapi/rg/utility_rg_list_pfw.go b/internal/service/cloudapi/rg/utility_rg_list_pfw.go index e0eeff7..4f14deb 100644 --- a/internal/service/cloudapi/rg/utility_rg_list_pfw.go +++ b/internal/service/cloudapi/rg/utility_rg_list_pfw.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListPortForwards, error) { +func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListPortForwards, error) { c := m.(*controller.ControllerCfg) req := rg.ListPFWRequest{ RGID: uint64(d.Get("rg_id").(int)), diff --git a/internal/service/cloudapi/rg/utility_rg_list_vins.go b/internal/service/cloudapi/rg/utility_rg_list_vins.go index f77c195..2befba8 100644 --- a/internal/service/cloudapi/rg/utility_rg_list_vins.go +++ b/internal/service/cloudapi/rg/utility_rg_list_vins.go @@ -40,14 +40,34 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListVINS, error) { +func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListVINS, error) { c := m.(*controller.ControllerCfg) req := rg.ListVINSRequest{ RGID: uint64(d.Get("rg_id").(int)), } - if val, ok := d.GetOk("reason"); ok { - req.Reason = val.(string) + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + + if vins_id, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vins_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) } listVins, err := c.CloudAPI().RG().ListVINS(ctx, req) diff --git a/internal/service/cloudapi/snapshot/flattens.go b/internal/service/cloudapi/snapshot/flattens.go index 85709f3..c63fb78 100644 --- a/internal/service/cloudapi/snapshot/flattens.go +++ b/internal/service/cloudapi/snapshot/flattens.go @@ -5,9 +5,9 @@ import ( "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute" ) -func flattenSnapshotList(gl compute.ListSnapShots) []map[string]interface{} { +func flattenSnapshotList(gl *compute.ListSnapShots) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range gl { + for _, item := range gl.Data { temp := map[string]interface{}{ "label": item.Label, "guid": item.GUID, diff --git a/internal/service/cloudapi/snapshot/utility_snapshot.go b/internal/service/cloudapi/snapshot/utility_snapshot.go index 8c099a6..fde4cf4 100644 --- a/internal/service/cloudapi/snapshot/utility_snapshot.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot.go @@ -54,7 +54,7 @@ func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m findId = d.Id() } - for _, s := range snapShotList { + for _, s := range snapShotList.Data { if s.GUID == findId { return &s, nil } diff --git a/internal/service/cloudapi/snapshot/utility_snapshot_list.go b/internal/service/cloudapi/snapshot/utility_snapshot_list.go index 1a7ae80..301b56a 100644 --- a/internal/service/cloudapi/snapshot/utility_snapshot_list.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListSnapShots, error) { +func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListSnapShots, error) { c := m.(*controller.ControllerCfg) req := compute.SnapshotListRequest{ ComputeID: uint64(d.Get("compute_id").(int)), diff --git a/internal/service/cloudapi/vins/data_source_vins_audits.go b/internal/service/cloudapi/vins/data_source_vins_audits.go index c123c7e..2ba379e 100644 --- a/internal/service/cloudapi/vins/data_source_vins_audits.go +++ b/internal/service/cloudapi/vins/data_source_vins_audits.go @@ -49,6 +49,7 @@ func dataSourceVinsAuditsRead(ctx context.Context, d *schema.ResourceData, m int id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsAudits(audits)) + return nil } diff --git a/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go b/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go index 48a5865..d68a580 100644 --- a/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_ext_net_list.go @@ -49,6 +49,7 @@ func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsExtNetList(extNetList)) + return nil } diff --git a/internal/service/cloudapi/vins/data_source_vins_ip_list.go b/internal/service/cloudapi/vins/data_source_vins_ip_list.go index 5003189..167ca7a 100644 --- a/internal/service/cloudapi/vins/data_source_vins_ip_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_ip_list.go @@ -49,6 +49,7 @@ func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m int id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsIpList(ips)) + return nil } diff --git a/internal/service/cloudapi/vins/data_source_vins_list.go b/internal/service/cloudapi/vins/data_source_vins_list.go index 0d3812a..598d60c 100644 --- a/internal/service/cloudapi/vins/data_source_vins_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_list.go @@ -50,17 +50,43 @@ func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m inter id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsList(vinsList)) + d.Set("entry_count", vinsList.EntryCount) return nil } func dataSourceVinsListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by Account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP address", + }, "include_deleted": { Type: schema.TypeBool, Optional: true, Default: false, - Description: "include deleted computes", + Description: "Include deleted computes", }, "page": { Type: schema.TypeInt, @@ -144,6 +170,10 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/vins/data_source_vins_list_deleted.go b/internal/service/cloudapi/vins/data_source_vins_list_deleted.go index ad81f9b..1b4b112 100644 --- a/internal/service/cloudapi/vins/data_source_vins_list_deleted.go +++ b/internal/service/cloudapi/vins/data_source_vins_list_deleted.go @@ -50,12 +50,38 @@ func dataSourceVinsListDeletedRead(ctx context.Context, d *schema.ResourceData, id := uuid.New() d.SetId(id.String()) d.Set("items", flattenVinsList(vinsList)) + d.Set("entry_count", vinsList.EntryCount) return nil } func dataSourceVinsListDeletedSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by resgroup ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, "page": { Type: schema.TypeInt, Optional: true, @@ -138,6 +164,10 @@ func dataSourceVinsListDeletedSchemaMake() map[string]*schema.Schema { }, }, }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, } return res } diff --git a/internal/service/cloudapi/vins/flattens.go b/internal/service/cloudapi/vins/flattens.go index ce2b16c..7fb545f 100644 --- a/internal/service/cloudapi/vins/flattens.go +++ b/internal/service/cloudapi/vins/flattens.go @@ -277,7 +277,7 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} { func flattenRules(rules vins.ListNATRules) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, rule := range rules { + for _, rule := range rules.Data { tmp := map[string]interface{}{ "rule_id": rule.ID, "local_ip": rule.LocalIP, @@ -345,7 +345,7 @@ func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} { func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, rule := range rules { + for _, rule := range rules.Data { tmp := map[string]interface{}{ "int_ip": rule.LocalIP, "int_port": rule.LocalPort, @@ -436,9 +436,9 @@ func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} { return res } -func flattenVinsExtNetList(extNetList vins.ListExtNets) []map[string]interface{} { +func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, extNet := range extNetList { + for _, extNet := range extNetList.Data { temp := map[string]interface{}{ "default_gw": extNet.DefaultGW, "ext_net_id": extNet.ExtNetID, @@ -453,9 +453,9 @@ func flattenVinsExtNetList(extNetList vins.ListExtNets) []map[string]interface{} return res } -func flattenVinsIpList(ips vins.ListIPs) []map[string]interface{} { +func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, ip := range ips { + for _, ip := range ips.Data { temp := map[string]interface{}{ "client_type": ip.ClientType, "domainname": ip.DomainName, @@ -471,9 +471,9 @@ func flattenVinsIpList(ips vins.ListIPs) []map[string]interface{} { return res } -func flattenVinsList(vl vins.ListVINS) []map[string]interface{} { +func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, v := range vl { + for _, v := range vl.Data { temp := map[string]interface{}{ "account_id": v.AccountID, "account_name": v.AccountName, @@ -497,9 +497,9 @@ func flattenVinsList(vl vins.ListVINS) []map[string]interface{} { return res } -func flattenVinsNatRuleList(natRules vins.ListNATRules) []map[string]interface{} { +func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, natRule := range natRules { + for _, natRule := range natRules.Data { temp := map[string]interface{}{ "id": natRule.ID, "local_ip": natRule.LocalIP, diff --git a/internal/service/cloudapi/vins/resource_check_input_values.go b/internal/service/cloudapi/vins/resource_check_input_values.go index a1fb8e4..682be89 100644 --- a/internal/service/cloudapi/vins/resource_check_input_values.go +++ b/internal/service/cloudapi/vins/resource_check_input_values.go @@ -21,7 +21,7 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool return false, err } - return len(rgList.FilterByID(rgId)) != 0, nil + return len(rgList.FilterByID(rgId).Data) != 0, nil } func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -40,7 +40,7 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) ( return false, err } - return len(extNetList.FilterByID(extNetIDParsed)) != 0, nil + return len(extNetList.FilterByID(extNetIDParsed).Data) != 0, nil } func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -53,7 +53,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) return false, err } - return len(accountList.FilterByID(accountId)) != 0, nil + return len(accountList.FilterByID(accountId).Data) != 0, nil } func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { @@ -66,5 +66,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, return false, err } - return len(locationList.FilterByGID(gid)) != 0, nil + return len(locationList.FilterByGID(gid).Data) != 0, nil } diff --git a/internal/service/cloudapi/vins/utility_vins_ext_net_list.go b/internal/service/cloudapi/vins/utility_vins_ext_net_list.go index 3e3e7f3..fe210e2 100644 --- a/internal/service/cloudapi/vins/utility_vins_ext_net_list.go +++ b/internal/service/cloudapi/vins/utility_vins_ext_net_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListExtNets, error) { +func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListExtNets, error) { c := m.(*controller.ControllerCfg) req := vins.ExtNetListRequest{ VINSID: uint64(d.Get("vins_id").(int)), diff --git a/internal/service/cloudapi/vins/utility_vins_ip_list.go b/internal/service/cloudapi/vins/utility_vins_ip_list.go index 614ebbe..c7f24af 100644 --- a/internal/service/cloudapi/vins/utility_vins_ip_list.go +++ b/internal/service/cloudapi/vins/utility_vins_ip_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListIPs, error) { +func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) { c := m.(*controller.ControllerCfg) req := vins.IPListRequest{ VINSID: uint64(d.Get("vins_id").(int)), diff --git a/internal/service/cloudapi/vins/utility_vins_list.go b/internal/service/cloudapi/vins/utility_vins_list.go index a00c20b..67804ef 100644 --- a/internal/service/cloudapi/vins/utility_vins_list.go +++ b/internal/service/cloudapi/vins/utility_vins_list.go @@ -42,10 +42,30 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) { +func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) { c := m.(*controller.ControllerCfg) req := vins.ListRequest{} + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + if includeDeleted, ok := d.GetOk("include_deleted"); ok { req.IncludeDeleted = includeDeleted.(bool) } diff --git a/internal/service/cloudapi/vins/utility_vins_list_deleted.go b/internal/service/cloudapi/vins/utility_vins_list_deleted.go index 92db68a..3554c2c 100644 --- a/internal/service/cloudapi/vins/utility_vins_list_deleted.go +++ b/internal/service/cloudapi/vins/utility_vins_list_deleted.go @@ -41,7 +41,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) { +func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) { c := m.(*controller.ControllerCfg) req := vins.ListDeletedRequest{} @@ -52,6 +52,26 @@ func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.Resource req.Size = uint64(size.(int)) } + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + log.Debugf("utilityVinsListDeletedCheckPresence") vinsList, err := c.CloudAPI().VINS().ListDeleted(ctx, req) if err != nil { diff --git a/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go b/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go index 5e3c283..b6fb116 100644 --- a/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go +++ b/internal/service/cloudapi/vins/utility_vins_nat_rule_list.go @@ -40,7 +40,7 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListNATRules, error) { +func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) { c := m.(*controller.ControllerCfg) req := vins.NATRuleListRequest{ VINSID: uint64(d.Get("vins_id").(int)), diff --git a/internal/service/cloudbroker/account/data_source_account_deleted_list.go b/internal/service/cloudbroker/account/data_source_account_deleted_list.go index 01ed41b..dc2b700 100644 --- a/internal/service/cloudbroker/account/data_source_account_deleted_list.go +++ b/internal/service/cloudbroker/account/data_source_account_deleted_list.go @@ -48,7 +48,7 @@ func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceDat id := uuid.New() d.SetId(id.String()) - d.Set("items", flattenAccountList(accountDeletedList)) + d.Set("items", flattenListDeleted(accountDeletedList)) return nil } diff --git a/internal/service/cloudbroker/account/flattens.go b/internal/service/cloudbroker/account/flattens.go index 7084d45..39ccf95 100644 --- a/internal/service/cloudbroker/account/flattens.go +++ b/internal/service/cloudbroker/account/flattens.go @@ -8,7 +8,7 @@ import ( func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) { d.Set("dc_location", acc.DCLocation) - d.Set("resources", flattenAccResources(acc.Resources)) + // d.Set("resources", flattenAccResources(acc.Resources)) d.Set("ckey", acc.CKey) d.Set("acl", flattenAccAcl(acc.ACL)) d.Set("company", acc.Company) @@ -32,7 +32,7 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) { d.Set("dc_location", acc.DCLocation) - d.Set("resources", flattenAccResources(acc.Resources)) + // d.Set("resources", flattenAccResources(acc.Resources)) d.Set("ckey", acc.CKey) // d.Set("meta", flattens.FlattenMeta(acc.)) d.Set("acl", flattenAccAcl(acc.ACL)) @@ -57,9 +57,9 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) { } -func flattenAccountRGList(argl account.ListRG) []map[string]interface{} { +func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, arg := range argl { + for _, arg := range argl.Data { temp := map[string]interface{}{ "computes": flattenAccRGComputes(arg.Computes), "resources": flattenAccRGResources(arg.Resources), @@ -102,7 +102,7 @@ func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} { return res } -func flattenAccResources(r account.RecordResources) []map[string]interface{} { +func flattenAccResources(r account.RecordResourceConsumption) []map[string]interface{} { res := make([]map[string]interface{}, 0) temp := map[string]interface{}{ "current": flattenAccResource(r.Current), @@ -201,9 +201,51 @@ func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} { return res } -func flattenAccountList(al account.ListAccounts) []map[string]interface{} { +func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, acc := range al { + for _, acc := range al.Data { + temp := map[string]interface{}{ + "dc_location": acc.DCLocation, + "ckey": acc.CKey, + "meta": flattens.FlattenMeta(acc.Meta), + + "acl": flattenRgAcl(acc.ACL), + + "company": acc.Company, + "companyurl": acc.CompanyURL, + "created_by": acc.CreatedBy, + + "created_time": acc.CreatedTime, + + "deactivation_time": acc.DeactivationTime, + "deleted_by": acc.DeletedBy, + + "deleted_time": acc.DeletedTime, + + "displayname": acc.DisplayName, + "guid": acc.GUID, + + "account_id": acc.ID, + "account_name": acc.Name, + + "resource_limits": flattenRgResourceLimits(acc.ResourceLimits), + "send_access_emails": acc.SendAccessEmails, + // "service_account": acc.ServiceAccount, + + "status": acc.Status, + "updated_time": acc.UpdatedTime, + + "version": acc.Version, + "vins": acc.VINS, + } + res = append(res, temp) + } + return res +} + +func flattenAccountList(al *account.ListAccounts) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, acc := range al.Data { temp := map[string]interface{}{ "dc_location": acc.DCLocation, "ckey": acc.CKey, @@ -258,9 +300,9 @@ func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} { return res } -func flattenAccountComputesList(acl account.ListComputes) []map[string]interface{} { +func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, acc := range acl { + for _, acc := range acl.Data { temp := map[string]interface{}{ "account_id": acc.AccountID, "account_name": acc.AccountName, @@ -288,9 +330,9 @@ func flattenAccountComputesList(acl account.ListComputes) []map[string]interface return res } -func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} { +func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, ad := range adl { + for _, ad := range adl.Data { temp := map[string]interface{}{ "disk_id": ad.ID, "disk_name": ad.Name, @@ -304,9 +346,9 @@ func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} { return res } -func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]interface{} { +func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, afg := range afgl { + for _, afg := range afgl.Data { temp := map[string]interface{}{ "account_id": afg.AccountID, "client_type": afg.ClientType, @@ -335,9 +377,9 @@ func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]inte return res } -func flattenAccountVinsList(avl account.ListVINS) []map[string]interface{} { +func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, av := range avl { + for _, av := range avl.Data { temp := map[string]interface{}{ "account_id": av.AccountID, "account_name": av.AccountName, diff --git a/internal/service/cloudbroker/account/utility_account_computes_list.go b/internal/service/cloudbroker/account/utility_account_computes_list.go index bcf695a..1cb3cab 100644 --- a/internal/service/cloudbroker/account/utility_account_computes_list.go +++ b/internal/service/cloudbroker/account/utility_account_computes_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListComputes, error) { +func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListComputes, error) { c := m.(*controller.ControllerCfg) req := account.ListComputesRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudbroker/account/utility_account_deleted_list.go b/internal/service/cloudbroker/account/utility_account_deleted_list.go index 78407df..62dcbce 100644 --- a/internal/service/cloudbroker/account/utility_account_deleted_list.go +++ b/internal/service/cloudbroker/account/utility_account_deleted_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) { +func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) { c := m.(*controller.ControllerCfg) req := account.ListDeletedRequest{} diff --git a/internal/service/cloudbroker/account/utility_account_disks_list.go b/internal/service/cloudbroker/account/utility_account_disks_list.go index 0028b1a..6e243dd 100644 --- a/internal/service/cloudbroker/account/utility_account_disks_list.go +++ b/internal/service/cloudbroker/account/utility_account_disks_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListDisks, error) { +func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListDisks, error) { c := m.(*controller.ControllerCfg) req := account.ListDisksRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudbroker/account/utility_account_flip_groups.go b/internal/service/cloudbroker/account/utility_account_flip_groups.go index 7f14cee..186cdb1 100644 --- a/internal/service/cloudbroker/account/utility_account_flip_groups.go +++ b/internal/service/cloudbroker/account/utility_account_flip_groups.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListFLIPGroups, error) { +func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListFLIPGroups, error) { c := m.(*controller.ControllerCfg) req := account.ListFLIPGroupsRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudbroker/account/utility_account_list.go b/internal/service/cloudbroker/account/utility_account_list.go index f572ea8..a9d35e3 100644 --- a/internal/service/cloudbroker/account/utility_account_list.go +++ b/internal/service/cloudbroker/account/utility_account_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) { +func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) { c := m.(*controller.ControllerCfg) req := account.ListRequest{} diff --git a/internal/service/cloudbroker/account/utility_account_rg_list.go b/internal/service/cloudbroker/account/utility_account_rg_list.go index 3be8fd7..efbedee 100644 --- a/internal/service/cloudbroker/account/utility_account_rg_list.go +++ b/internal/service/cloudbroker/account/utility_account_rg_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListRG, error) { +func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListRG, error) { c := m.(*controller.ControllerCfg) req := account.ListRGRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudbroker/account/utility_account_vins_list.go b/internal/service/cloudbroker/account/utility_account_vins_list.go index 571b8cd..abf17d8 100644 --- a/internal/service/cloudbroker/account/utility_account_vins_list.go +++ b/internal/service/cloudbroker/account/utility_account_vins_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListVINS, error) { +func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListVINS, error) { c := m.(*controller.ControllerCfg) req := account.ListVINSRequest{ AccountID: uint64(d.Get("account_id").(int)), diff --git a/internal/service/cloudbroker/disks/flattens.go b/internal/service/cloudbroker/disks/flattens.go index ec304cf..ba66670 100644 --- a/internal/service/cloudbroker/disks/flattens.go +++ b/internal/service/cloudbroker/disks/flattens.go @@ -76,9 +76,9 @@ func flattenIOTune(iot disks.IOTune) []map[string]interface{} { return res } -func flattenDiskList(dl disks.ListDisks) []map[string]interface{} { +func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, disk := range dl { + for _, disk := range dl.Data { diskAcl, _ := json.Marshal(disk.ACL) temp := map[string]interface{}{ "account_id": disk.AccountID, diff --git a/internal/service/cloudbroker/disks/utility_disk_list.go b/internal/service/cloudbroker/disks/utility_disk_list.go index c953135..a5e4742 100644 --- a/internal/service/cloudbroker/disks/utility_disk_list.go +++ b/internal/service/cloudbroker/disks/utility_disk_list.go @@ -42,7 +42,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ListDisks, error) { +func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) { c := m.(*controller.ControllerCfg) req := disks.ListRequest{} diff --git a/internal/service/cloudbroker/extnet/data_source_extnet.go b/internal/service/cloudbroker/extnet/data_source_extnet.go new file mode 100644 index 0000000..272dabe --- /dev/null +++ b/internal/service/cloudbroker/extnet/data_source_extnet.go @@ -0,0 +1,296 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + net, err := utilityExtnetCheckPresence(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(net.ID, 10)) + flattenRecordExtnet(d, net) + + return nil +} + +func dataSourceExtnetSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "net_id": { + Type: schema.TypeInt, + Required: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ipcidr": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ovs_bridge": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "check_ips": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "dns": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "excluded": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "prefix": { + Type: schema.TypeInt, + Computed: true, + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func DataSourceExtnetCB() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceExtnetRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceExtnetSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/extnet/data_source_extnet_default.go b/internal/service/cloudbroker/extnet/data_source_extnet_default.go new file mode 100644 index 0000000..6d4fa7d --- /dev/null +++ b/internal/service/cloudbroker/extnet/data_source_extnet_default.go @@ -0,0 +1,80 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + extnetId, err := utilityExtnetDefaultCheckPresence(ctx, m) + if err != nil { + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + + d.Set("net_id", extnetId) + + return nil +} + +func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func DataSourceExtnetDefaultCB() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceExtnetDefaultRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceExtnetDefaultSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/extnet/data_source_extnet_list.go b/internal/service/cloudbroker/extnet/data_source_extnet_list.go new file mode 100644 index 0000000..92dfd4a --- /dev/null +++ b/internal/service/cloudbroker/extnet/data_source_extnet_list.go @@ -0,0 +1,255 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + netList, err := utilityExtnetListCheckPresence(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(uuid.New().String()) + + d.Set("items", flattenListExtnet(netList)) + d.Set("entry_count", netList.EntryCount) + + return nil +} + +func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by account ID", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "network": { + Type: schema.TypeString, + Optional: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VLAN ID", + }, + "vnfdev_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VnfDEV ID", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ipcidr": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ovs_bridge": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "check_ips": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func DataSourceExtnetListCB() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceExtnetListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceExtnetListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/extnet/flattens.go b/internal/service/cloudbroker/extnet/flattens.go new file mode 100644 index 0000000..6017540 --- /dev/null +++ b/internal/service/cloudbroker/extnet/flattens.go @@ -0,0 +1,161 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" +) + +func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, item := range extList.Data { + temp := map[string]interface{}{ + "ckey": item.CKey, + "meta": flattens.FlattenMeta(item.Meta), + "default": item.Default, + "desc": item.Description, + "free_ips": item.FreeIPs, + "gid": item.GID, + "guid": item.GUID, + "extnet_id": item.ID, + "ipcidr": item.IPCIDR, + "milestones": item.Milestones, + "name": item.Name, + "network_id": item.NetworkID, + "ovs_bridge": item.OVSBridge, + "pre_reservations_num": item.PreReservationsNum, + "pri_vnfdev_id": item.PriVNFDevID, + "shared_with": item.SharedWith, + "status": item.Status, + "vlan_id": item.VLANID, + "check_ips": item.CheckIPs, + } + + res = append(res, temp) + } + + return res +} + +func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) { + d.Set("ckey", recNet.CKey) + d.Set("meta", flattens.FlattenMeta(recNet.Meta)) + + d.Set("default", recNet.Default) + d.Set("desc", recNet.Description) + d.Set("free_ips", recNet.FreeIPs) + d.Set("gid", recNet.GID) + d.Set("guid", recNet.GUID) + d.Set("extnet_id", recNet.ID) + d.Set("ipcidr", recNet.IPCIDR) + d.Set("milestones", recNet.Milestones) + d.Set("name", recNet.Name) + d.Set("network_id", recNet.NetworkID) + d.Set("ovs_bridge", recNet.OVSBridge) + d.Set("pre_reservations_num", recNet.PreReservationsNum) + d.Set("pri_vnfdev_id", recNet.PriVNFDevID) + d.Set("shared_with", recNet.SharedWith) + d.Set("status", recNet.Status) + d.Set("vlan_id", recNet.VLANID) + d.Set("check_ips", recNet.CheckIPs) + d.Set("dns", recNet.DNS) + d.Set("excluded", flattenExtnetExcluded(recNet.Excluded)) + d.Set("gateway", recNet.Gateway) + d.Set("network", recNet.Network) + d.Set("prefix", recNet.Prefix) + + d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS)) + d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs)) + d.Set("reservations", flattenExtnetReservations(recNet.Reservations)) +} + +func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, er := range ers { + temp := map[string]interface{}{ + "client_type": er.ClientType, + "domain_name": er.DomainName, + "hostname": er.Hostname, + "ip": er.IP, + "mac": er.MAC, + "type": er.Type, + "vm_id": er.VMID, + } + res = append(res, temp) + } + + return res +} + +func flattenExtnetReservations(ers extnet.ListReservations) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, er := range ers { + temp := map[string]interface{}{ + "client_type": er.ClientType, + "domain_name": er.DomainName, + "hostname": er.Hostname, + "desc": er.Description, + "ip": er.IP, + "mac": er.MAC, + "type": er.Type, + "vm_id": er.VMID, + } + res = append(res, temp) + } + + return res +} + +func flattenExtnetVNFS(evnfs extnet.VNFs) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "dhcp": evnfs.DHCP, + } + res = append(res, temp) + return res +} + +func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "e_rate": edqos.ERate, + "guid": edqos.GUID, + "in_burst": edqos.InBurst, + "in_rate": edqos.InRate, + } + res = append(res, temp) + return res +} diff --git a/internal/service/cloudbroker/extnet/resource_extnet.go b/internal/service/cloudbroker/extnet/resource_extnet.go new file mode 100644 index 0000000..b1ff12c --- /dev/null +++ b/internal/service/cloudbroker/extnet/resource_extnet.go @@ -0,0 +1,542 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string)) + c := m.(*controller.ControllerCfg) + + req := extnet.CreateRequest{ + Name: d.Get("name").(string), + GID: uint64(d.Get("gid").(int)), + IPCIDR: d.Get("ipcidr").(string), + VLANID: uint64(d.Get("vlan_id").(int)), + } + + if gateway, ok := d.GetOk("gateway"); ok { + req.Gateway = gateway.(string) + } + + if dns, ok := d.GetOk("dns"); ok { + res := make([]string, 0) + for _, elem := range dns.([]interface{}) { + res = append(res, elem.(string)) + } + + req.DNS = res + } + + if ntp, ok := d.GetOk("ntp"); ok { + res := make([]string, 0) + for _, elem := range ntp.([]interface{}) { + res = append(res, elem.(string)) + } + + req.NTP = res + } + + if check_ips, ok := d.GetOk("check_ips"); ok { + res := make([]string, 0) + for _, elem := range check_ips.([]interface{}) { + res = append(res, elem.(string)) + } + + req.CheckIPs = res + } + + if virtual, ok := d.GetOk("virtual"); ok { + req.Virtual = virtual.(bool) + } + + if desc, ok := d.GetOk("desc"); ok { + req.Description = desc.(string) + } + + if start_ip, ok := d.GetOk("start_ip"); ok { + req.StartIP = start_ip.(string) + } + + if end_ip, ok := d.GetOk("end_ip"); ok { + req.EndIP = end_ip.(string) + } + + if vnfdev_ip, ok := d.GetOk("vnfdev_ip"); ok { + req.VNFDevIP = vnfdev_ip.(string) + } + + if pre_reservations_num, ok := d.GetOk("pre_reservations_num"); ok { + req.PreReservationsNum = uint64(pre_reservations_num.(int)) + } + + if ovs_bridge, ok := d.GetOk("ovs_bridge"); ok { + req.OVSBridge = ovs_bridge.(string) + } + + log.Debugf("cloudbroker: Sent create request") + netID, err := c.CloudBroker().ExtNet().Create(ctx, req) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(netID, 10)) + log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID) + + if d.Get("excluded_ips").(*schema.Set).Len() > 0 { + ips := make([]string, 0) + + for _, ip := range d.Get("excluded_ips").(*schema.Set).List() { + ips = append(ips, ip.(string)) + } + + req := extnet.IPsExcludeRequest{ + NetID: netID, + IPs: ips, + } + + _, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req) + if err != nil { + return diag.FromErr(err) + } + } + + return resourceExtnetRead(ctx, d, m) +} + +func resourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("cloudbroker: resourceExtnetRead called with id %s", d.Id()) + recNet, err := utilityExtnetCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + flattenRecordExtnet(d, recNet) + + return nil +} + +func resourceExtnetUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("cloudbroker: resourceExtnetUpdate called with id %s", d.Id()) + c := m.(*controller.ControllerCfg) + + recNet, err := utilityExtnetCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + if err := handleBasicUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + + if d.HasChange("enable") { + if err := handleEnableUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("default_qos") { + if err := handleDefaultQOSUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("dns") { + if err := handleDNSUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("ntp") { + if err := handleNTPUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("set_default") { + if err := handleSetDefault(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("excluded_ips") { + if err := handleExcludedIPsUpdate(ctx, d, c, recNet); err != nil { + return diag.FromErr(err) + } + } + + return resourceExtnetRead(ctx, d, m) +} + +func resourceExtnetDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("cloudbroker: resourceExtnetDelete called with id %s", d.Id()) + c := m.(*controller.ControllerCfg) + + netId, _ := strconv.ParseUint(d.Id(), 10, 64) + req := extnet.DestroyRequest{NetID: netId} + + _, err := c.CloudBroker().ExtNet().Destroy(ctx, req) + if err != nil { + return diag.FromErr(err) + } + log.Debugf("cloudbroker: successfully destroyed extnet with id %s", d.Id()) + + return nil +} + +func resourceExtnetSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "External network name", + }, + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "Grid (platform) ID", + }, + "ipcidr": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "IP network CIDR", + }, + "vlan_id": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + Description: "VLAN ID", + }, + "gateway": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "External network gateway IP address", + }, + "dns": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of DNS addresses", + }, + "ntp": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of NTP addresses", + }, + "check_ips": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "IPs to check network availability", + }, + "virtual": { + Type: schema.TypeBool, + Optional: true, + Description: "If true - platform DHCP server will not be created", + }, + "desc": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional description", + }, + "start_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Start of IP range to be explicitly included", + }, + "end_ip": { + Type: schema.TypeString, + Optional: true, + Description: "End of IP range to be explicitly included", + }, + "vnfdev_ip": { + Type: schema.TypeString, + Optional: true, + Description: "IP to create VNFDev with", + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Number of pre created reservations", + }, + "ovs_bridge": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "OpenvSwith bridge name for ExtNet connection", + }, + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Disable/Enable extnet", + }, + "set_default": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Set current extnet as default (can not be undone)", + }, + "excluded_ips": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "IPs to exclude in current extnet pool", + }, + "default_qos": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "excluded": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "prefix": { + Type: schema.TypeInt, + Computed: true, + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func ResourceExtnetCB() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: resourceExtnetRead, + CreateContext: resourceExtnetCreate, + UpdateContext: resourceExtnetUpdate, + DeleteContext: resourceExtnetDelete, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout300s, + Create: &constants.Timeout300s, + Update: &constants.Timeout300s, + Delete: &constants.Timeout300s, + Default: &constants.Timeout300s, + }, + + Schema: resourceExtnetSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/extnet/utility_extnet.go b/internal/service/cloudbroker/extnet/utility_extnet.go new file mode 100644 index 0000000..383ba93 --- /dev/null +++ b/internal/service/cloudbroker/extnet/utility_extnet.go @@ -0,0 +1,288 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +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. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package extnet + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" +) + +func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + old_set, new_set := d.GetChange("excluded_ips") + + detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set)) + if detach_set.Len() > 0 { + ips := make([]string, 0) + for _, detach_ip := range detach_set.List() { + ips = append(ips, detach_ip.(string)) + } + + log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len()) + req := extnet.IPsIncludeRequest{ + NetID: recNet.ID, + IPs: ips, + } + + _, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req) + if err != nil { + return err + } + } + + attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set)) + if attach_set.Len() > 0 { + ips := make([]string, 0) + for _, attach_ip := range attach_set.List() { + ips = append(ips, attach_ip.(string)) + } + + log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID) + req := extnet.IPsExcludeRequest{ + NetID: recNet.ID, + IPs: ips, + } + + _, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req) + if err != nil { + return err + } + } + + return nil +} + +func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + set_default := d.Get("set_default").(bool) + if set_default && recNet.Default == false { + req := extnet.SetDefaultRequest{ + NetID: recNet.ID, + } + + _, err := c.CloudBroker().ExtNet().SetDefault(ctx, req) + if err != nil { + return err + } + } + + return nil +} + +func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + doBasicUpdate := false + basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID} + + if d.HasChange("name") { + basiUpdateReq.Name = d.Get("name").(string) + doBasicUpdate = true + } + if d.HasChange("desc") { + basiUpdateReq.Description = d.Get("desc").(string) + doBasicUpdate = true + } + + if doBasicUpdate { + _, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq) + if err != nil { + return err + } + } + + return nil +} + +func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + enable := d.Get("enable").(bool) + if enable { + if recNet.Status == status.Disabled { + req := extnet.EnableRequest{NetID: recNet.ID} + _, err := c.CloudBroker().ExtNet().Enable(ctx, req) + if err != nil { + return err + } + } + } else { + if recNet.Status == status.Enabled { + req := extnet.DisableRequest{NetID: recNet.ID} + _, err := c.CloudBroker().ExtNet().Disable(ctx, req) + if err != nil { + return err + } + } + } + return nil +} + +func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{}) + + req := extnet.DefaultQOSUpdateRequest{ + NetID: recNet.ID, + IngressRate: uint64(qos["in_rate"].(int)), + IngressBurst: uint64(qos["in_burst"].(int)), + EgressRate: uint64(qos["e_rate"].(int)), + } + + _, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req) + if err != nil { + return err + } + + return nil +} + +func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + changed_list := d.Get("ntp").([]interface{}) + + ntp_list := make([]string, 0) + for _, ntp_address := range changed_list { + ntp_list = append(ntp_list, ntp_address.(string)) + } + + req := extnet.NTPApplyRequest{ + NetID: recNet.ID, + NTPList: ntp_list, + } + + _, err := c.CloudBroker().ExtNet().NTPApply(ctx, req) + if err != nil { + return err + } + + return nil +} + +func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error { + changed_list := d.Get("dns").([]interface{}) + + dns_list := make([]string, 0) + for _, dns_address := range changed_list { + dns_list = append(dns_list, dns_address.(string)) + } + + req := extnet.DNSApplyRequest{ + NetID: recNet.ID, + DNSList: dns_list, + } + + _, err := c.CloudBroker().ExtNet().DNSApply(ctx, req) + if err != nil { + return err + } + + return nil +} + +func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) { + c := m.(*controller.ControllerCfg) + + return c.CloudBroker().ExtNet().GetDefault(ctx) +} + +func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) { + c := m.(*controller.ControllerCfg) + + req := extnet.ListRequest{} + + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if network, ok := d.GetOk("network"); ok { + req.Network = network.(string) + } + + if vlan_id, ok := d.GetOk("vlan_id"); ok { + req.VLANID = uint64(vlan_id.(int)) + } + + if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok { + req.VNFDevID = uint64(vnfdev_id.(int)) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + res, err := c.CloudBroker().ExtNet().List(ctx, req) + if err != nil { + return nil, err + } + + return res, nil +} + +func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) { + c := m.(*controller.ControllerCfg) + var netId uint64 + + if id, ok := d.GetOk("net_id"); ok { + netId = uint64(id.(int)) + } else { + parsed, _ := strconv.ParseUint(d.Id(), 10, 64) + netId = parsed + } + + req := extnet.GetRequest{ + NetID: netId, + } + + res, err := c.CloudBroker().ExtNet().Get(ctx, req) + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/internal/service/cloudbroker/grid/flattens.go b/internal/service/cloudbroker/grid/flattens.go index 349c699..e980c35 100644 --- a/internal/service/cloudbroker/grid/flattens.go +++ b/internal/service/cloudbroker/grid/flattens.go @@ -14,9 +14,9 @@ func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) { d.Set("id", grid.ID) } -func flattenGridList(gl grid.ListGrids) []map[string]interface{} { +func flattenGridList(gl *grid.ListGrids) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range gl { + for _, item := range gl.Data { temp := map[string]interface{}{ "name": item.Name, "flag": item.Flag, diff --git a/internal/service/cloudbroker/grid/utility_grid_list.go b/internal/service/cloudbroker/grid/utility_grid_list.go index 3f48a88..0bde99c 100644 --- a/internal/service/cloudbroker/grid/utility_grid_list.go +++ b/internal/service/cloudbroker/grid/utility_grid_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (grid.ListGrids, error) { +func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.ListGrids, error) { c := m.(*controller.ControllerCfg) req := grid.ListRequest{} diff --git a/internal/service/cloudbroker/image/data_source_image_list.go b/internal/service/cloudbroker/image/data_source_image_list.go index 5b8f28c..379526b 100644 --- a/internal/service/cloudbroker/image/data_source_image_list.go +++ b/internal/service/cloudbroker/image/data_source_image_list.go @@ -59,11 +59,6 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema { Optional: true, Description: "filter images by storage endpoint provider ID", }, - "shared_with": { - Type: schema.TypeInt, - Optional: true, - Description: "filter images by account ID availability", - }, "page": { Type: schema.TypeInt, Optional: true, diff --git a/internal/service/cloudbroker/image/flattens.go b/internal/service/cloudbroker/image/flattens.go index d72f319..1652240 100644 --- a/internal/service/cloudbroker/image/flattens.go +++ b/internal/service/cloudbroker/image/flattens.go @@ -82,9 +82,9 @@ func flattenHistory(history []image.History) []map[string]interface{} { return temp } -func flattenImageList(il image.ListImages) []map[string]interface{} { +func flattenImageList(il *image.ListImages) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range il { + for _, item := range il.Data { temp := map[string]interface{}{ "name": item.Name, "url": item.URL, @@ -130,9 +130,9 @@ func flattenImageList(il image.ListImages) []map[string]interface{} { return res } -func flattenImageListStacks(_ *schema.ResourceData, stack image.ListStacks) []map[string]interface{} { +func flattenImageListStacks(_ *schema.ResourceData, stack *image.ListStacks) []map[string]interface{} { temp := make([]map[string]interface{}, 0) - for _, item := range stack { + for _, item := range stack.Data { t := map[string]interface{}{ "api_url": item.APIURL, "api_key": item.APIKey, diff --git a/internal/service/cloudbroker/image/utility_image_list.go b/internal/service/cloudbroker/image/utility_image_list.go index e6f4de6..30e8551 100644 --- a/internal/service/cloudbroker/image/utility_image_list.go +++ b/internal/service/cloudbroker/image/utility_image_list.go @@ -41,16 +41,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListImages, error) { +func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) { c := m.(*controller.ControllerCfg) req := image.ListRequest{} if sepId, ok := d.GetOk("sep_id"); ok { req.SepID = uint64(sepId.(int)) } - if sharedWith, ok := d.GetOk("shared_with"); ok { - req.SharedWith = uint64(sharedWith.(int)) - } if page, ok := d.GetOk("page"); ok { req.Page = uint64(page.(int)) diff --git a/internal/service/cloudbroker/image/utility_image_list_stacks.go b/internal/service/cloudbroker/image/utility_image_list_stacks.go index 582221a..8ee11fe 100644 --- a/internal/service/cloudbroker/image/utility_image_list_stacks.go +++ b/internal/service/cloudbroker/image/utility_image_list_stacks.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListStacks, error) { +func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListStacks, error) { c := m.(*controller.ControllerCfg) req := image.ListStacksRequest{ ImageID: uint64(d.Get("image_id").(int)), diff --git a/internal/service/cloudbroker/kvmvm/resource_compute.go b/internal/service/cloudbroker/kvmvm/resource_compute.go index 2b0439f..ef728f4 100644 --- a/internal/service/cloudbroker/kvmvm/resource_compute.go +++ b/internal/service/cloudbroker/kvmvm/resource_compute.go @@ -75,14 +75,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf reqPPC.RAM = uint64(d.Get("ram").(int)) reqPPC.ImageID = uint64(d.Get("image_id").(int)) reqPPC.BootDisk = uint64(d.Get("boot_disk_size").(int)) - reqPPC.NetType = "NONE" reqPPC.Start = false reqX86.CPU = uint64(d.Get("cpu").(int)) reqX86.RAM = uint64(d.Get("ram").(int)) reqX86.ImageID = uint64(d.Get("image_id").(int)) reqX86.BootDisk = uint64(d.Get("boot_disk_size").(int)) - reqX86.NetType = "NONE" reqX86.Start = false argVal, argSet := d.GetOk("description") diff --git a/internal/service/cloudbroker/kvmvm/utility_compute.go b/internal/service/cloudbroker/kvmvm/utility_compute.go index 619b705..9e34c28 100644 --- a/internal/service/cloudbroker/kvmvm/utility_compute.go +++ b/internal/service/cloudbroker/kvmvm/utility_compute.go @@ -269,8 +269,8 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m return nil, err } - log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList)) - for index, item := range computeList { + log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList.Data)) + for index, item := range computeList.Data { // need to match Compute by name, skip Computes with the same name in DESTROYED satus if item.Name == computeName.(string) && item.Status != "DESTROYED" { log.Debugf("utilityComputeCheckPresence: index %d, matched name %s", index, item.Name) diff --git a/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go index e5496c1..c945f26 100644 --- a/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go @@ -42,9 +42,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" ) -func flattenPcideviceList(pl pcidevice.ListPCIDevices) []map[string]interface{} { +func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range pl { + for _, item := range pl.Data { temp := map[string]interface{}{ "ckey": item.CKey, "meta": flattens.FlattenMeta(item.Meta), diff --git a/internal/service/cloudbroker/pcidevice/utility_pcidevice.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go index 1dea551..fb006cc 100644 --- a/internal/service/cloudbroker/pcidevice/utility_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go @@ -53,7 +53,7 @@ func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData, pcideviceId = id } - for _, pd := range pcideviceList { + for _, pd := range pcideviceList.Data { if pd.ID == pcideviceId { return &pd, nil } diff --git a/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go index 09aa578..de7c5d9 100644 --- a/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go @@ -38,10 +38,12 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (pcidevice.ListPCIDevices, error) { +func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (*pcidevice.ListPCIDevices, error) { c := m.(*controller.ControllerCfg) - pcideviceList, err := c.CloudBroker().PCIDevice().List(ctx) + req := pcidevice.ListRequest{} + + pcideviceList, err := c.CloudBroker().PCIDevice().List(ctx, req) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/rg/data_source_rg_list.go b/internal/service/cloudbroker/rg/data_source_rg_list.go index 3446668..1acca0c 100644 --- a/internal/service/cloudbroker/rg/data_source_rg_list.go +++ b/internal/service/cloudbroker/rg/data_source_rg_list.go @@ -41,9 +41,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenRgList(rgl rg.ListRG) []map[string]interface{} { +func flattenRgList(rgl *rg.ListRG) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, rg := range rgl { + for _, rg := range rgl.Data { temp := map[string]interface{}{ "account_id": rg.AccountID, "account_name": rg.AccountName, diff --git a/internal/service/cloudbroker/rg/utility_rg.go b/internal/service/cloudbroker/rg/utility_rg.go index 949b139..1b75486 100644 --- a/internal/service/cloudbroker/rg/utility_rg.go +++ b/internal/service/cloudbroker/rg/utility_rg.go @@ -84,8 +84,8 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m return nil, err } - log.Debugf("utilityResgroupCheckPresence: traversing decoded Json of length %d", len(model)) - for index, item := range model { + log.Debugf("utilityResgroupCheckPresence: traversing decoded Json of length %d", len(model.Data)) + for index, item := range model.Data { // match by RG name & account ID if item.Name == rgName.(string) && item.AccountID == uint64(d.Get("account_id").(int)) { log.Debugf("utilityResgroupCheckPresence: match RG name %s / ID %d, account ID %d at index %d", diff --git a/internal/service/cloudbroker/rg/utility_rg_list.go b/internal/service/cloudbroker/rg/utility_rg_list.go index 9bb3c07..249d8df 100644 --- a/internal/service/cloudbroker/rg/utility_rg_list.go +++ b/internal/service/cloudbroker/rg/utility_rg_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListRG, error) { +func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListRG, error) { c := m.(*controller.ControllerCfg) req := rg.ListRequest{} diff --git a/internal/service/cloudbroker/sep/data_source_sep_list.go b/internal/service/cloudbroker/sep/data_source_sep_list.go index 4b03f7b..c7192a1 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_list.go +++ b/internal/service/cloudbroker/sep/data_source_sep_list.go @@ -43,9 +43,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" ) -func flattenSepList(sl sep.ListSEP) []map[string]interface{} { +func flattenSepList(sl *sep.ListSEP) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, item := range sl { + for _, item := range sl.Data { data, _ := json.Marshal(item.Config) temp := map[string]interface{}{ "ckey": item.CKey, diff --git a/internal/service/cloudbroker/sep/utility_sep_list.go b/internal/service/cloudbroker/sep/utility_sep_list.go index 462537f..cb43c04 100644 --- a/internal/service/cloudbroker/sep/utility_sep_list.go +++ b/internal/service/cloudbroker/sep/utility_sep_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (sep.ListSEP, error) { +func utilitySepListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.ListSEP, error) { c := m.(*controller.ControllerCfg) req := sep.ListRequest{} diff --git a/internal/service/cloudbroker/vgpu/utility_vgpu.go b/internal/service/cloudbroker/vgpu/utility_vgpu.go index 5fb5f5e..516306f 100644 --- a/internal/service/cloudbroker/vgpu/utility_vgpu.go +++ b/internal/service/cloudbroker/vgpu/utility_vgpu.go @@ -65,7 +65,7 @@ func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m int return nil, err } - for _, vgpu := range vgpus { + for _, vgpu := range vgpus.Data { if vgpu.ID == vgpuId { return &vgpu, nil } diff --git a/internal/service/cloudbroker/vins/data_source_vins_list.go b/internal/service/cloudbroker/vins/data_source_vins_list.go index b39aadc..806ec36 100644 --- a/internal/service/cloudbroker/vins/data_source_vins_list.go +++ b/internal/service/cloudbroker/vins/data_source_vins_list.go @@ -41,9 +41,9 @@ import ( "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" ) -func flattenVinsList(vl vins.ListVINS) []map[string]interface{} { +func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} { res := make([]map[string]interface{}, 0) - for _, v := range vl { + for _, v := range vl.Data { temp := map[string]interface{}{ "account_id": v.AccountID, "account_name": v.AccountName, diff --git a/internal/service/cloudbroker/vins/utility_vins_list.go b/internal/service/cloudbroker/vins/utility_vins_list.go index b938e0a..3495931 100644 --- a/internal/service/cloudbroker/vins/utility_vins_list.go +++ b/internal/service/cloudbroker/vins/utility_vins_list.go @@ -41,7 +41,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) { +func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) { c := m.(*controller.ControllerCfg) req := vins.ListRequest{} diff --git a/internal/status/status.go b/internal/status/status.go index 9fb4f8d..223d0da 100644 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -53,6 +53,7 @@ var ( // - BasicService // - K8s Cluster // - Load Balancer + // - cloudbroker/extnet Enabled Status = "ENABLED" // Enabling in process @@ -73,6 +74,7 @@ var ( // - BasicService // - K8s Cluster // - Load Balancer + // - cloudbroker/extnet Disabled Status = "DISABLED" // Disabling in process diff --git a/samples/cloudapi/data_k8ci_list/main.tf b/samples/cloudapi/data_k8ci_list/main.tf new file mode 100644 index 0000000..0e7d0d2 --- /dev/null +++ b/samples/cloudapi/data_k8ci_list/main.tf @@ -0,0 +1,77 @@ +/* +Пример использования +Получение информации о k8ci +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_k8ci_list" "k8ci_list" { + #Поиск по ID + #опциональный параметр + #тип - число + by_id = 12 + + #Поиск по наименованию + #опциональный параметр + #тип - строка + name = "name" + + #Поиск по статус + #опциональный параметр + #тип - строка + status = "status" + + #Поиск по worker драйверу + #опциональный параметр + #тип - строка + worker_driver = "wdriver" + + #Поиск по master драйверу + #опциональный параметр + #тип - строка + master_driver = "wdriver" + + #Поиск по network плагину + #опциональный параметр + #тип - строка + network_plugin = "flannel" + + #Показать выключенные K8CI + #опциональный параметр + #тип - bool + include_disabled = true + + #Номер страницы + #опциональный параметр + #тип - число + page = 1 + + #Размер страницы + #опциональный параметр + #тип - число + size = 5 +} + +output "output_k8ci" { + value = data.decort_k8ci_list.k8ci_list +} diff --git a/samples/cloudapi/resource_kvmvm/initconfig.tftpl b/samples/cloudapi/resource_kvmvm/initconfig.tftpl new file mode 100644 index 0000000..587b59c --- /dev/null +++ b/samples/cloudapi/resource_kvmvm/initconfig.tftpl @@ -0,0 +1,14 @@ +{ +"users": [ + { + "groups": "users, wheel", + "name": "user", + "plain_text_passwd": "examplePassword", + "primary_group": "user", + "ssh_authorized_keys": [ + "ssh-rsa EXAMPLE%id_rsa.pub" + ], + "sudo": "ALL=(ALL) NOPASSWD:ALL" + } +] +} diff --git a/samples/cloudapi/resource_kvmvm/main.tf b/samples/cloudapi/resource_kvmvm/main.tf index ce5f9d3..b0626c2 100644 --- a/samples/cloudapi/resource_kvmvm/main.tf +++ b/samples/cloudapi/resource_kvmvm/main.tf @@ -77,6 +77,11 @@ resource "decort_kvmvm" "comp" { #тип - строка pool = "data02" + #конфигурация cloud init + #опциональный параметр + #тип - файл в формате JSON/YAML + cloud_init = file("initconfig.tftpl") + #описание compute #опциональный параметр #тип - строка @@ -332,11 +337,6 @@ resource "decort_kvmvm" "comp" { #тип - булев pin_to_stack = true - #Применяется только при создании нового экземпляра compute, игнорируется во всех остальных случаях - #опциональный параметр - #тип - строка - cloud_init = "" - #Флаг доступности компьюта для проведения с ним операций #опциональный параметр #тип - булев diff --git a/samples/cloudbroker/data_extnet/main.tf b/samples/cloudbroker/data_extnet/main.tf new file mode 100644 index 0000000..400c143 --- /dev/null +++ b/samples/cloudbroker/data_extnet/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение списка доступных дисков +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_extnet" "ex" { + # ID сети + # Обязательный параметр + # Тип - число + net_id = 13 +} + +output "ex_out" { + value = data.decort_cb_extnet.ex +} diff --git a/samples/cloudbroker/data_extnet_default/main.tf b/samples/cloudbroker/data_extnet_default/main.tf new file mode 100644 index 0000000..281ff03 --- /dev/null +++ b/samples/cloudbroker/data_extnet_default/main.tf @@ -0,0 +1,35 @@ +/* +Пример использования +Получение информации о сети по-умолчанию + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_extnet_default" "ed" { +} + +output "default_net_id_out" { + value = data.decort_cb_extnet_default.ed.net_id +} diff --git a/samples/cloudbroker/data_extnet_list/main.tf b/samples/cloudbroker/data_extnet_list/main.tf new file mode 100644 index 0000000..9ac0c2e --- /dev/null +++ b/samples/cloudbroker/data_extnet_list/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Получение списка доступных дисков +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_extnet_list" "ex_list" { + # Фильтр по имени + # Опциональный параметр + # Тип - строка + name = "test_name" + + # Фильтр по статусу + # Опциональный параметр + # Тип - строка + status = "ENABLED" +} + +output "ex_out" { + value = data.decort_cb_extnet_list.ex_list +} diff --git a/samples/cloudbroker/resource_extnet/main.tf b/samples/cloudbroker/resource_extnet/main.tf new file mode 100644 index 0000000..3a7051f --- /dev/null +++ b/samples/cloudbroker/resource_extnet/main.tf @@ -0,0 +1,68 @@ +/* +Пример использования +Получение списка доступных образов +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +# terraform { +# required_providers { +# decort = { +# version = "" +# source = "basis/decort/decort" +# } +# } +# } + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_extnet" "new_extnet" { + # Наименование внешней сети + # Обязательный параметр + # Тип - строка + name = "test_extnet" + + # ID платформы + # Обязательный параметр + # Тип - число + gid = 500 + + # CIDR + # Обязательный параметр + # Тип - строка + ipcidr = "192.168.0.0/24" + + # ID виртуальной локальной сети + # Обязательный параметр + # Тип - число + vlan_id = 111 + + # Список DNS адресов + # Опциональный параметр + # Тип - массив строк + dns = ["8.8.8.8", "9.9.9.9"] + + # Описание + # Опциональный параметр + # Тип - строка + desc = "test desc" + + # Включение/Выключение внешней сети + # Опциональный параметр (default = true) + # Тип - булев + enable = true + + # Список исключенных IP адресов + # Опциональный параметр + # Тип - массив строк + excluded_ips = ["192.168.0.4", "192.168.0.5"] +} diff --git a/scripts/install.bat b/scripts/install.bat new file mode 100644 index 0000000..70b508b --- /dev/null +++ b/scripts/install.bat @@ -0,0 +1,87 @@ +:: Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +:: Authors: +:: Tim Tkachev, +:: +:: 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. +:: +:: Installer uses basis/decort/decort as path value to provider executable. + +@echo off + +FOR %%f IN (bin\*) DO ( + if "%%~xf" == ".exe" ( + set filename=bin\%%~nf + ) else ( + set filename=%%f + ) +) + +for /F "tokens=1,2,3,4 delims=_" %%a in ("%filename%") do ( + set version=%%b + set os=%%c + set arch=%%d +) + +if "%os%" neq "windows" ( + echo Unable to find provider executable, is it moved or renamed? + pause + exit /b +) + +set provider_path=%appdata%\terraform.d\plugins\basis\decort\decort\%version%\%os%_%arch%\ + +if exist %provider_path% ( + echo Provider directory already exists, checking for decort provider executable.. + dir /b /s /a "%provider_path%" | findstr .>nul || ( + copy %filename% %provider_path%\terraform-provider-decort.exe + if errorlevel 1 ( + pause + exit /b + ) + call :print_success + pause + exit /b + ) + echo DECORT provider version %version% is already installed. Exiting. + pause + exit /b +) else ( + echo Creating provider directory.. + mkdir %provider_path% + if errorlevel 1 ( + pause + exit /b + ) + copy %filename% %provider_path%\terraform-provider-decort.exe + if errorlevel 1 ( + pause + exit /b + ) + call :print_success + pause + exit /b +) + +:print_success +echo DECORT provider version %version% has been successfully installed +echo: +echo Copy this provider configuration to main.tf file: +echo terraform { +echo required_providers { +echo decort = { +echo version = "%version%" +echo source = "basis/decort/decort" +echo } +echo } +echo } +goto:eof diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..a800f19 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,68 @@ +# Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +# Authors: +# Tim Tkachev, +# +# 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. +# +# Installer uses basis/decort/decort as path value to provider binary. + +set -e + +filename="bin"/* + +version=$(basename $filename | cut -d '_' -f 2) +os=$(basename $filename | cut -d '_' -f 3) +arch=$(basename $filename | cut -d '_' -f 4) + +plugins_dir=~/.terraform.d/plugins/ +provider_path=basis/decort/decort/$version/$os\_$arch/ + +print_success () { + echo "DECORT provider version $version has been successfully installed" + echo "\n" + echo "Copy this provider configuration to main.tf file" + echo "terraform {" + echo " required_providers {" + echo " decort = {" + echo " version = \"$version\"" + echo " source = \"basis/decort/decort\"" + echo " }" + echo " }" + echo "}" +} + +install () { + if [[ -d $plugins_dir$provider_path ]] + then + echo "Provider directory already exists, checking for decort provider executable.." + if [[ ! "$(ls -A $plugins_dir$provider_path)" ]]; then + cp bin/terraform-provider-decort_$version\_$os\_$arch $plugins_dir$provider_path/terraform-provider-decort + print_success + else + echo "DECORT provider version $version is already installed. Exiting.." + fi + else + echo "Creating provider directory.." + mkdir -p $plugins_dir/$provider_path + cp bin/terraform-provider-decort_$version\_$os\_$arch $plugins_dir$provider_path/terraform-provider-decort + print_success + fi +} + +case "$OSTYPE" in + linux*) install ;; + darwin*) install ;; + bsd*) install ;; + msys*) echo "Use bat script to install DECORT provider on Windows machine." ;; + cygwin*) echo "Use bat script to install DECORT provider on Windows machine." ;; +esac