Skip to content

Commit 6536f78

Browse files
authored
Merge pull request dmacvicar#574 from dmacvicar/issue-572
Make MAC address attribute case insensitive
2 parents db01afa + 01004fa commit 6536f78

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,34 @@ func TestAccLibvirtDomain_ShutoffMultiDomainsRunning(t *testing.T) {
13151315
})
13161316
}
13171317

1318+
func TestAccLibvirtDomain_CaseInsensitiveAttrs_MAC(t *testing.T) {
1319+
randomDomainName := acctest.RandString(10)
1320+
var config = fmt.Sprintf(`
1321+
resource "libvirt_domain" "%s" {
1322+
name = "%s"
1323+
network_interface {
1324+
mac = "52:54:00:b2:2f:88"
1325+
}
1326+
}`, randomDomainName, randomDomainName)
1327+
1328+
resource.Test(t, resource.TestCase{
1329+
PreCheck: func() { testAccPreCheck(t) },
1330+
Providers: testAccProviders,
1331+
CheckDestroy: testAccCheckLibvirtDomainDestroy,
1332+
Steps: []resource.TestStep{
1333+
{
1334+
Config: config,
1335+
Check: resource.ComposeTestCheckFunc(
1336+
// libvirt always returns upper-cased
1337+
resource.TestCheckResourceAttr("libvirt_domain."+randomDomainName, "network_interface.0.mac", "52:54:00:B2:2F:88"),
1338+
),
1339+
// because the attribute is case insensitive, there should be no plan
1340+
ExpectNonEmptyPlan: false,
1341+
},
1342+
},
1343+
})
1344+
}
1345+
13181346
func testAccCheckLibvirtDomainStateEqual(name string, domain *libvirt.Domain, exptectedState string) resource.TestCheckFunc {
13191347
return func(s *terraform.State) error {
13201348

0 commit comments

Comments
 (0)