Skip to content

Commit

Permalink
feat: Add routeros_ip_cloud_advanced resource to manage advanced cl…
Browse files Browse the repository at this point in the history
…oud settings
  • Loading branch information
dokmic committed Jan 22, 2024
1 parent 87f06c0 commit 405827d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/resources/routeros_ip_cloud_advanced/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import routeros_ip_cloud_advanced.settings .
3 changes: 3 additions & 0 deletions examples/resources/routeros_ip_cloud_advanced/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "routeros_ip_cloud_advanced" "settings" {
use_local_address = true
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func Provider() *schema.Provider {

// System Objects
"routeros_ip_cloud": ResourceIpCloud(),
"routeros_ip_cloud_advanced": ResourceIpCloudAdvanced(),
"routeros_system_certificate": ResourceSystemCertificate(),
"routeros_system_identity": ResourceSystemIdentity(),
"routeros_system_logging": ResourceSystemLogging(),
Expand Down
39 changes: 39 additions & 0 deletions routeros/resource_ip_cloud_advanced.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package routeros

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

/*
{
"use-local-address":"false"
}
*/

// https://help.mikrotik.com/docs/display/ROS/Cloud#Cloud-Advanced
func ResourceIpCloudAdvanced() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/cloud/advanced"),
MetaId: PropId(Id),

"use_local_address": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option whether to assign an internal router address to the dynamic DNS name.",
},
}

return &schema.Resource{
CreateContext: DefaultSystemCreate(resSchema),
ReadContext: DefaultSystemRead(resSchema),
UpdateContext: DefaultSystemUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

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

Schema: resSchema,
}
}
53 changes: 53 additions & 0 deletions routeros/resource_ip_cloud_advanced_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package routeros

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testIpCloudAdvancedAddress = "routeros_ip_cloud_advanced.test"

func TestAccIpCloudAdvancedTest_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,
Steps: []resource.TestStep{
{
Config: testAccIpCloudAdvancedConfig(0),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpCloudAdvancedAddress),
resource.TestCheckResourceAttr(testIpCloudAdvancedAddress, "use_local_address", "true"),
),
},
{
Config: testAccIpCloudAdvancedConfig(1),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpCloudAdvancedAddress),
resource.TestCheckResourceAttr(testIpCloudAdvancedAddress, "use_local_address", "false"),
),
},
},
})
})
}
}

func testAccIpCloudAdvancedConfig(n int) string {
var conf = []string{
`
resource "routeros_ip_cloud_advanced" "test" {
use_local_address = true
}`,
`
resource "routeros_ip_cloud_advanced" "test" {
use_local_address = false
}`,
}
return providerConfig + conf[n]
}

0 comments on commit 405827d

Please sign in to comment.