Skip to content

Commit

Permalink
feat(networks): add default value to networks data source (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimehk authored Dec 16, 2024
1 parent d4267a2 commit 13cc3a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data "katapult_networks" "all" {}
Read-Only:

- `data_center_id` (String) The ID of the data center this network belongs to.
- `default` (Boolean) True if this is the default network for the data center it belongs to.
- `id` (String) The ID of this resource.
- `name` (String) The name of the network.
- `permalink` (String) The permalink of the network.
15 changes: 7 additions & 8 deletions internal/v6provider/data_source_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ func (nds *NetworksDataSource) Configure(
}

func NetworkListType() types.ObjectType {
t := NetworkType()

// When fetching a list of Networks we do not include the "default"
// attribute, as it currently requires separate API calls for each data
// center.
delete(t.AttrTypes, "default")

return t
return NetworkType()
}

func (nds *NetworksDataSource) Schema(
Expand Down Expand Up @@ -86,6 +79,11 @@ func (nds *NetworksDataSource) Schema(
Description: "The ID of the data center this " +
"network belongs to.",
},
"default": schema.BoolAttribute{
Computed: true,
Description: "True if this is the default " +
"network for the data center it belongs to.",
},
},
},
},
Expand Down Expand Up @@ -129,6 +127,7 @@ func (nds *NetworksDataSource) Read(
"name": types.StringPointerValue(network.Name),
"permalink": types.StringValue(permalink),
"data_center_id": types.StringPointerValue(network.DataCenter.Id),
"default": types.BoolPointerValue(network.Default),
}

list[i] = types.ObjectValueMust(NetworkListType().AttrTypes, attrs)
Expand Down
5 changes: 5 additions & 0 deletions internal/v6provider/data_source_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func testAccCheckKatapultNetworksAttrs(
"id": *network.Id,
"name": *network.Name,
"data_center_id": *network.DataCenter.Id,
"default": "false",
}

if *network.Default {
attrs["default"] = "true"
}

if !network.Permalink.IsNull() {
Expand Down

0 comments on commit 13cc3a9

Please sign in to comment.