Skip to content

Commit

Permalink
add logic for computing schema and template if not provided, remove d…
Browse files Browse the repository at this point in the history
…efaults, add validation for mutually

adds logic for computing l3out schema and tempalte if not provided,
removes default l3out_on_apic
adds validation for mutually exclusive attributes
  • Loading branch information
juchowan committed Oct 1, 2024
1 parent e9a8d18 commit 8c86e7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
37 changes: 26 additions & 11 deletions mso/resource_mso_schema_site_external_epg.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ func resourceMSOSchemaSiteExternalEpg() *schema.Resource {
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
ConflictsWith: []string{"l3out_on_apic"},
},
"l3out_schema_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
ConflictsWith: []string{"l3out_on_apic"},
},
"l3out_on_apic": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
ConflictsWith: []string{"l3out_schema_id", "l3out_template_name"},
},
}),
}
Expand Down Expand Up @@ -132,7 +134,6 @@ func resourceMSOSchemaSiteExternalEpgImport(d *schema.ResourceData, m interface{
d.Set("l3out_name", matchL3out[3])
d.Set("l3out_schema_id", matchL3out[1])
d.Set("l3out_template_name", matchL3out[2])
d.Set("l3out_on_apic", false)
} else {
return nil, fmt.Errorf("Error in parsing l3outRef to get L3Out name")
}
Expand All @@ -144,7 +145,7 @@ func resourceMSOSchemaSiteExternalEpgImport(d *schema.ResourceData, m interface{
d.Set("l3out_name", matchL3out[1])
d.Set("l3out_on_apic", true)
} else {
return fmt.Errorf("Error in parsing l3outDn to get L3Out name")
return nil, fmt.Errorf("Error in parsing l3outDn to get L3Out name")
}
}

Expand Down Expand Up @@ -195,9 +196,17 @@ func resourceMSOSchemaSiteExternalEpgCreate(d *schema.ResourceData, m interface{

if l3outOnApic {
siteEpgMap["l3outRef"] = ""
} else {
l3outRefMap["schemaId"] = l3outSchema
l3outRefMap["templateName"] = l3outTemplate
} else {
if l3outTemplate == "" {
l3outRefMap["templateName"] = templateName
} else {
l3outRefMap["templateName"] = l3outTemplate
}
if l3outSchema == "" {
l3outRefMap["schemaId"] = schemaId
} else {
l3outRefMap["schemaId"] = l3outSchema
}
l3outRefMap["l3outName"] = l3outName

siteEpgMap["l3outRef"] = l3outRefMap
Expand Down Expand Up @@ -296,7 +305,6 @@ func resourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{})
d.Set("l3out_name", matchL3out[3])
d.Set("l3out_schema_id", matchL3out[1])
d.Set("l3out_template_name", matchL3out[2])
d.Set("l3out_on_apic", false)
} else {
return fmt.Errorf("Error in parsing l3outRef to get L3Out name")
}
Expand All @@ -305,7 +313,7 @@ func resourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{})
matchL3out := reL3out.FindStringSubmatch(l3outDn)
log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead l3outDn: %s matchL3out: %s", l3outDn, matchL3out)
if len(matchL3out) >= 2 {
d.Set("l3out_name", matchL3out[1])
d.Set("l3out_name", matchL3out[2])
d.Set("l3out_on_apic", true)
} else {
return fmt.Errorf("Error in parsing l3outDn to get L3Out name")
Expand Down Expand Up @@ -358,9 +366,16 @@ func resourceMSOSchemaSiteExternalEpgUpdate(d *schema.ResourceData, m interface{
if l3outOnApic {
siteEpgMap["l3outRef"] = ""
} else {

l3outRefMap["schemaId"] = l3outSchema
l3outRefMap["templateName"] = l3outTemplate
if l3outTemplate == "" {
l3outRefMap["templateName"] = templateName
} else {
l3outRefMap["templateName"] = l3outTemplate
}
if l3outSchema == "" {
l3outRefMap["schemaId"] = schemaId
} else {
l3outRefMap["schemaId"] = l3outSchema
}
l3outRefMap["l3outName"] = l3outName

siteEpgMap["l3outRef"] = l3outRefMap
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/schema_site_external_epg.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ resource "mso_schema_site_external_epg" "external_epg_1" {
## Attribute Reference ##

* `l3out_name` - (Optional) Name of the L3Out.
* `l3out_schema_id` - (Optional) Schema ID of the L3Out.
* `l3out_template_name` - (Optional) Template of the L3Out.
* `l3out_on_apic` - (Optional) Whether L3Out is created only locally on APIC.
* `l3out_schema_id` - (Optional) ID of the schema that defines the referenced L3Out. If this attribute is unspecified, it defaults to the current schema. This is mutually exclusive with `l3out_on_apic`.
* `l3out_template_name` - (Optional) The template that defines the referenced L3Out. If this parameter is unspecified, it defaults to the current template. This is mutually exclusive with `l3out_on_apic`.
* `l3out_on_apic` - (Optional) Indicates that L3Out is created only localy on APIC. This is mutually exclusive with `l3out_schema_id` and `l3out_template_name`.

## Importing ##

Expand Down

0 comments on commit 8c86e7a

Please sign in to comment.