-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/snmp/community get [print show-ids]] | ||
terraform import routeros_snmp_community.test "*0" |
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,12 @@ | ||
resource "routeros_snmp_community" "test" { | ||
authentication_password = "authpasswd" | ||
authentication_protocol = "MD5" | ||
comment = "Comment" | ||
disabled = true | ||
encryption_password = "encpassword" | ||
encryption_protocol = "DES" | ||
name = "private" | ||
read_access = true | ||
security = "private" | ||
write_access = true | ||
} |
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,111 @@ | ||
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 ResourceSNMPCommunity() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/snmp/community"), | ||
MetaId: PropId(Id), | ||
|
||
"addresses": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "::/0", | ||
Description: "Addresses from which connections to SNMP server is allowed.", | ||
ValidateFunc: validation.IsIPAddress, | ||
}, | ||
"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, | ||
} | ||
} |
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,66 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const testSNMPCommunityAddress = "routeros_snmp_community.test" | ||
|
||
func TestAccSNMPCommunityTest_basic(t *testing.T) { | ||
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("/snmp/community", "routeros_snmp_community"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSNMPCommunityConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckSNMPCommunityExists(testSNMPCommunityAddress), | ||
resource.TestCheckResourceAttr(testSNMPCommunityAddress, "name", "private"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccCheckSNMPCommunityExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", name) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no id is set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccSNMPCommunityConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_snmp_community" "test" { | ||
authentication_password = "authpasswd" | ||
authentication_protocol = "MD5" | ||
comment = "Comment" | ||
disabled = true | ||
encryption_password = "encpassword" | ||
encryption_protocol = "DES" | ||
name = "private" | ||
read_access = true | ||
security = "private" | ||
write_access = true | ||
}` | ||
} |