parent
							
								
									9cf150437d
								
							
						
					
					
						commit
						caf7213bca
					
				| @ -1,10 +1,13 @@ | ||||
| ## Version 4.0.2 | ||||
| ## Version 4.1.0 | ||||
| 
 | ||||
| ## Features | ||||
| - Added new data source decort_k8s_computes used to list all VMs in k8s cluster | ||||
| - Added the ability to manipulate worker-groups inside resource decort_k8s | ||||
| 	- Added new required field name to workers block | ||||
| 	- Added new optional fields (labels, annotations, taints) to workers block | ||||
| - Added cloudapi/flipgroup functionality to provider: | ||||
| 	- decort_flipgroup data source - read info about created flipgroup | ||||
| 	- decort_flipgroup_list data source - read info about all created flipgroups | ||||
| 	- decort_flipgroup resource - manage flipgroup instance | ||||
| 
 | ||||
| ## Bug Fix | ||||
| - Fixed incorrect state reading in resource decort_k8s | ||||
| ## Bug Fixes | ||||
| - Increased resource_vins timeouts | ||||
| - Automated compute start/stop when managing networks | ||||
| - Removed reading of default generated label "workersGroupName=" in resource_k8s, resource_k8s_wg in tfstate | ||||
| - Updated samples for flipgroups, image, pfw, k8s resources and data sources | ||||
|  | ||||
| @ -0,0 +1,191 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| Tim Tkachev, <tvtkachev@basistech.ru> | ||||
| 
 | ||||
| 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 flipgroup | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	"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 dataSourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	fg, err := utilityFlipgroupCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenFlipgroup(d, fg) | ||||
| 	d.SetId(fmt.Sprint(fg.ID)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"flipgroup_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "Flipgroupd ID", | ||||
| 		}, | ||||
| 		"account_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"account_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"client_ids": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &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, | ||||
| 		}, | ||||
| 		"conn_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"conn_type": { | ||||
| 			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, | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"ip": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"net_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"net_type": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"network": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_name": { | ||||
| 			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, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func DataSourceFlipgroup() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceFlipgroupRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout180s, | ||||
| 			Default: &constants.Timeout180s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceFlipgroupSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,210 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| Tim Tkachev, <tvtkachev@basistech.ru> | ||||
| 
 | ||||
| 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 flipgroup | ||||
| 
 | ||||
| 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 dataSourceFlipgroupList(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	fg_list, err := utilityFlipgroupListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 
 | ||||
| 	d.Set("items", flattenFlipgroupList(fg_list)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"flipgroup_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"client_ids": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &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, | ||||
| 					}, | ||||
| 					"conn_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"conn_type": { | ||||
| 						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, | ||||
| 					}, | ||||
| 					"gid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"milestones": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"net_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"net_type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"ip": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"network": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_name": { | ||||
| 						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, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func DataSourceFlipGroupList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceFlipgroupList, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout180s, | ||||
| 			Default: &constants.Timeout180s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceFlipgroupListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,107 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| Tim Tkachev, <tvtkachev@basistech.ru> | ||||
| 
 | ||||
| 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 flipgroup | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup" | ||||
| ) | ||||
| 
 | ||||
| func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) { | ||||
| 	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) | ||||
| 	d.Set("flipgroup_id", fg.ID) | ||||
| 	d.Set("ip", fg.IP) | ||||
| 	d.Set("milestones", fg.Milestones) | ||||
| 	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{} { | ||||
| 	res := make([]map[string]interface{}, 0) | ||||
| 	for _, fg := range fg_list { | ||||
| 		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, | ||||
| 			"flipgroup_id": fg.ID, | ||||
| 			"ip":           fg.IP, | ||||
| 			"milestones":   fg.Milestones, | ||||
| 			"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) | ||||
| 	} | ||||
| 
 | ||||
| 	return res | ||||
| } | ||||
| @ -0,0 +1,309 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| Tim Tkachev, <tvtkachev@basistech.ru> | ||||
| 
 | ||||
| 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 flipgroup | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| ) | ||||
| 
 | ||||
