-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ns1-terraform:master' into master
- Loading branch information
Showing
8 changed files
with
163 additions
and
9 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
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
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,60 @@ | ||
package ns1 | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
ns1 "gopkg.in/ns1/ns1-go.v2/rest" | ||
) | ||
|
||
func dataSourceMonitoringRegions() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"regions": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"code": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"subnets": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Read: MonitoringingRegionsRead, | ||
} | ||
} | ||
|
||
// MonitoringRegionsRead reads the available Monitoring Regions from ns1. | ||
func MonitoringingRegionsRead(d *schema.ResourceData, meta any) error { | ||
client := meta.(*ns1.Client) | ||
|
||
regions, resp, err := client.MonitorRegions.List() | ||
if err != nil { | ||
return ConvertToNs1Error(resp, err) | ||
} | ||
|
||
out := []map[string]any{} | ||
|
||
for _, region := range regions { | ||
out = append(out, map[string]any{ | ||
"code": region.Code, | ||
"name": region.Name, | ||
"subnets": region.Subnets, | ||
}) | ||
} | ||
|
||
d.SetId("1") | ||
return d.Set("regions", out) | ||
} |
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,51 @@ | ||
package ns1 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccMonitoringRegions_basic(t *testing.T) { | ||
name := "foobar" | ||
resourceName := fmt.Sprintf("data.ns1_monitoring_regions.%s", name) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTeamDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(testAccMonitoringRegionsBasic, name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckMonitoringRegionsLength(resourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckMonitoringRegionsLength( | ||
n string, | ||
) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
regions, ok := s.RootModule().Resources[n] | ||
|
||
if !ok { | ||
return fmt.Errorf("not found: %s", n) | ||
} | ||
|
||
// make sure we get some monitoring regions | ||
if len(regions.Primary.Attributes["regions.#"]) == 0 { | ||
return fmt.Errorf("no monitoring regions found") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccMonitoringRegionsBasic = ` | ||
data "ns1_monitoring_regions" "%s" { | ||
} | ||
` |
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,38 @@ | ||
--- | ||
layout: "ns1" | ||
page_title: "NS1: ns1_monitoring_regions" | ||
sidebar_current: "docs-ns1-datasource-monitoring-regions" | ||
description: |- | ||
Provides details of all available monitoring regions. | ||
--- | ||
|
||
# Data Source: ns1_monitoring_regions | ||
|
||
Provides details of all available monitoring regions. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
# Get details of all available monitoring regions. | ||
data "ns1_monitoring_regions" "example" { | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
There are no required arguments. | ||
|
||
## Attributes Reference | ||
|
||
The following are attributes exported: | ||
|
||
* `regions` - A set of the available monitoring regions. [Regions](#regions) is | ||
documented below. | ||
|
||
#### Regions | ||
|
||
A region has the following fields: | ||
|
||
* `code` - 3-letter city code identifying the location of the monitor. | ||
* `name` - City name identifying the location of the monitor. | ||
* `subnets` - A list of IPv4 and IPv6 subnets the monitor sources requests from. |