Migrate to sdkv2 and project structure refactoring
This commit is contained in:
87
internal/provider/data_sources_map.go
Normal file
87
internal/provider/data_sources_map.go
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/account"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/bservice"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/disks"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/extnet"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/rg"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/snapshot"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vgpu"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vins"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/grid"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/image"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/sep"
|
||||
)
|
||||
|
||||
func NewDataSourcesMap() map[string]*schema.Resource {
|
||||
return map[string]*schema.Resource{
|
||||
"decort_account": account.DataSourceAccount(),
|
||||
"decort_resgroup": rg.DataSourceResgroup(),
|
||||
// "decort_kvmvm": dataSourceCompute(),
|
||||
"decort_image": image.DataSourceImage(),
|
||||
"decort_disk": disks.DataSourceDisk(),
|
||||
"decort_vins": vins.DataSourceVins(),
|
||||
"decort_grid": grid.DataSourceGrid(),
|
||||
"decort_grid_list": grid.DataSourceGridList(),
|
||||
"decort_image_list": image.DataSourceImageList(),
|
||||
"decort_image_list_stacks": image.DataSourceImageListStacks(),
|
||||
"decort_snapshot_list": snapshot.DataSourceSnapshotList(),
|
||||
"decort_vgpu": vgpu.DataSourceVGPU(),
|
||||
"decort_pcidevice": pcidevice.DataSourcePcidevice(),
|
||||
"decort_pcidevice_list": pcidevice.DataSourcePcideviceList(),
|
||||
"decort_sep_list": sep.DataSourceSepList(),
|
||||
"decort_sep": sep.DataSourceSep(),
|
||||
"decort_sep_consumption": sep.DataSourceSepConsumption(),
|
||||
"decort_sep_disk_list": sep.DataSourceSepDiskList(),
|
||||
"decort_sep_config": sep.DataSourceSepConfig(),
|
||||
"decort_sep_pool": sep.DataSourceSepPool(),
|
||||
"decort_disk_list": disks.DataSourceDiskList(),
|
||||
"decort_rg_list": rg.DataSourceRgList(),
|
||||
"decort_account_list": account.DataSourceAccountList(),
|
||||
"decort_account_computes_list": account.DataSourceAccountComputesList(),
|
||||
"decort_account_disks_list": account.DataSourceAccountDisksList(),
|
||||
"decort_account_vins_list": account.DataSourceAccountVinsList(),
|
||||
"decort_account_audits_list": account.DataSourceAccountAuditsList(),
|
||||
"decort_account_rg_list": account.DataSourceAccountRGList(),
|
||||
"decort_account_consumed_units": account.DataSourceAccountConsumedUnits(),
|
||||
"decort_account_consumed_units_by_type": account.DataSourceAccountConsumedUnitsByType(),
|
||||
"decort_account_reserved_units": account.DataSourceAccountReservedUnits(),
|
||||
"decort_account_templates_list": account.DataSourceAccountTemplatessList(),
|
||||
"decort_account_deleted_list": account.DataSourceAccountDeletedList(),
|
||||
"decort_account_flipgroups_list": account.DataSourceAccountFlipGroupsList(),
|
||||
"decort_bservice_list": bservice.DataSourceBasicServiceList(),
|
||||
"decort_bservice": bservice.DataSourceBasicService(),
|
||||
"decort_bservice_snapshot_list": bservice.DataSourceBasicServiceSnapshotList(),
|
||||
"decort_bservice_group": bservice.DataSourceBasicServiceGroup(),
|
||||
"decort_bservice_deleted_list": bservice.DataSourceBasicServiceDeletedList(),
|
||||
"decort_extnet_list": extnet.DataSourceExtnetList(),
|
||||
"decort_extnet_computes_list": extnet.DataSourceExtnetComputesList(),
|
||||
"decort_extnet": extnet.DataSourceExtnet(),
|
||||
"decort_extnet_default": extnet.DataSourceExtnetDefault(),
|
||||
"decort_vins_list": vins.DataSourceVinsList(),
|
||||
// "decort_pfw": dataSourcePfw(),
|
||||
}
|
||||
|
||||
}
|
||||
134
internal/provider/provider.go
Normal file
134
internal/provider/provider.go
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
|
||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/location"
|
||||
)
|
||||
|
||||
func Provider() *schema.Provider {
|
||||
return &schema.Provider{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"authenticator": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: StateFuncToLower,
|
||||
ValidateFunc: validation.StringInSlice([]string{"oauth2", "legacy", "jwt"}, true), // ignore case while validating
|
||||
Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'oauth2', 'legacy' or 'jwt'.",
|
||||
},
|
||||
|
||||
"oauth2_url": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
StateFunc: StateFuncToLower,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil),
|
||||
Description: "OAuth2 application URL in 'oauth2' authentication mode.",
|
||||
},
|
||||
|
||||
"controller_url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: StateFuncToLower,
|
||||
Description: "URL of DECORT Cloud controller to use. API calls will be directed to this URL.",
|
||||
},
|
||||
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_USER", nil),
|
||||
Description: "User name for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_PASSWORD", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil),
|
||||
Description: "Application ID to access DECORT cloud API in 'oauth2' authentication mode.",
|
||||
},
|
||||
|
||||
"app_secret": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil),
|
||||
Description: "Application secret to access DECORT cloud API in 'oauth2' authentication mode.",
|
||||
},
|
||||
|
||||
"jwt": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_JWT", nil),
|
||||
Description: "JWT to access DECORT cloud API in 'jwt' authentication mode.",
|
||||
},
|
||||
|
||||
"allow_unverified_ssl": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!",
|
||||
},
|
||||
},
|
||||
|
||||
ResourcesMap: NewRersourcesMap(),
|
||||
|
||||
DataSourcesMap: NewDataSourcesMap(),
|
||||
|
||||
ConfigureFunc: providerConfigure,
|
||||
}
|
||||
}
|
||||
|
||||
func StateFuncToLower(argval interface{}) string {
|
||||
return strings.ToLower(argval.(string))
|
||||
}
|
||||
|
||||
func StateFuncToUpper(argval interface{}) string {
|
||||
return strings.ToUpper(argval.(string))
|
||||
}
|
||||
|
||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
decsController, err := controller.ControllerConfigure(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
gridId, err := location.UtilityLocationGetDefaultGridID(decsController)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if gridId == 0 {
|
||||
return nil, fmt.Errorf("providerConfigure: invalid default Grid ID = 0")
|
||||
}
|
||||
|
||||
return decsController, nil
|
||||
}
|
||||
58
internal/provider/resource_map.go
Normal file
58
internal/provider/resource_map.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/account"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/bservice"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/disks"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/k8s"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/pfw"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/rg"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/snapshot"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vins"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/image"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
|
||||
"github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/sep"
|
||||
)
|
||||
|
||||
func NewRersourcesMap() map[string]*schema.Resource {
|
||||
return map[string]*schema.Resource{
|
||||
"decort_resgroup": rg.ResourceResgroup(),
|
||||
// "decort_kvmvm": resourceCompute(),
|
||||
"decort_disk": disks.ResourceDisk(),
|
||||
"decort_vins": vins.ResourceVins(),
|
||||
"decort_pfw": pfw.ResourcePfw(),
|
||||
"decort_k8s": k8s.ResourceK8s(),
|
||||
"decort_k8s_wg": k8s.ResourceK8sWg(),
|
||||
"decort_image": image.ResourceImage(),
|
||||
"decort_virtual_image": image.ResourceVirtualImage(),
|
||||
"decort_cdrom_image": image.ResourceCDROMImage(),
|
||||
"decort_delete_images": image.ResourceDeleteImages(),
|
||||
"decort_snapshot": snapshot.ResourceSnapshot(),
|
||||
"decort_pcidevice": pcidevice.ResourcePcidevice(),
|
||||
"decort_sep": sep.ResourceSep(),
|
||||
"decort_sep_config": sep.ResourceSepConfig(),
|
||||
"decort_account": account.ResourceAccount(),
|
||||
"decort_bservice": bservice.ResourceBasicService(),
|
||||
"decort_bservice_group": bservice.ResourceBasicServiceGroup(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user