Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions civo/network/datasource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ func DataSourceNetwork() *schema.Resource {
Computed: true,
Description: "If is the default network",
},
"cidr_v4": {
Type: schema.TypeString,
Computed: true,
Description: "The CIDR block for the network",
},
"nameservers_v4": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of nameservers for the network",
},
},
}
}
Expand Down Expand Up @@ -90,6 +103,8 @@ func dataSourceNetworkRead(_ context.Context, d *schema.ResourceData, m interfac
d.Set("label", foundNetwork.Label)
d.Set("region", apiClient.Region)
d.Set("default", foundNetwork.Default)
d.Set("cidr_v4", foundNetwork.CIDR)
d.Set("nameservers_v4", foundNetwork.NameserversV4)

return nil
}
4 changes: 4 additions & 0 deletions civo/network/datasource_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestAccDataSourceCivoNetwork_basic(t *testing.T) {
Config: DataSourceCivoNetworkConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "label", name),
resource.TestCheckResourceAttr(datasourceName, "cidr_v4", "10.0.0.0/24"),
resource.TestCheckResourceAttr(datasourceName, "nameservers_v4.#", "3"),
),
},
},
Expand All @@ -32,6 +34,8 @@ func DataSourceCivoNetworkConfig(name string) string {
resource "civo_network" "foobar" {
label = "%s"
region = "LON1"
cidr_v4 = "10.0.0.0/24"
nameservers_v4 = ["8.8.8.8", "8.8.4.4", "1.1.1.1"]
}

data "civo_network" "foobar" {
Expand Down
14 changes: 10 additions & 4 deletions docs/data-sources/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ Networks may be looked up by id or label, and you can optionally pass region if
data "civo_network" "test" {
label = "test-network"
region = "LON1"
cidr_v4 = "10.0.0.0/24"
nameservers_v4 = ["8.8.8.8", "8.8.4.4", "1.1.1.1"]
}

output "network_cidr_v4" {
value = data.civo_network.test.cidr_v4
}

output "network_nameservers_v4" {
value = data.civo_network.test.nameservers_v4
}
```

Expand All @@ -37,8 +43,8 @@ data "civo_network" "test" {

### Read-Only

- `cidr_v4` (String) The CIDR block for the network
- `default` (Boolean) If is the default network
- `id` (String) The ID of this resource.
- `name` (String) The name of the network


- `nameservers_v4` (List of String) List of nameservers for the network
10 changes: 8 additions & 2 deletions examples/data-sources/civo_network/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
data "civo_network" "test" {
label = "test-network"
region = "LON1"
cidr_v4 = "10.0.0.0/24"
nameservers_v4 = ["8.8.8.8", "8.8.4.4", "1.1.1.1"]
}

output "network_cidr_v4" {
value = data.civo_network.test.cidr_v4
}

output "network_nameservers_v4" {
value = data.civo_network.test.nameservers_v4
}
Loading