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

Mark optional field as computed to prevent error after apply #190

Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions mikrotik/resource_bgp_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (s *bgpPeer) Schema(_ context.Context, _ resource.SchemaRequest, resp *reso
},
"instance": schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString("default"),
Description: "The name of the instance this peer belongs to. See Mikrotik bgp instance resource.",
},
"keepalive_time": schema.StringAttribute{
Expand Down
1 change: 1 addition & 0 deletions mikrotik/resource_dhcp_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (s *dhcpLease) Schema(_ context.Context, _ resource.SchemaRequest, resp *re
},
"comment": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "The comment of the DHCP lease to be created.",
},
"blocked": schema.BoolAttribute{
Expand Down
1 change: 1 addition & 0 deletions mikrotik/resource_interface_wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (i *interfaceWireguard) Schema(_ context.Context, _ resource.SchemaRequest,
},
"comment": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "Comment associated with interface wireguard.",
},
"disabled": schema.BoolAttribute{
Expand Down
1 change: 1 addition & 0 deletions mikrotik/resource_ipv6_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (s *ipv6Address) Schema(_ context.Context, _ resource.SchemaRequest, resp *
},
"comment": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "The comment for the IPv6 address assignment.",
},
"disabled": schema.BoolAttribute{
Expand Down
30 changes: 30 additions & 0 deletions mikrotik/resource_ipv6_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ func TestAccMikrotikResourceIpv6Address_create(t *testing.T) {
})
}

func TestAccMikrotikResourceIpv6Address_create_onlyRequiredFields(t *testing.T) {
client.SkipIfRouterOSV6OrEarlier(t, sysResources)

ipv6Addr := internal.GetNewIpv6Addr() + "/64"
ifName := "ether1"

resourceName := "mikrotik_ipv6_address.test_required_fields"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckMikrotikIpv6AddressDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`resource "mikrotik_ipv6_address" "test_required_fields" {
address = "%s"
interface = "%s"
}`, ipv6Addr, ifName,
),
Check: resource.ComposeAggregateTestCheckFunc(
testAccIpv6AddressExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "address", ipv6Addr),
resource.TestCheckResourceAttr(resourceName, "interface", ifName),
resource.TestCheckResourceAttr(resourceName, "comment", ""),
),
},
},
})
}

func TestAccMikrotikResourceIpv6Address_updateAddr(t *testing.T) {
client.SkipIfRouterOSV6OrEarlier(t, sysResources)

Expand Down
2 changes: 2 additions & 0 deletions mikrotik/resource_vlan_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (s *vlanInterface) Schema(_ context.Context, _ resource.SchemaRequest, resp
},
"vlan_id": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(1),
Description: "Virtual LAN identifier or tag that is used to distinguish VLANs. Must be equal for all computers that belong to the same VLAN.",
},
},
Expand Down
36 changes: 36 additions & 0 deletions mikrotik/resource_vlan_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ func TestVlanInterface_basic(t *testing.T) {
})
}

func TestVlanInterface_noVlanID(t *testing.T) {
resourceName := "mikrotik_vlan_interface.testacc"
iface := "ether1"
mtu := 1500
name := "test-vlan"
useServiceTag := false
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckVlanInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccVlanInterfaceNoVLANID(iface, mtu, name, useServiceTag),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVlanInterfaceExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "mtu", strconv.Itoa(mtu)),
resource.TestCheckResourceAttr(resourceName, "vlan_id", "1"),
),
},
},
})
}

func testAccVlanInterfaceExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -103,3 +128,14 @@ func testAccVlanInterface(iface string, mtu int, name string, useServiceTag bool
}
`, iface, mtu, name, useServiceTag, vlanID)
}

func testAccVlanInterfaceNoVLANID(iface string, mtu int, name string, useServiceTag bool) string {
return fmt.Sprintf(`
resource "mikrotik_vlan_interface" "testacc" {
interface = %q
mtu = %d
name = %q
use_service_tag = %t
}
`, iface, mtu, name, useServiceTag)
}