Skip to content

Commit ae0aa4f

Browse files
shrsrlhercot
authored andcommitted
auto generated stp files
1 parent b1a01d1 commit ae0aa4f

File tree

6 files changed

+210
-113
lines changed

6 files changed

+210
-113
lines changed

aci/data_source_aci_stpifpol.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,32 @@ func dataSourceAciSpanningTreeInterfacePolicy() *schema.Resource {
1212
Read: dataSourceAciSpanningTreeInterfacePolicyRead,
1313
SchemaVersion: 1,
1414
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{
15-
"name": &schema.Schema{
15+
"annotation": {
1616
Type: schema.TypeString,
17-
Required: true,
17+
Optional: true,
18+
Computed: true,
1819
},
19-
20-
"ctrl": &schema.Schema{
20+
"ctrl": {
2121
Type: schema.TypeList,
2222
Optional: true,
2323
Computed: true,
2424
Elem: &schema.Schema{
2525
Type: schema.TypeString,
2626
},
2727
},
28+
"name": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
},
2832
})),
2933
}
3034
}
3135

3236
func dataSourceAciSpanningTreeInterfacePolicyRead(d *schema.ResourceData, m interface{}) error {
3337
aciClient := m.(*client.Client)
3438
name := d.Get("name").(string)
35-
rn := fmt.Sprintf("ifPol-%s", name)
39+
40+
rn := fmt.Sprintf("infra/ifPol-%s", name)
3641
dn := fmt.Sprintf("uni/%s", rn)
3742
stpIfPol, err := getRemoteSpanningTreeInterfacePolicy(aciClient, dn)
3843
if err != nil {

aci/resource_aci_stpifpol.go

Lines changed: 85 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
)
1515

1616
func resourceAciSpanningTreeInterfacePolicy() *schema.Resource {
17-
1817
return &schema.Resource{
1918
Create: resourceAciSpanningTreeInterfacePolicyCreate,
2019
Update: resourceAciSpanningTreeInterfacePolicyUpdate,
@@ -27,12 +26,8 @@ func resourceAciSpanningTreeInterfacePolicy() *schema.Resource {
2726

2827
SchemaVersion: 1,
2928
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{
30-
"name": &schema.Schema{
31-
Type: schema.TypeString,
32-
Required: true,
33-
ForceNew: true,
34-
},
35-
"ctrl": &schema.Schema{
29+
30+
"ctrl": {
3631
Type: schema.TypeList,
3732
Optional: true,
3833
Computed: true,
@@ -41,9 +36,15 @@ func resourceAciSpanningTreeInterfacePolicy() *schema.Resource {
4136
ValidateFunc: validation.StringInSlice([]string{
4237
"bpdu-filter",
4338
"bpdu-guard",
39+
"unspecified",
4440
}, false),
4541
},
4642
},
43+
"name": {
44+
Type: schema.TypeString,
45+
Required: true,
46+
ForceNew: true,
47+
},
4748
})),
4849
}
4950
}
@@ -64,7 +65,6 @@ func setSpanningTreeInterfacePolicyAttributes(stpIfPol *models.SpanningTreeInter
6465
d.SetId(stpIfPol.DistinguishedName)
6566
d.Set("description", stpIfPol.Description)
6667
stpIfPolMap, _ := stpIfPol.ToMap()
67-
d.Set("name", stpIfPolMap["name"])
6868
d.Set("annotation", stpIfPolMap["annotation"])
6969
ctrlGet := make([]string, 0, 1)
7070
for _, val := range strings.Split(stpIfPolMap["ctrl"], ",") {
@@ -85,6 +85,7 @@ func setSpanningTreeInterfacePolicyAttributes(stpIfPol *models.SpanningTreeInter
8585
} else {
8686
d.Set("ctrl", ctrlGet)
8787
}
88+
d.Set("name", stpIfPolMap["name"])
8889
d.Set("name_alias", stpIfPolMap["nameAlias"])
8990
return d
9091
}
@@ -103,54 +104,64 @@ func resourceAciSpanningTreeInterfacePolicyImport(d *schema.ResourceData, m inte
103104
}
104105

105106
func resourceAciSpanningTreeInterfacePolicyCreate(d *schema.ResourceData, m interface{}) error {
106-
return resourceAciSpanningTreeInterfacePolicyCreateOrUpdate(d, m, false)
107-
}
108-
109-
func resourceAciSpanningTreeInterfacePolicyUpdate(d *schema.ResourceData, m interface{}) error {
110-
return resourceAciSpanningTreeInterfacePolicyCreateOrUpdate(d, m, true)
111-
}
112-
113-
func resourceAciSpanningTreeInterfacePolicyRead(d *schema.ResourceData, m interface{}) error {
114-
log.Printf("[DEBUG] %s: Beginning Read", d.Id())
107+
log.Printf("[DEBUG] SpanningTreeInterfacePolicy: Beginning Creation")
115108
aciClient := m.(*client.Client)
116-
dn := d.Id()
117-
stpIfPol, err := getRemoteSpanningTreeInterfacePolicy(aciClient, dn)
118-
if err != nil {
119-
d.SetId("")
120-
return nil
109+
desc := d.Get("description").(string)
110+
name := d.Get("name").(string)
111+
stpIfPolAttr := models.SpanningTreeInterfacePolicyAttributes{}
112+
nameAlias := ""
113+
if NameAlias, ok := d.GetOk("name_alias"); ok {
114+
nameAlias = NameAlias.(string)
115+
}
116+
if Annotation, ok := d.GetOk("annotation"); ok {
117+
stpIfPolAttr.Annotation = Annotation.(string)
118+
} else {
119+
stpIfPolAttr.Annotation = "{}"
121120
}
122-
setSpanningTreeInterfacePolicyAttributes(stpIfPol, d)
123-
log.Printf("[DEBUG] %s: Read finished successfully", d.Id())
124-
return nil
125-
}
126121

127-
func resourceAciSpanningTreeInterfacePolicyDelete(d *schema.ResourceData, m interface{}) error {
128-
log.Printf("[DEBUG] %s: Beginning Destroy", d.Id())
129-
aciClient := m.(*client.Client)
130-
dn := d.Id()
131-
err := aciClient.DeleteByDn(dn, "stpIfPol")
122+
if Ctrl, ok := d.GetOk("ctrl"); ok {
123+
ctrlList := make([]string, 0, 1)
124+
for _, val := range Ctrl.([]interface{}) {
125+
ctrlList = append(ctrlList, val.(string))
126+
}
127+
Ctrl := strings.Join(ctrlList, ",")
128+
stpIfPolAttr.Ctrl = Ctrl
129+
}
130+
131+
if Name, ok := d.GetOk("name"); ok {
132+
stpIfPolAttr.Name = Name.(string)
133+
}
134+
stpIfPol := models.NewSpanningTreeInterfacePolicy(fmt.Sprintf("infra/ifPol-%s", name), "uni", desc, nameAlias, stpIfPolAttr)
135+
err := aciClient.Save(stpIfPol)
132136
if err != nil {
133137
return err
134138
}
135-
log.Printf("[DEBUG] %s: Destroy finished successfully", d.Id())
136-
d.SetId("")
137-
return err
139+
d.Partial(true)
140+
d.SetPartial("name")
141+
d.Partial(false)
142+
143+
d.SetId(stpIfPol.DistinguishedName)
144+
log.Printf("[DEBUG] %s: Creation finished successfully", d.Id())
145+
return resourceAciSpanningTreeInterfacePolicyRead(d, m)
138146
}
139-
func resourceAciSpanningTreeInterfacePolicyCreateOrUpdate(d *schema.ResourceData, m interface{}, update bool) error {
140-
action := "Creation"
141-
if update == true {
142-
action = "Update"
143-
}
144-
log.Printf("[DEBUG] SpanningTreeInterfacePolicy: Beginning %s", action)
147+
148+
func resourceAciSpanningTreeInterfacePolicyUpdate(d *schema.ResourceData, m interface{}) error {
149+
log.Printf("[DEBUG] SpanningTreeInterfacePolicy: Beginning Update")
145150
aciClient := m.(*client.Client)
146151
desc := d.Get("description").(string)
147152
name := d.Get("name").(string)
148153
stpIfPolAttr := models.SpanningTreeInterfacePolicyAttributes{}
154+
nameAlias := ""
155+
if NameAlias, ok := d.GetOk("name_alias"); ok {
156+
nameAlias = NameAlias.(string)
157+
}
158+
149159
if Annotation, ok := d.GetOk("annotation"); ok {
150160
stpIfPolAttr.Annotation = Annotation.(string)
151161
} else {
152162
stpIfPolAttr.Annotation = "{}"
153163
}
164+
154165
if Ctrl, ok := d.GetOk("ctrl"); ok {
155166
ctrlList := make([]string, 0, 1)
156167
for _, val := range Ctrl.([]interface{}) {
@@ -159,23 +170,49 @@ func resourceAciSpanningTreeInterfacePolicyCreateOrUpdate(d *schema.ResourceData
159170
Ctrl := strings.Join(ctrlList, ",")
160171
stpIfPolAttr.Ctrl = Ctrl
161172
}
162-
nameAlias := ""
163-
if NameAlias, ok := d.GetOk("name_alias"); ok {
164-
nameAlias = NameAlias.(string)
165-
}
166173

167-
stpIfPol := models.NewSpanningTreeInterfacePolicy(fmt.Sprintf("infra/ifPol-%s", name), "uni", desc, nameAlias, stpIfPolAttr)
168-
if update == true {
169-
stpIfPol.Status = "modified"
174+
if Name, ok := d.GetOk("name"); ok {
175+
stpIfPolAttr.Name = Name.(string)
170176
}
177+
stpIfPol := models.NewSpanningTreeInterfacePolicy(fmt.Sprintf("infra/ifPol-%s", name), "uni", desc, nameAlias, stpIfPolAttr)
178+
stpIfPol.Status = "modified"
171179
err := aciClient.Save(stpIfPol)
172180
if err != nil {
173181
return err
174182
}
175183
d.Partial(true)
176184
d.SetPartial("name")
177185
d.Partial(false)
186+
178187
d.SetId(stpIfPol.DistinguishedName)
179-
log.Printf("[DEBUG] %s: %s finished successfully", d.Id(), action)
188+
log.Printf("[DEBUG] %s: Update finished successfully", d.Id())
180189
return resourceAciSpanningTreeInterfacePolicyRead(d, m)
181190
}
191+
192+
func resourceAciSpanningTreeInterfacePolicyRead(d *schema.ResourceData, m interface{}) error {
193+
log.Printf("[DEBUG] %s: Beginning Read", d.Id())
194+
aciClient := m.(*client.Client)
195+
dn := d.Id()
196+
stpIfPol, err := getRemoteSpanningTreeInterfacePolicy(aciClient, dn)
197+
if err != nil {
198+
d.SetId("")
199+
return err
200+
}
201+
setSpanningTreeInterfacePolicyAttributes(stpIfPol, d)
202+
203+
log.Printf("[DEBUG] %s: Read finished successfully", d.Id())
204+
return nil
205+
}
206+
207+
func resourceAciSpanningTreeInterfacePolicyDelete(d *schema.ResourceData, m interface{}) error {
208+
log.Printf("[DEBUG] %s: Beginning Destroy", d.Id())
209+
aciClient := m.(*client.Client)
210+
dn := d.Id()
211+
err := aciClient.DeleteByDn(dn, "stpIfPol")
212+
if err != nil {
213+
return err
214+
}
215+
log.Printf("[DEBUG] %s: Destroy finished successfully", d.Id())
216+
d.SetId("")
217+
return err
218+
}

aci/resource_aci_stpifpol_test.go

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,63 @@ import (
66

77
"github.com/ciscoecosystem/aci-go-client/client"
88
"github.com/ciscoecosystem/aci-go-client/models"
9-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
9+
"github.com/hashicorp/terraform/helper/acctest"
10+
"github.com/hashicorp/terraform/helper/resource"
11+
"github.com/hashicorp/terraform/terraform"
1112
)
1213

1314
func TestAccAciSpanningTreeInterfacePolicy_Basic(t *testing.T) {
1415
var spanning_tree_interface_policy models.SpanningTreeInterfacePolicy
15-
description := "Spanning Tree Interface Policy created while acceptance testing"
16+
stp_if_pol_name := acctest.RandString(5)
17+
description := "spanning_tree_interface_policy created while acceptance testing"
1618

1719
resource.Test(t, resource.TestCase{
1820
PreCheck: func() { testAccPreCheck(t) },
1921
Providers: testAccProviders,
2022
CheckDestroy: testAccCheckAciSpanningTreeInterfacePolicyDestroy,
2123
Steps: []resource.TestStep{
2224
{
23-
Config: testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(description),
25+
Config: testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(stp_if_pol_name),
2426
Check: resource.ComposeTestCheckFunc(
25-
testAccCheckAciSpanningTreeInterfacePolicyExists("aci_stp_if_pol.foospanning_tree_interface_policy", &spanning_tree_interface_policy),
26-
testAccCheckAciSpanningTreeInterfacePolicyAttributes(description, &spanning_tree_interface_policy),
27+
testAccCheckAciSpanningTreeInterfacePolicyExists("aci_spanning_tree_interface_policy.foospanning_tree_interface_policy", &spanning_tree_interface_policy),
28+
testAccCheckAciSpanningTreeInterfacePolicyAttributes(stp_if_pol_name, description, &spanning_tree_interface_policy),
2729
),
2830
},
2931
},
3032
})
3133
}
3234

33-
func TestAccAciSpanningTreeInterfacePolicy_update(t *testing.T) {
34-
var spanning_tree_interface_policy models.SpanningTreeInterfacePolicy
35-
description := "Spanning Tree Interface Policy created while acceptance testing"
36-
resource.Test(t, resource.TestCase{
37-
PreCheck: func() { testAccPreCheck(t) },
38-
Providers: testAccProviders,
39-
CheckDestroy: testAccCheckAciSpanningTreeInterfacePolicyDestroy,
40-
Steps: []resource.TestStep{
41-
{
42-
Config: testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(description),
43-
Check: resource.ComposeTestCheckFunc(
44-
testAccCheckAciSpanningTreeInterfacePolicyExists("aci_stp_if_pol.foospanning_tree_interface_policy", &spanning_tree_interface_policy),
45-
testAccCheckAciSpanningTreeInterfacePolicyAttributes(description, &spanning_tree_interface_policy),
46-
),
47-
},
48-
{
49-
Config: testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(description),
50-
Check: resource.ComposeTestCheckFunc(
51-
testAccCheckAciSpanningTreeInterfacePolicyExists("aci_stp_if_pol.foospanning_tree_interface_policy", &spanning_tree_interface_policy),
52-
testAccCheckAciSpanningTreeInterfacePolicyAttributes(description, &spanning_tree_interface_policy),
53-
),
54-
},
55-
},
56-
})
57-
}
58-
59-
func testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(description string) string {
35+
func testAccCheckAciSpanningTreeInterfacePolicyConfig_basic(stp_if_pol_name string) string {
6036
return fmt.Sprintf(`
61-
resource "aci_stp_if_pol" "foospanning_tree_interface_policy" {
62-
description = "%s"
63-
name = "example"
64-
annotation = "example"
65-
ctrl = ["bpdu-guard"]
66-
name_alias = "example"
37+
38+
resource "aci_spanning_tree_interface_policy" "foospanning_tree_interface_policy" {
39+
name = "%s"
40+
description = "spanning_tree_interface_policy created while acceptance testing"
41+
6742
}
68-
`, description)
43+
44+
`, stp_if_pol_name)
6945
}
7046

7147
func testAccCheckAciSpanningTreeInterfacePolicyExists(name string, spanning_tree_interface_policy *models.SpanningTreeInterfacePolicy) resource.TestCheckFunc {
7248
return func(s *terraform.State) error {
7349
rs, ok := s.RootModule().Resources[name]
50+
7451
if !ok {
7552
return fmt.Errorf("Spanning Tree Interface Policy %s not found", name)
7653
}
54+
7755
if rs.Primary.ID == "" {
7856
return fmt.Errorf("No Spanning Tree Interface Policy dn was set")
7957
}
58+
8059
client := testAccProvider.Meta().(*client.Client)
60+
8161
cont, err := client.Get(rs.Primary.ID)
8262
if err != nil {
8363
return err
8464
}
65+
8566
spanning_tree_interface_policyFound := models.SpanningTreeInterfacePolicyFromContainer(cont)
8667
if spanning_tree_interface_policyFound.DistinguishedName != rs.Primary.ID {
8768
return fmt.Errorf("Spanning Tree Interface Policy %s not found", rs.Primary.ID)
@@ -94,7 +75,7 @@ func testAccCheckAciSpanningTreeInterfacePolicyExists(name string, spanning_tree
9475
func testAccCheckAciSpanningTreeInterfacePolicyDestroy(s *terraform.State) error {
9576
client := testAccProvider.Meta().(*client.Client)
9677
for _, rs := range s.RootModule().Resources {
97-
if rs.Type == "aci_stp_if_pol" {
78+
if rs.Type == "aci_spanning_tree_interface_policy" {
9879
cont, err := client.Get(rs.Primary.ID)
9980
spanning_tree_interface_policy := models.SpanningTreeInterfacePolicyFromContainer(cont)
10081
if err == nil {
@@ -107,23 +88,14 @@ func testAccCheckAciSpanningTreeInterfacePolicyDestroy(s *terraform.State) error
10788
return nil
10889
}
10990

110-
func testAccCheckAciSpanningTreeInterfacePolicyAttributes(description string, spanning_tree_interface_policy *models.SpanningTreeInterfacePolicy) resource.TestCheckFunc {
91+
func testAccCheckAciSpanningTreeInterfacePolicyAttributes(stp_if_pol_name, description string, spanning_tree_interface_policy *models.SpanningTreeInterfacePolicy) resource.TestCheckFunc {
11192
return func(s *terraform.State) error {
93+
if stp_if_pol_name != GetMOName(spanning_tree_interface_policy.DistinguishedName) {
94+
return fmt.Errorf("Bad stp_if_pol %s", GetMOName(spanning_tree_interface_policy.DistinguishedName))
95+
}
11296

11397
if description != spanning_tree_interface_policy.Description {
114-
return fmt.Errorf("Bad Spanning Tree Interface Policy Description %s", spanning_tree_interface_policy.Description)
115-
}
116-
if "example" != spanning_tree_interface_policy.Name {
117-
return fmt.Errorf("Bad Spanning Tree Interface Policy name %s", spanning_tree_interface_policy.Name)
118-
}
119-
if "example" != spanning_tree_interface_policy.Annotation {
120-
return fmt.Errorf("Bad Spanning Tree Interface Policy annotation %s", spanning_tree_interface_policy.Annotation)
121-
}
122-
if "bpdu-guard" != spanning_tree_interface_policy.Ctrl {
123-
return fmt.Errorf("Bad Spanning Tree Interface Policy ctrl %s", spanning_tree_interface_policy.Ctrl)
124-
}
125-
if "example" != spanning_tree_interface_policy.NameAlias {
126-
return fmt.Errorf("Bad Spanning Tree Interface Policy name_alias %s", spanning_tree_interface_policy.NameAlias)
98+
return fmt.Errorf("Bad spanning_tree_interface_policy Description %s", spanning_tree_interface_policy.Description)
12799
}
128100
return nil
129101
}

0 commit comments

Comments
 (0)