Skip to content

Commit

Permalink
fix: Add state migrator to routeros_snmp_community to fix backward …
Browse files Browse the repository at this point in the history
…compatibility
  • Loading branch information
dokmic committed Jun 29, 2024
1 parent eec9f38 commit 9fdea29
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
8 changes: 8 additions & 0 deletions routeros/resource_snmp_community.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,13 @@ func ResourceSNMPCommunity() *schema.Resource {
},

Schema: resSchema,
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: ResourceSNMPCommunityV0().CoreConfigSchema().ImpliedType(),
Upgrade: stateMigrationScalarToList("addresses"),
Version: 0,
},
},
}
}
110 changes: 110 additions & 0 deletions routeros/resource_snmp_community_v0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

/*
{
".id": "*2",
"addresses": "::/0",
"authentication-password": "",
"authentication-protocol": "MD5",
"comment": "Comment",
"default": "false",
"disabled": "true",
"encryption-password": "",
"encryption-protocol": "DES",
"name": "private",
"read-access": "true",
"security": "none",
"write-access": "false"
}
*/

// https://help.mikrotik.com/docs/display/ROS/SNMP#SNMP-CommunityProperties
func ResourceSNMPCommunityV0() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/snmp/community"),
MetaId: PropId(Id),

"addresses": {
Type: schema.TypeString,
Optional: true,
Description: "Set of IP (v4 or v6) addresses or CIDR networks from which connections to SNMP server are allowed.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"authentication_password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Password used to authenticate the connection to the server (SNMPv3).",
},
"authentication_protocol": {
Type: schema.TypeString,
Optional: true,
Default: "MD5",
Description: "The protocol used for authentication (SNMPv3).",
ValidateFunc: validation.StringInSlice([]string{"MD5", "SHA1"}, false),
},
KeyComment: PropCommentRw,
"default": {
Type: schema.TypeBool,
Computed: true,
Description: "It's a default community.",
},
KeyDisabled: PropDisabledRw,
"encryption_password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "The password used for encryption (SNMPv3).",
},
"encryption_protocol": {
Type: schema.TypeString,
Optional: true,
Default: "DES",
Description: "encryption protocol to be used to encrypt the communication (SNMPv3). AES (see rfc3826) " +
"available since v6.16.",
ValidateFunc: validation.StringInSlice([]string{"DES", "AES"}, false),
},

"name": {
Type: schema.TypeString,
Optional: true,
Description: "Community Name.",
},
"read_access": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Whether read access is enabled for this community.",
},
"security": {
Type: schema.TypeString,
Optional: true,
Default: "none",
Description: "Security features.",
ValidateFunc: validation.StringInSlice([]string{"authorized", "none", "private"}, false),
},
"write_access": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether write access is enabled for this community.",
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}

0 comments on commit 9fdea29

Please sign in to comment.