| func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceFlipgroupCreate called with name: %s, accountID %v", d.Get("name").(string), d.Get("account_id").(int)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := flipgroup.CreateRequest{ | ||||
| 		AccountID:   uint64(d.Get("account_id").(int)), | ||||
| 		Name:        d.Get("name").(string), | ||||
| 		NetType:     d.Get("net_type").(string), | ||||
| 		NetID:       uint64(d.Get("net_id").(int)), | ||||
| 		ClientType:  d.Get("client_type").(string), | ||||
| 		IP:          d.Get("ip").(string), | ||||
| 		Description: d.Get("desc").(string), | ||||
| 	} | ||||
| 
 | ||||
| 	resp, err := c.CloudAPI().FLIPGroup().Create(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(fmt.Sprint(resp.ID)) | ||||
| 
 | ||||
| 	var warnings dc.Warnings | ||||
| 
 | ||||
| 	if client_ids, ok := d.GetOk("client_ids"); ok { | ||||
| 		casted := client_ids.([]interface{}) | ||||
| 		addComputesAfterCreation(ctx, &warnings, c, casted, resp.ID) | ||||
| 	} | ||||
| 
 | ||||
| 	defer resourceFlipgroupRead(ctx, d, m) | ||||
| 	return warnings.Get() | ||||
| } | ||||
| 
 | ||||
| func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	fg, err := utilityFlipgroupCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenFlipgroup(d, fg) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceFlipgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceFlipgroupUpdate called with id: %v", d.Get("flipgroup_id").(int)) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	fg, err := utilityFlipgroupCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	var warnings dc.Warnings | ||||
| 	basicUpdate := false | ||||
| 	req := flipgroup.EditRequest{FLIPGroupID: fg.ID} | ||||
| 
 | ||||
| 	if d.HasChange("desc") { | ||||
| 		req.Description = d.Get("desc").(string) | ||||
| 		basicUpdate = true | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("name") { | ||||
| 		req.Name = d.Get("name").(string) | ||||
| 		basicUpdate = true | ||||
| 	} | ||||
| 
 | ||||
| 	if basicUpdate { | ||||
| 		_, err := c.CloudAPI().FLIPGroup().Edit(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("client_ids") { | ||||
| 		handleClientIDsUpdate(ctx, d, c, fg, &warnings) | ||||
| 	} | ||||
| 
 | ||||
| 	defer resourceFlipgroupRead(ctx, d, m) | ||||
| 	return warnings.Get() | ||||
| } | ||||
| 
 | ||||
| func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceFlipgroupDelete called with id: %v", d.Get("flipgroup_id").(int)) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	fg, err := utilityFlipgroupCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	req := flipgroup.DeleteRequest{ | ||||
| 		FLIPGroupID: fg.ID, | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudAPI().FLIPGroup().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceFlipgroupSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "Account ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Flipgroup name", | ||||
| 		}, | ||||
| 		"net_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "EXTNET or ViNS ID", | ||||
| 		}, | ||||
| 		"net_type": { | ||||
| 			Type:         schema.TypeString, | ||||
| 			Required:     true, | ||||
| 			ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, true), | ||||
| 			Description:  "Network type, EXTNET or VINS", | ||||
| 		}, | ||||
| 		"client_type": { | ||||
| 			Type:         schema.TypeString, | ||||
| 			Required:     true, | ||||
| 			Description:  "Type of client, 'compute' ('vins' will be later)", | ||||
| 			ValidateFunc: validation.StringInSlice([]string{"compute"}, true), | ||||
| 		}, | ||||
| 		"ip": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "IP address to associate with this group. If empty, the platform will autoselect IP address", | ||||
| 		}, | ||||
| 		"desc": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Text description of this Flipgroup instance", | ||||
| 		}, | ||||
| 		"client_ids": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeInt, | ||||
| 			}, | ||||
| 			Description: "List of clients attached to this Flipgroup instance", | ||||
| 		}, | ||||
| 		"flipgroup_id": { | ||||
| 			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, | ||||
| 		}, | ||||
| 		"conn_type": { | ||||
| 			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, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"network": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_name": { | ||||
| 			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, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ResourceFlipgroup() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		CreateContext: resourceFlipgroupCreate, | ||||
| 		ReadContext:   resourceFlipgroupRead, | ||||
| 		UpdateContext: resourceFlipgroupUpdate, | ||||
| 		DeleteContext: resourceFlipgroupDelete, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout300s, | ||||
| 			Read:    &constants.Timeout300s, | ||||
| 			Update:  &constants.Timeout300s, | ||||
| 			Delete:  &constants.Timeout300s, | ||||
| 			Default: &constants.Timeout300s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceFlipgroupSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,167 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| Tim Tkachev, <tvtkachev@basistech.ru> | ||||
| 
 | ||||
| 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 flipgroup | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| ) | ||||
| 
 | ||||
