Add support for local_dns_record (#293)
This commit is contained in:
committed by
GitHub
parent
a351398f9e
commit
1a9bac4a09
@@ -37,6 +37,7 @@ data "unifi_user" "client" {
|
||||
- `hostname` (String) The hostname of the user.
|
||||
- `id` (String) The ID of the user.
|
||||
- `ip` (String) The IP address of the user.
|
||||
- `local_dns_record` (String) The local DNS record for this user.
|
||||
- `name` (String) The name of the user.
|
||||
- `network_id` (String) The network ID for this user.
|
||||
- `note` (String) A note with additional information for the user.
|
||||
|
||||
@@ -40,6 +40,7 @@ resource "unifi_user" "test" {
|
||||
- `blocked` (Boolean) Specifies whether this user should be blocked from the network.
|
||||
- `dev_id_override` (Number) Override the device fingerprint.
|
||||
- `fixed_ip` (String) A fixed IPv4 address for this user.
|
||||
- `local_dns_record` (String) Specifies the local DNS record for this user.
|
||||
- `network_id` (String) The network ID for this user.
|
||||
- `note` (String) A note with additional information for the user.
|
||||
- `site` (String) The name of the site to associate the user with.
|
||||
|
||||
@@ -81,6 +81,11 @@ func dataUser() *schema.Resource {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"local_dns_record": {
|
||||
Description: "The local DNS record for this user.",
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -111,6 +116,10 @@ func dataUserRead(ctx context.Context, d *schema.ResourceData, meta interface{})
|
||||
if resp.UseFixedIP {
|
||||
fixedIP = resp.FixedIP
|
||||
}
|
||||
localDnsRecord := ""
|
||||
if resp.LocalDNSRecordEnabled {
|
||||
localDnsRecord = resp.LocalDNSRecord
|
||||
}
|
||||
d.SetId(resp.ID)
|
||||
d.Set("site", site)
|
||||
d.Set("mac", resp.MAC)
|
||||
@@ -123,6 +132,7 @@ func dataUserRead(ctx context.Context, d *schema.ResourceData, meta interface{})
|
||||
d.Set("dev_id_override", resp.DevIdOverride)
|
||||
d.Set("hostname", resp.Hostname)
|
||||
d.Set("ip", resp.IP)
|
||||
d.Set("ip", localDnsRecord)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -83,6 +83,11 @@ func resourceUser() *schema.Resource {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"local_dns_record": {
|
||||
Description: "Specifies the local DNS record for this user.",
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
// these are "meta" attributes that control TF UX
|
||||
"allow_existing": {
|
||||
@@ -177,15 +182,18 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf
|
||||
|
||||
func resourceUserGetResourceData(d *schema.ResourceData) (*unifi.User, error) {
|
||||
fixedIP := d.Get("fixed_ip").(string)
|
||||
localDnsRecord := d.Get("local_dns_record").(string)
|
||||
|
||||
return &unifi.User{
|
||||
MAC: d.Get("mac").(string),
|
||||
Name: d.Get("name").(string),
|
||||
UserGroupID: d.Get("user_group_id").(string),
|
||||
Note: d.Get("note").(string),
|
||||
FixedIP: fixedIP,
|
||||
UseFixedIP: fixedIP != "",
|
||||
NetworkID: d.Get("network_id").(string),
|
||||
MAC: d.Get("mac").(string),
|
||||
Name: d.Get("name").(string),
|
||||
UserGroupID: d.Get("user_group_id").(string),
|
||||
Note: d.Get("note").(string),
|
||||
FixedIP: fixedIP,
|
||||
UseFixedIP: fixedIP != "",
|
||||
LocalDNSRecord: localDnsRecord,
|
||||
LocalDNSRecordEnabled: localDnsRecord != "",
|
||||
NetworkID: d.Get("network_id").(string),
|
||||
// not sure if this matters/works
|
||||
Blocked: d.Get("blocked").(bool),
|
||||
DevIdOverride: d.Get("dev_id_override").(int),
|
||||
@@ -198,12 +206,18 @@ func resourceUserSetResourceData(resp *unifi.User, d *schema.ResourceData, site
|
||||
fixedIP = resp.FixedIP
|
||||
}
|
||||
|
||||
localDnsRecord := ""
|
||||
if resp.LocalDNSRecordEnabled {
|
||||
localDnsRecord = resp.LocalDNSRecord
|
||||
}
|
||||
|
||||
d.Set("site", site)
|
||||
d.Set("mac", resp.MAC)
|
||||
d.Set("name", resp.Name)
|
||||
d.Set("user_group_id", resp.UserGroupID)
|
||||
d.Set("note", resp.Note)
|
||||
d.Set("fixed_ip", fixedIP)
|
||||
d.Set("local_dns_record", localDnsRecord)
|
||||
d.Set("network_id", resp.NetworkID)
|
||||
d.Set("blocked", resp.Blocked)
|
||||
d.Set("dev_id_override", resp.DevIdOverride)
|
||||
|
||||
@@ -232,6 +232,43 @@ func TestAccUser_fingerprint(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccUser_localdns(t *testing.T) {
|
||||
testMAC := generateTestMac()
|
||||
vlanID := 301
|
||||
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
preCheck(t)
|
||||
preCheckVersionConstraint(t, ">= 7.2.91")
|
||||
},
|
||||
ProviderFactories: providerFactories,
|
||||
CheckDestroy: testCheckUserDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccUserConfig(testMAC, "tfacc", ""),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("unifi_user.test", "local_dns_record", ""),
|
||||
),
|
||||
},
|
||||
userImportStep("unifi_user.test"),
|
||||
{
|
||||
Config: testAccUserConfig_localdns(vlanID, testMAC, "tfacc", "resource.example.com"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("unifi_user.test", "local_dns_record", "resource.example.com"),
|
||||
),
|
||||
},
|
||||
userImportStep("unifi_user.test"),
|
||||
{
|
||||
Config: testAccUserConfig_localdns(vlanID, testMAC, "tfacc", ""),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("unifi_user.test", "local_dns_record", ""),
|
||||
),
|
||||
},
|
||||
userImportStep("unifi_user.test"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testCheckUserDestroy(s *terraform.State) error {
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "unifi_user" {
|
||||
@@ -329,3 +366,16 @@ resource "unifi_user" "test" {
|
||||
}
|
||||
`, mac, name, devIdOverride)
|
||||
}
|
||||
|
||||
func testAccUserConfig_localdns(vlanID int, mac, name string, localDnsRecord string) string {
|
||||
return fmt.Sprintf(testAccUserConfig_network(vlanID)+`
|
||||
resource "unifi_user" "test" {
|
||||
mac = "%s"
|
||||
name = "%s"
|
||||
|
||||
fixed_ip = "10.1.10.50"
|
||||
network_id = unifi_network.test.id
|
||||
local_dns_record = "%s"
|
||||
}
|
||||
`, mac, name, localDnsRecord)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user