Skip to content

Commit 3980760

Browse files
committed
[minor_change] Add resource and data source for MACsec Policy under Fabric Policy Template.
1 parent 6c8fcdc commit 3980760

8 files changed

+968
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
terraform {
2+
required_providers {
3+
mso = {
4+
source = "CiscoDevNet/mso"
5+
}
6+
}
7+
}
8+
9+
provider "mso" {
10+
username = "" # <MSO username>
11+
password = "" # <MSO pwd>
12+
url = "" # <MSO URL>
13+
insecure = true
14+
}
15+
16+
# fabric policy template example
17+
18+
resource "mso_template" "fabric_policy_template" {
19+
template_name = "fabric_policy_template"
20+
template_type = "fabric_policy"
21+
}
22+
23+
# fabric policies macsec policy example
24+
25+
resource "mso_fabric_policies_macsec_policy" "macsec_policy" {
26+
template_id = mso_template.fabric_policy_template.id
27+
name = "macsec_policy"
28+
description = "Example description"
29+
admin_state = "enabled"
30+
interface_type = "access"
31+
cipher_suite = "256GcmAes"
32+
window_size = 128
33+
security_policy = "shouldSecure"
34+
sak_expire_time = 60
35+
confidentiality_offset = "offset30"
36+
key_server_priority = 8
37+
macsec_key {
38+
key_name = "abc123"
39+
psk = "AA111111111111111111111111111111111111111111111111111111111111aa"
40+
start_time = "now"
41+
end_time = "2027-09-23 00:00:00"
42+
}
43+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package mso
2+
3+
import (
4+
"log"
5+
6+
"github.com/ciscoecosystem/mso-go-client/client"
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
)
9+
10+
func datasourceMacsecPolicy() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceMacsecPolicyRead,
13+
14+
Schema: map[string]*schema.Schema{
15+
"template_id": {
16+
Type: schema.TypeString,
17+
Required: true,
18+
},
19+
"name": {
20+
Type: schema.TypeString,
21+
Required: true,
22+
},
23+
"description": {
24+
Type: schema.TypeString,
25+
Computed: true,
26+
},
27+
"uuid": {
28+
Type: schema.TypeString,
29+
Computed: true,
30+
},
31+
"admin_state": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
},
35+
"interface_type": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
"cipher_suite": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
43+
"window_size": {
44+
Type: schema.TypeInt,
45+
Computed: true,
46+
},
47+
"security_policy": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
},
51+
"sak_expire_time": {
52+
Type: schema.TypeInt,
53+
Computed: true,
54+
},
55+
"confidentiality_offset": {
56+
Type: schema.TypeString,
57+
Computed: true,
58+
},
59+
"key_server_priority": {
60+
Type: schema.TypeInt,
61+
Computed: true,
62+
},
63+
"macsec_key": {
64+
Type: schema.TypeSet,
65+
Computed: true,
66+
Elem: &schema.Resource{
67+
Schema: map[string]*schema.Schema{
68+
"key_name": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
72+
"psk": {
73+
Type: schema.TypeString,
74+
Computed: true,
75+
},
76+
"start_time": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
},
80+
"end_time": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
},
84+
},
85+
},
86+
},
87+
},
88+
}
89+
}
90+
91+
func dataSourceMacsecPolicyRead(d *schema.ResourceData, m interface{}) error {
92+
log.Printf("[DEBUG] MSO MACsec Policy Data Source - Beginning Read")
93+
msoClient := m.(*client.Client)
94+
95+
templateId := d.Get("template_id").(string)
96+
policyName := d.Get("name").(string)
97+
98+
setMacsecPolicyData(d, msoClient, templateId, policyName)
99+
log.Printf("[DEBUG] MSO MACsec Policy Data Source - Read Complete : %v", d.Id())
100+
return nil
101+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package mso
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
)
9+
10+
func TestAccMSOMacsecPolicyDataSource(t *testing.T) {
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
PreConfig: func() { fmt.Println("Test: MACsec Policy Data Source") },
17+
Config: testAccMSOMacsecPolicyDataSource(),
18+
Check: resource.ComposeAggregateTestCheckFunc(
19+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "name", "tf_test_macsec_policy"),
20+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "description", "Terraform test MACsec Policy"),
21+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "admin_state", "enabled"),
22+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "interface_type", "access"),
23+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "cipher_suite", "256GcmAes"),
24+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "window_size", "128"),
25+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "security_policy", "shouldSecure"),
26+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "sak_expire_time", "60"),
27+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "confidentiality_offset", "offset30"),
28+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "key_server_priority", "8"),
29+
resource.TestCheckResourceAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "macsec_key.#", "1"),
30+
customTestCheckResourceTypeSetAttr("data.mso_fabric_policies_macsec_policy.macsec_policy", "macsec_key",
31+
map[string]string{
32+
"key_name": "abc123",
33+
"psk": "AA111111111111111111111111111111111111111111111111111111111111aa",
34+
"start_time": "2027-09-23 00:00:00",
35+
"end_time": "2030-09-23 00:00:00",
36+
},
37+
),
38+
),
39+
},
40+
},
41+
})
42+
}
43+
44+
func testAccMSOMacsecPolicyDataSource() string {
45+
return fmt.Sprintf(`%s
46+
data "mso_fabric_policies_macsec_policy" "macsec_policy" {
47+
template_id = mso_fabric_policies_macsec_policy.macsec_policy.template_id
48+
name = "tf_test_macsec_policy"
49+
}`, testAccMSOMacsecPolicyConfigCreate())
50+
}

mso/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func Provider() terraform.ResourceProvider {
129129
"mso_tenant_policies_dhcp_relay_policy": resourceMSOTenantPoliciesDHCPRelayPolicy(),
130130
"mso_fabric_policies_vlan_pool": resourceMSOVlanPool(),
131131
"mso_fabric_policies_physical_domain": resourceMSOPhysicalDomain(),
132+
"mso_fabric_policies_macsec_policy": resourceMSOMacsecPolicy(),
132133
},
133134

134135
DataSourcesMap: map[string]*schema.Resource{
@@ -191,6 +192,7 @@ func Provider() terraform.ResourceProvider {
191192
"mso_tenant_policies_dhcp_relay_policy": datasourceMSOTenantPoliciesDHCPRelayPolicy(),
192193
"mso_fabric_policies_vlan_pool": datasourceMSOVlanPool(),
193194
"mso_fabric_policies_physical_domain": datasourceMSOPhysicalDomain(),
195+
"mso_fabric_policies_macsec_policy": datasourceMacsecPolicy(),
194196
},
195197

196198
ConfigureFunc: configureClient,

0 commit comments

Comments
 (0)