| func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.ItemFLIPGroup, warn *dc.Warnings) { | ||||
| 	addedClients := make([]interface{}, 0) | ||||
| 	removedClients := make([]interface{}, 0) | ||||
| 
 | ||||
| 	old_set, new_set := d.GetChange("client_ids") | ||||
| 	oldSlice := old_set.([]interface{}) | ||||
| 	newSlice := new_set.([]interface{}) | ||||
| 
 | ||||
| 	for _, oldElem := range oldSlice { | ||||
| 		if !containsClient(newSlice, oldElem) { | ||||
| 			removedClients = append(removedClients, oldElem) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, newElem := range newSlice { | ||||
| 		if !containsClient(oldSlice, newElem) { | ||||
| 			addedClients = append(addedClients, newElem) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("Found client_ids change with %v deletion(s) and %v addition(s) [flipgroupID=%v]", len(removedClients), len(addedClients), fg.ID) | ||||
| 
 | ||||
| 	if len(addedClients) > 0 { | ||||
| 		for _, id := range addedClients { | ||||
| 			req := flipgroup.ComputeAddRequest{ | ||||
| 				FLIPGroupID: fg.ID, | ||||
| 				ComputeID:   uint64(id.(int)), | ||||
| 			} | ||||
| 
 | ||||
| 			if _, err := c.CloudAPI().FLIPGroup().ComputeAdd(ctx, req); err != nil { | ||||
| 				warn.Add(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if len(removedClients) > 0 { | ||||
| 		for _, id := range removedClients { | ||||
| 			req := flipgroup.ComputeRemoveRequest{ | ||||
| 				FLIPGroupID: fg.ID, | ||||
| 				ComputeID:   uint64(id.(int)), | ||||
| 			} | ||||
| 
 | ||||
| 			if _, err := c.CloudAPI().FLIPGroup().ComputeRemove(ctx, req); err != nil { | ||||
| 				warn.Add(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func containsClient(set []interface{}, check interface{}) bool { | ||||
| 	for _, elem := range set { | ||||
| 		elemConv := elem.(int) | ||||
| 		checkConv := check.(int) | ||||
| 		if elemConv == checkConv { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *controller.ControllerCfg, compute_ids []interface{}, flipgroupID uint64) { | ||||
| 	if len(compute_ids) == 0 { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("Adding %v computes to flipgroup [id=%v]...", len(compute_ids), flipgroupID) | ||||
| 
 | ||||
| 	for _, elem := range compute_ids { | ||||
| 		compute_id := uint64(elem.(int)) | ||||
| 		req := flipgroup.ComputeAddRequest{ | ||||
| 			FLIPGroupID: flipgroupID, | ||||
| 			ComputeID:   compute_id, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudAPI().FLIPGroup().ComputeAdd(ctx, req) | ||||
| 		if err != nil { | ||||
| 			warnings.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ItemFLIPGroup, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := flipgroup.GetRequest{} | ||||
| 
 | ||||
| 	if d.Id() == "" { | ||||
| 		req.FLIPGroupID = uint64(d.Get("flipgroup_id").(int)) | ||||
| 	} else { | ||||
| 		id, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 		req.FLIPGroupID = id | ||||
| 	} | ||||
| 
 | ||||
| 	fg, err := c.CloudAPI().FLIPGroup().Get(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return fg, err | ||||
| } | ||||
| 
 | ||||
| func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (flipgroup.ListFLIPGroups, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := flipgroup.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)) | ||||
| 	} | ||||
| 
 | ||||
| 	fg_list, err := c.CloudAPI().FLIPGroup().List(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return fg_list, err | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in new issue