From 9bc0d91bd863913ae037c48a6aedae0682893531 Mon Sep 17 00:00:00 2001 From: Anthony Howe Date: Fri, 14 Aug 2020 09:19:55 -0400 Subject: [PATCH] add check for vfxt name and licensing id output (#809) --- .../terraform-provider-avere/constants.go | 1 + .../terraform-provider-avere/resource_vfxt.go | 23 +++++++++++++++++-- .../terraform-provider-avere/types.go | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/terraform/providers/terraform-provider-avere/constants.go b/src/terraform/providers/terraform-provider-avere/constants.go index 7b1d396bb..95547a64b 100644 --- a/src/terraform/providers/terraform-provider-avere/constants.go +++ b/src/terraform/providers/terraform-provider-avere/constants.go @@ -142,4 +142,5 @@ const ( node_names = "node_names" junction_namespace_path = "junction_namespace_path" primary_cluster_ips = "primary_cluster_ips" + licensing_id = "licensing_id" ) diff --git a/src/terraform/providers/terraform-provider-avere/resource_vfxt.go b/src/terraform/providers/terraform-provider-avere/resource_vfxt.go index 01e41a08e..afb8e95ec 100644 --- a/src/terraform/providers/terraform-provider-avere/resource_vfxt.go +++ b/src/terraform/providers/terraform-provider-avere/resource_vfxt.go @@ -141,7 +141,7 @@ func resourceVfxt() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringDoesNotContainAny(" '\"$"), + ValidateFunc: ValidateVfxtName, }, vfxt_admin_password: { Type: schema.TypeString, @@ -363,6 +363,10 @@ func resourceVfxt() *schema.Resource { Type: schema.TypeString, }, }, + licensing_id: { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -512,6 +516,12 @@ func resourceVfxtRead(d *schema.ResourceData, m interface{}) error { d.Set(vfxt_node_count, len(*(avereVfxt.NodeNames))) } + cluster, err := avereVfxt.GetCluster() + if err != nil { + return fmt.Errorf("error encountered getting cluster '%v'", err) + } + d.Set(licensing_id, cluster.LicensingId) + return nil } @@ -1513,7 +1523,6 @@ func ValidateExportSubdirectory(v interface{}, _ string) (warnings []string, err return warnings, errors } -// ValidateAutomationRunbookName validates Automation Account Runbook names func ValidateUserName(v interface{}, _ string) (warnings []string, errors []error) { input := v.(string) @@ -1528,6 +1537,16 @@ func ValidateUserName(v interface{}, _ string) (warnings []string, errors []erro return warnings, errors } +func ValidateVfxtName(v interface{}, _ string) (warnings []string, errors []error) { + input := v.(string) + + if !regexp.MustCompile(`^[a-z]([-a-z0-9]*[a-z0-9])?$`).MatchString(input) { + errors = append(errors, fmt.Errorf("the vfxt name '%s' is invalid, and per vfxt.py must match the regular expressesion ^[a-z]([-a-z0-9]*[a-z0-9])?$ ''", input)) + } + + return warnings, errors +} + func unflattenStringSlice(input []interface{}) *[]string { output := make([]string, 0) diff --git a/src/terraform/providers/terraform-provider-avere/types.go b/src/terraform/providers/terraform-provider-avere/types.go index e686738a7..95dd5209f 100644 --- a/src/terraform/providers/terraform-provider-avere/types.go +++ b/src/terraform/providers/terraform-provider-avere/types.go @@ -148,4 +148,5 @@ type Cluster struct { NtpServers string `json:"NTPservers"` ClusterName string `json:"name"` Proxy string `json:"proxy"` + LicensingId string `json:"id"` }