Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dhcp): typo attribute with check elements on list #1242

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/vpc_public_gateway_dhcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following arguments are supported:
- `rebind_timer` - (Optional) After how long, in seconds, a DHCP client will query for a new lease if previous renews fail. Must be 30s lower than `valid_lifetime`. Defaults to 51m (3060s).
- `push_default_route` - (Optional) Whether the gateway should push a default route to DHCP clients or only hand out IPs. Defaults to `true`.
- `push_dns_server` - (Optional) Whether the gateway should push custom DNS servers to clients. This allows for instance hostname -> IP resolution. Defaults to `true`.
- `dns_server_override` - (Optional) Override the DNS server list pushed to DHCP clients, instead of the gateway itself
- `dns_servers_override` - (Optional) Override the DNS server list pushed to DHCP clients, instead of the gateway itself
- `dns_search` - (Optional) Additional DNS search paths
- `dns_local_name` - (Optional) TLD given to hostnames in the Private Network. Allowed characters are `a-z0-9-.`. Defaults to the slugified Private Network name if created along a GatewayNetwork, or else to `priv`.

Expand Down
16 changes: 11 additions & 5 deletions scaleway/resource_vpc_public_gateway_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func resourceScalewayVPCPublicGatewayDHCP() *schema.Resource {
Computed: true,
Description: "Whether the gateway should push custom DNS servers to clients. This allows for instance hostname -> IP resolution. Defaults to true.",
},
"dns_server_override": {
"dns_servers_override": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Expand Down Expand Up @@ -216,11 +216,17 @@ func resourceScalewayVPCPublicGatewayDHCPRead(ctx context.Context, d *schema.Res
return diag.FromErr(err)
}

if len(dhcp.DNSSearch) > 0 {
_ = d.Set("dns_search", flattenSliceString(dhcp.DNSSearch))
}

if len(dhcp.DNSServersOverride) > 0 {
_ = d.Set("dns_servers_override", flattenSliceString(dhcp.DNSServersOverride))
}

_ = d.Set("address", dhcp.Address.String())
_ = d.Set("created_at", dhcp.CreatedAt.Format(time.RFC3339))
_ = d.Set("dns_local_name", dhcp.DNSLocalName)
_ = d.Set("dns_search", flattenSliceString(dhcp.DNSSearch))
_ = d.Set("dns_server_override", flattenSliceString(dhcp.DNSServersOverride))
_ = d.Set("enable_dynamic", dhcp.EnableDynamic)
_ = d.Set("organization_id", dhcp.OrganizationID)
_ = d.Set("pool_high", dhcp.PoolLow.String())
Expand Down Expand Up @@ -297,13 +303,13 @@ func resourceScalewayVPCPublicGatewayDHCPUpdate(ctx context.Context, d *schema.R
req.PoolHigh = scw.IPPtr(net.ParseIP(d.Get("pool_high").(string)))
}

if d.HasChangesExcept("dns_servers_override") {
if d.HasChanges("dns_servers_override") {
if dnsServerOverride, ok := d.GetOk("dns_servers_override"); ok {
req.DNSServersOverride = expandStringsPtr(dnsServerOverride)
}
}

if d.HasChangesExcept("dns_search") {
if d.HasChanges("dns_search") {
if dnsSearch, ok := d.GetOk("dns_search"); ok {
req.DNSSearch = expandStringsPtr(dnsSearch)
}
Expand Down
47 changes: 47 additions & 0 deletions scaleway/resource_vpc_public_gateway_dhcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,53 @@ func TestAccScalewayVPCPublicGatewayDHCP_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "organization_id"),
),
},
{
Config: `
resource "scaleway_vpc_public_gateway_dhcp" main {
subnet = "192.168.1.0/24"
push_default_route = true
push_dns_server = true
enable_dynamic = true
dns_servers_override = ["192.168.1.2"]
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayVPCPublicGatewayDHCPExists(tt, "scaleway_vpc_public_gateway_dhcp.main"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "subnet", "192.168.1.0/24"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "enable_dynamic", "true"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "valid_lifetime", "3000"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "renew_timer", "2000"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "rebind_timer", "2060"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "push_default_route", "true"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "push_dns_server", "true"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "dns_servers_override.#", "1"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "dns_servers_override.0", "192.168.1.2"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "dns_local_name"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "pool_low"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "pool_high"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "created_at"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "updated_at"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "zone"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_dhcp.main", "organization_id"),
),
},
{
Config: `
resource "scaleway_vpc_public_gateway_dhcp" main {
subnet = "192.168.1.0/24"
push_default_route = true
push_dns_server = true
enable_dynamic = true
dns_servers_override = ["192.168.1.3"]
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayVPCPublicGatewayDHCPExists(tt, "scaleway_vpc_public_gateway_dhcp.main"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "subnet", "192.168.1.0/24"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "dns_servers_override.#", "1"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_dhcp.main", "dns_servers_override.0", "192.168.1.3"),
),
},
},
})
}
Expand Down
Loading