-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file): Add support for /file (#355)
* feat(no-release): Add support for /file
- Loading branch information
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# routeros_file (Resource) | ||
|
||
|
||
## Example Usage | ||
```terraform | ||
resource "routeros_file" "test" { | ||
name = "test" | ||
contents = "This is a test" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the file | ||
|
||
### Optional | ||
|
||
- `___id___` (Number) <em>Resource ID type (.id / name). This is an internal service field, setting a value is not required.</em> | ||
- `___path___` (String) <em>Resource path for CRUD operations. This is an internal service field, setting a value is not required.</em> | ||
- `contents` (String) The actual content of the file | ||
|
||
### Read-Only | ||
|
||
- `creation_time` (String) A time when the file was created | ||
- `id` (String) The ID of this resource. | ||
- `package_architecture` (String) Architecture that package is built for. Applies only to RouterOS ".npk" files | ||
- `package_built_time` (String) A time when the package was built. Applies only to RouterOS ".npk" files | ||
- `package_name` (String) Name of the installable package. Applies only to RouterOS ".npk" files | ||
- `package_version` (String) A version of the installable package. Applies only to RouterOS ".npk" files | ||
- `size` (Number) File size in bytes | ||
- `type` (String) Type of the file. For folders, the file type is the directory | ||
|
||
## Import | ||
Import is supported using the following syntax: | ||
```shell | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/file get [print show-ids]] | ||
terraform import routeros_file.test "*1" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/file get [print show-ids]] | ||
terraform import routeros_file.test "*1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
resource "routeros_file" "test" { | ||
name = "test" | ||
contents = "This is a test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// https://help.mikrotik.com/docs/pages/viewpage.action?pageId=2555971 | ||
func ResourceFile() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/file"), | ||
MetaId: PropId(Id), | ||
|
||
"contents": { | ||
Type: schema.TypeString, | ||
ForceNew: true, | ||
Optional: true, | ||
Description: "The actual content of the file", | ||
}, | ||
"creation_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A time when the file was created", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the file", | ||
}, | ||
"package_architecture": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Architecture that package is built for. Applies only to RouterOS \".npk\" files", | ||
}, | ||
"package_built_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A time when the package was built. Applies only to RouterOS \".npk\" files", | ||
}, | ||
"package_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Name of the installable package. Applies only to RouterOS \".npk\" files", | ||
}, | ||
"package_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A version of the installable package. Applies only to RouterOS \".npk\" files", | ||
}, | ||
"size": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "File size in bytes", | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Type of the file. For folders, the file type is the directory", | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(resSchema), | ||
|
||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: resSchema, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package routeros | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testFileMinVersion = "7.9" | ||
const testFile = "routeros_file.test" | ||
|
||
func TestAccFileTest_basic(t *testing.T) { | ||
if !testCheckMinVersion(t, testFileMinVersion) { | ||
t.Logf("Test skipped, the minimum required version is %v", testFileMinVersion) | ||
return | ||
} | ||
|
||
for _, name := range testNames { | ||
t.Run(name, func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
testSetTransportEnv(t, name) | ||
}, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testCheckResourceDestroy("/file", "routeros_file"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFileConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testFile), | ||
resource.TestCheckResourceAttr(testFile, "name", "test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccFileConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_file" "test" { | ||
name = "test" | ||
contents = "This is a test" | ||
} | ||
` | ||
} |