diff --git a/examples/schema_template_deploy_ndo/main.tf b/examples/schema_template_deploy_ndo/main.tf index 96e1328a..b843b131 100644 --- a/examples/schema_template_deploy_ndo/main.tf +++ b/examples/schema_template_deploy_ndo/main.tf @@ -6,11 +6,13 @@ terraform { } } +// mso_schema_template_deploy_ndo resource will only work when platform is set to nd provider "mso" { username = "" # password = "" # url = "" # insecure = true + platform = "nd" } resource "mso_site" "site_test_1" { diff --git a/mso/resource_mso_schema_site.go b/mso/resource_mso_schema_site.go index b919346a..a8a0dcd3 100644 --- a/mso/resource_mso_schema_site.go +++ b/mso/resource_mso_schema_site.go @@ -213,14 +213,14 @@ func resourceMSOSchemaSiteDelete(d *schema.ResourceData, m interface{}) error { log.Printf("[DEBUG] Parse of JSON failed with err: %s.", err) return err } - req, err := msoClient.MakeRestRequest("POST", "mso/api/v1/task", payload, true) + req, err := msoClient.MakeRestRequest("POST", "api/v1/task", payload, true) if err != nil { log.Printf("[DEBUG] MakeRestRequest failed with err: %s.", err) return err } - _, _, err = msoClient.Do(req) - if err != nil { - log.Printf("[DEBUG] Request failed with err: %s.", err) + _, resp, err := msoClient.Do(req) + if err != nil || resp.StatusCode != 202 { + log.Printf("[DEBUG] Request failed with resp: %v. Err: %s.", resp, err) return err } } else if d.Get("undeploy_on_destroy").(bool) && err == nil { @@ -228,6 +228,8 @@ func resourceMSOSchemaSiteDelete(d *schema.ResourceData, m interface{}) error { if err != nil { return err } + } else if d.Get("undeploy_on_destroy").(bool) { + log.Printf("[WARNING] Failed to compare version. Template could not be undeployed prior to schema site deletion. Err: %s.", err) } schemasite := models.NewSchemaSite("remove", fmt.Sprintf("/sites/%s-%s", siteId, templateName), siteId, templateName) diff --git a/mso/resource_ndo_schema_template_deploy.go b/mso/resource_ndo_schema_template_deploy.go index 7efec455..fc0437b6 100644 --- a/mso/resource_ndo_schema_template_deploy.go +++ b/mso/resource_ndo_schema_template_deploy.go @@ -1,6 +1,7 @@ package mso import ( + "errors" "fmt" "log" @@ -20,6 +21,15 @@ func resourceNDOSchemaTemplateDeploy() *schema.Resource { SchemaVersion: version, + CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error { + // Plan time validation. + msoClient := v.(*client.Client) + if msoClient.GetPlatform() != "nd" { + return errors.New(`The 'mso_schema_template_deploy_ndo' resource is only supported for nd based platforms, 'platform=nd' must be configured in the provider section of your configuration.`) + } + return nil + }, + Schema: (map[string]*schema.Schema{ "schema_id": &schema.Schema{ Type: schema.TypeString, @@ -52,7 +62,7 @@ func resourceNDOSchemaTemplateDeployExecute(d *schema.ResourceData, m interface{ log.Printf("[DEBUG] %s: Beginning Template Deploy Execution", d.Id()) templateName := d.Get("template_name").(string) schemaId := d.Get("schema_id").(string) - path := "mso/api/v1/task" + path := "api/v1/task" msoClient := m.(*client.Client) @@ -71,9 +81,9 @@ func resourceNDOSchemaTemplateDeployExecute(d *schema.ResourceData, m interface{ log.Printf("[DEBUG] MakeRestRequest failed with err: %s.", err) return err } - _, _, err = msoClient.Do(req) - if err != nil { - log.Printf("[DEBUG] Request failed with err: %s.", err) + _, resp, err := msoClient.Do(req) + if err != nil || resp.StatusCode != 202 { + log.Printf("[DEBUG] Request failed with resp: %v. Err: %s.", resp, err) return err } diff --git a/website/docs/r/schema_template_deploy_ndo.html.markdown b/website/docs/r/schema_template_deploy_ndo.html.markdown index 1a1696af..28d6a7a6 100644 --- a/website/docs/r/schema_template_deploy_ndo.html.markdown +++ b/website/docs/r/schema_template_deploy_ndo.html.markdown @@ -14,6 +14,14 @@ Manages deploy and redeploy operations of schema templates for NDO v3.7 and high ```hcl +provider "mso" { + username = "" # + password = "" # + url = "" # + insecure = true + platform = "nd" +} + resource "mso_schema_template_deploy_ndo" "template_deployer" { schema_id = mso_schema.schema1.id template_name = "Template1" @@ -29,6 +37,7 @@ resource "mso_schema_template_deploy_ndo" "template_deployer" { ### Notes ### +* This resource requires 'platform = "nd"' to be configured in the provider configuration section. * This resource is intentionally created non-idempotent so that it deploys the template in every run, it will not fail if there is no change and we deploy or redeploy the template again. When destroying the resource, no action is taken. * Prior to deploy or redeploy a schema validation is executed. When schema validation fails, the resource will fail and deploy or redeploy will not be executed. * A template can only be undeployed from a site by disassociating the site from the template with the resource mso_schema_site.