Skip to content

Commit d05f4c0

Browse files
committedMar 17, 2025··
feat(ip): Add /ip/smb resource
1 parent eccc99f commit d05f4c0

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed
 

‎docs/resources/ip_smb.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# routeros_ip_smb (Resource)
2+
3+
4+
## Example Usage
5+
```terraform
6+
resource "routeros_ip_smb" "test" {
7+
enabled = "auto"
8+
domain = "MSHOME"
9+
comment = "MikrotikSMB"
10+
interfaces = ["all"]
11+
}
12+
```
13+
14+
<!-- schema generated by tfplugindocs -->
15+
## Schema
16+
17+
### Optional
18+
19+
- `comment` (String) Set comment for the server.
20+
- `domain` (String) Name of Windows Workgroup.
21+
- `enabled` (String) The default value is 'auto'. This means that the SMB server will automatically be enabled when the first non-disabled SMB share is configured under '/ip smb share'.
22+
- `interfaces` (Set of String) List of interfaces on which SMB service will be running.
23+
24+
### Read-Only
25+
26+
- `id` (String) The ID of this resource.
27+
- `status` (String)
28+
29+
## Import
30+
Import is supported using the following syntax:
31+
```shell
32+
terraform import routeros_ip_smb.test .
33+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import routeros_ip_smb.test .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "routeros_ip_smb" "test" {
2+
enabled = "auto"
3+
domain = "MSHOME"
4+
comment = "MikrotikSMB"
5+
interfaces = ["all"]
6+
}

‎routeros/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func Provider() *schema.Provider {
135135
"routeros_ip_pool": ResourceIPPool(),
136136
"routeros_ip_route": ResourceIPRoute(),
137137
"routeros_ip_service": ResourceIpService(),
138+
"routeros_ip_smb": ResourceIpSMB(),
138139
"routeros_ip_ssh_server": ResourceIpSSHServer(),
139140
"routeros_ip_upnp": ResourceUPNPSettings(),
140141
"routeros_ip_upnp_interfaces": ResourceUPNPInterfaces(),

‎routeros/resource_ip_smb.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package routeros
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5+
)
6+
7+
/*
8+
{
9+
"enabled": "auto",
10+
"status": "disabled",
11+
"domain": "MSHOME",
12+
"comment": "MikrotikSMB",
13+
"interfaces": "all"
14+
}
15+
*/
16+
17+
// https://help.mikrotik.com/docs/spaces/ROS/pages/117145608/SMB
18+
func ResourceIpSMB() *schema.Resource {
19+
resSchema := map[string]*schema.Schema{
20+
MetaResourcePath: PropResourcePath("/ip/smb"),
21+
MetaId: PropId(Id),
22+
23+
KeyEnabled: {
24+
Type: schema.TypeString,
25+
Optional: true,
26+
Description: "The default value is 'auto'. This means that the SMB server will automatically be enabled when the first non-disabled SMB share is configured under '/ip smb share'.",
27+
DiffSuppressFunc: AlwaysPresentNotUserProvided,
28+
ValidateFunc: ValidationAutoYesNo,
29+
},
30+
"domain": {
31+
Type: schema.TypeString,
32+
Optional: true,
33+
Description: "Name of Windows Workgroup.",
34+
DiffSuppressFunc: AlwaysPresentNotUserProvided,
35+
},
36+
KeyComment: {
37+
Type: schema.TypeString,
38+
Optional: true,
39+
Description: "Set comment for the server.",
40+
DiffSuppressFunc: AlwaysPresentNotUserProvided,
41+
},
42+
"interfaces": {
43+
Type: schema.TypeSet,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeString,
46+
},
47+
Optional: true,
48+
Description: "List of interfaces on which SMB service will be running.",
49+
DiffSuppressFunc: AlwaysPresentNotUserProvided,
50+
},
51+
"status": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
},
55+
}
56+
57+
return &schema.Resource{
58+
CreateContext: DefaultSystemCreate(resSchema),
59+
ReadContext: DefaultSystemRead(resSchema),
60+
UpdateContext: DefaultSystemUpdate(resSchema),
61+
DeleteContext: DefaultSystemDelete(resSchema),
62+
63+
Importer: &schema.ResourceImporter{
64+
StateContext: schema.ImportStatePassthroughContext,
65+
},
66+
67+
Schema: resSchema,
68+
}
69+
}

‎routeros/resource_ip_smb_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package routeros
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
)
9+
10+
const testIpSMBTask = "routeros_ip_smb.test"
11+
12+
func TestAccIpSMBTest_basic(t *testing.T) {
13+
for _, name := range testNames {
14+
t.Run(name, func(t *testing.T) {
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() {
17+
testAccPreCheck(t)
18+
testSetTransportEnv(t, name)
19+
},
20+
ProviderFactories: testAccProviderFactories,
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccIpSMBConfig("auto", "MSHOME", "MikrotikSMB", "all"),
24+
Check: resource.ComposeTestCheckFunc(
25+
testResourcePrimaryInstanceId(testIpSMBTask),
26+
resource.TestCheckResourceAttr(testIpSMBTask, "enabled", "auto"),
27+
resource.TestCheckResourceAttr(testIpSMBTask, "domain", "MSHOME"),
28+
resource.TestCheckResourceAttr(testIpSMBTask, "comment", "MikrotikSMB"),
29+
resource.TestCheckResourceAttr(testIpSMBTask, "interfaces", "all"),
30+
),
31+
},
32+
},
33+
})
34+
35+
})
36+
}
37+
}
38+
39+
func testAccIpSMBConfig(enabled, domain, comment, _interface string) string {
40+
return fmt.Sprintf(`%v
41+
resource "routeros_ip_smb" "test" {
42+
enabled = "%v"
43+
domain = "%v"
44+
comment = "%v"
45+
interfaces = ["%v"]
46+
}
47+
`, providerConfig, enabled, domain, comment, _interface)
48+
}

0 commit comments

Comments
 (0)
Please sign in to comment.