-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor_change] Add resource and datasource for mso_template
- Loading branch information
Showing
6 changed files
with
837 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
terraform { | ||
required_providers { | ||
mso = { | ||
source = "CiscoDevNet/mso" | ||
} | ||
} | ||
} | ||
|
||
provider "mso" { | ||
username = "" # <MSO username> | ||
password = "" # <MSO pwd> | ||
url = "" # <MSO URL> | ||
insecure = true | ||
} | ||
|
||
data "mso_site" "site_1" { | ||
name = "example_site_1" | ||
} | ||
|
||
data "mso_site" "site_2" { | ||
name = "example_site_2" | ||
} | ||
|
||
data "mso_tenant" "example_tenant" { | ||
name = "example_tenant" | ||
} | ||
|
||
# tenant template example | ||
|
||
resource "mso_template" "tenant_template" { | ||
template_name = "tenant_template" | ||
template_type = "tenant" | ||
tenant_name = mso_tenant.example_tenant.display_name | ||
sites = [data.mso_site.site_1.id, data.mso_site.site_2.id] | ||
} | ||
|
||
# l3out template example | ||
|
||
resource "mso_template" "l3out_template" { | ||
template_name = "l3out_template" | ||
template_type = "l3out" | ||
tenant_name = mso_tenant.example_tenant.display_name | ||
sites = [data.mso_site.site_1.id] | ||
} | ||
|
||
# fabric policy template example | ||
|
||
resource "mso_template" "fabric_policy_template" { | ||
template_name = "fabric_policy_template" | ||
template_type = "fabric_policy" | ||
sites = [data.mso_site.site_1.id, data.mso_site.site_2.id] | ||
} | ||
|
||
# fabric resource template example | ||
|
||
resource "mso_template" "fabric_resource_template" { | ||
template_name = "fabric_resource_template" | ||
template_type = "fabric_resource" | ||
sites = [data.mso_site.site_1.id, data.mso_site.site_2.id] | ||
} | ||
|
||
# monitoring tenant template example | ||
|
||
resource "mso_template" "monitoring_tenant_template" { | ||
template_name = "monitoring_tenant_template" | ||
template_type = "monitoring_tenant" | ||
tenant_name = mso_tenant.example_tenant.display_name | ||
sites = [data.mso_site.site_1.id] | ||
} | ||
|
||
# monitoring access template example | ||
|
||
resource "mso_template" "monitoring_access_template" { | ||
template_name = "monitoring_access_template" | ||
template_type = "monitoring_access" | ||
sites = [data.mso_site.site_1.id] | ||
} | ||
|
||
# service device template example | ||
|
||
resource "mso_template" "service_device_template" { | ||
template_name = "service_device_template" | ||
template_type = "service_device" | ||
tenant_name = mso_tenant.example_tenant.display_name | ||
sites = [data.mso_site.site_1.id, data.mso_site.site_2.id] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package mso | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ciscoecosystem/mso-go-client/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
) | ||
|
||
func datasourceMSOTemplate() *schema.Resource { | ||
return &schema.Resource{ | ||
|
||
Read: datasourceMSOTemplateRead, | ||
|
||
SchemaVersion: version, | ||
|
||
Schema: (map[string]*schema.Schema{ | ||
"template_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringLenBetween(1, 1000), | ||
}, | ||
"template_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringLenBetween(1, 1000), | ||
}, | ||
"template_type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"tenant", | ||
"l3out", | ||
"fabric_policy", | ||
"fabric_resource", | ||
"monitoring_tenant", | ||
"monitoring_access", | ||
"service_device", | ||
}, false), | ||
}, | ||
"tenant_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sites": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
func datasourceMSOTemplateRead(d *schema.ResourceData, m interface{}) error { | ||
log.Println("[DEBUG] MSO Template Datasource: Beginning Read") | ||
|
||
msoClient := m.(*client.Client) | ||
id := d.Get("template_id").(string) | ||
name := d.Get("template_name").(string) | ||
templateType := d.Get("template_type").(string) | ||
|
||
if id == "" && name == "" { | ||
return fmt.Errorf("either `template_id` or `template_name` must be provided") | ||
} else if id != "" && name != "" { | ||
return fmt.Errorf("only one of `template_id` or `template_name` must be provided") | ||
} else if name != "" && templateType == "" { | ||
return fmt.Errorf("`template_type` must be provided when `template_name` is provided") | ||
} | ||
|
||
ndoTemplate := ndoTemplate{msoClient: msoClient, id: id, templateName: name, templateType: templateType} | ||
err := ndoTemplate.getTemplate(true) | ||
if err != nil { | ||
return err | ||
} | ||
ndoTemplate.SetToSchema(d) | ||
d.Set("template_id", d.Id()) | ||
log.Println("[DEBUG] MSO Template Datasource: Read Completed", d.Id()) | ||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.