Skip to content

Commit 01004fa

Browse files
committed
Make MAC address attribute case insensitive (dmacvicar#572)
1 parent aeb7121 commit 01004fa

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

libvirt/helper/suppress/strings.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package suppress
2+
3+
import (
4+
"strings"
5+
"github.com/hashicorp/terraform/helper/schema"
6+
)
7+
8+
func CaseDifference(_, old, new string, _ *schema.ResourceData) bool {
9+
return strings.EqualFold(old, new)
10+
}

libvirt/resource_libvirt_domain.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/davecgh/go-spew/spew"
13+
"github.com/dmacvicar/terraform-provider-libvirt/libvirt/helper/suppress"
1314
"github.com/hashicorp/terraform/helper/schema"
1415
libvirt "github.com/libvirt/libvirt-go"
1516
"github.com/libvirt/libvirt-go-xml"
@@ -198,9 +199,10 @@ func resourceLibvirtDomain() *schema.Resource {
198199
Computed: true,
199200
},
200201
"mac": {
201-
Type: schema.TypeString,
202-
Optional: true,
203-
Computed: true,
202+
Type: schema.TypeString,
203+
Optional: true,
204+
Computed: true,
205+
DiffSuppressFunc: suppress.CaseDifference,
204206
},
205207
"wait_for_lease": {
206208
Type: schema.TypeBool,

libvirt/resource_libvirt_domain_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,10 @@ func TestAccLibvirtDomain_CaseInsensitiveAttrs_MAC(t *testing.T) {
13331333
{
13341334
Config: config,
13351335
Check: resource.ComposeTestCheckFunc(
1336-
resource.TestCheckResourceAttr("libvirt_domain."+randomDomainName, "network_interface.0.mac", "52:54:00:b2:2f:88"),
1336+
// libvirt always returns upper-cased
1337+
resource.TestCheckResourceAttr("libvirt_domain."+randomDomainName, "network_interface.0.mac", "52:54:00:B2:2F:88"),
13371338
),
1339+
// because the attribute is case insensitive, there should be no plan
13381340
ExpectNonEmptyPlan: false,
13391341
},
13401342
},

0 commit comments

Comments
 (0)