Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename data sources apstra_datacenter_blueprint_system_node to apstra_datacenter_system #104

Merged
merged 6 commits into from
May 26, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import (
"terraform-provider-apstra/apstra/blueprint"
)

var _ datasource.DataSourceWithConfigure = &dataSourceBlueprintSystemNode{}
var _ datasource.DataSourceWithConfigure = &dataSourceDatacenterSystemNode{}

type dataSourceBlueprintSystemNode struct {
type dataSourceDatacenterSystemNode struct {
client *apstra.Client
}

func (o *dataSourceBlueprintSystemNode) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_blueprint_system_node"
func (o *dataSourceDatacenterSystemNode) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_system"
}

func (o *dataSourceBlueprintSystemNode) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (o *dataSourceDatacenterSystemNode) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
o.client = DataSourceGetClient(ctx, req, resp)
}

func (o *dataSourceBlueprintSystemNode) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (o *dataSourceDatacenterSystemNode) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "This data source returns details of a specific " +
"*system* Graph DB node (identified by ID) *system* nodes within " +
Expand All @@ -31,7 +31,7 @@ func (o *dataSourceBlueprintSystemNode) Schema(_ context.Context, _ datasource.S
}
}

func (o *dataSourceBlueprintSystemNode) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (o *dataSourceDatacenterSystemNode) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
if o.client == nil {
resp.Diagnostics.AddError(errDataSourceUnconfiguredSummary, errDatasourceUnconfiguredDetail)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
)

const (
dataSourceDataCenterBlueprintSystemNodeHCL = `
data "apstra_datacenter_blueprint_system_node" "test" {
blueprint_id = "%s"
dataSourceDataCenterSystemHCL = `
data "apstra_datacenter_system" "test" {
blueprint_id = "%s"
id = "%s"
}
`
)

func TestDatacenterBlueprintSystemNode_A(t *testing.T) {
func TestDatacenterSystem_A(t *testing.T) {
ctx := context.Background()
client, err := testutils.GetTestClient()
if err != nil {
Expand Down Expand Up @@ -75,21 +75,21 @@ func TestDatacenterBlueprintSystemNode_A(t *testing.T) {
}

// generate the terraform config
dataSourceHCL := fmt.Sprintf(dataSourceDataCenterBlueprintSystemNodeHCL, bpClient.Id(), spine1.Id)
dataSourceHCL := fmt.Sprintf(dataSourceDataCenterSystemHCL, bpClient.Id(), spine1.Id)

// test check functions
testCheckFuncs := []resource.TestCheckFunc{
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "id", spine1.Id),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.hostname", spine1.Hostname),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.label", spine1.Label),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.role", spine1.Role),
resource.TestCheckNoResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.system_id"),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.system_type", spine1.SystemType),
resource.TestCheckResourceAttr("data.apstra_datacenter_blueprint_system_node.test", "attributes.tag_ids.#", strconv.Itoa(len(template.Data.Spine.Tags))),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "id", spine1.Id),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "attributes.hostname", spine1.Hostname),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "attributes.label", spine1.Label),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "attributes.role", spine1.Role),
resource.TestCheckNoResourceAttr("data.apstra_datacenter_system.test", "attributes.system_id"),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "attributes.system_type", spine1.SystemType),
resource.TestCheckResourceAttr("data.apstra_datacenter_system.test", "attributes.tag_ids.#", strconv.Itoa(len(template.Data.Spine.Tags))),
}
for i := range template.Data.Spine.Tags {
testCheckFuncs = append(testCheckFuncs, resource.TestCheckTypeSetElemAttr(
"data.apstra_datacenter_blueprint_system_node.test",
"data.apstra_datacenter_system.test",
"attributes.tag_ids.*",
template.Data.Spine.Tags[i].Label,
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import (
"terraform-provider-apstra/apstra/blueprint"
)

var _ datasource.DataSourceWithConfigure = &dataSourceBlueprintSystemNodes{}
var _ datasource.DataSourceWithConfigure = &dataSourceDatacenterSystemNodes{}

type dataSourceBlueprintSystemNodes struct {
type dataSourceDatacenterSystemNodes struct {
client *apstra.Client
}

func (o *dataSourceBlueprintSystemNodes) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_blueprint_system_nodes"
func (o *dataSourceDatacenterSystemNodes) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_systems"
}

func (o *dataSourceBlueprintSystemNodes) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (o *dataSourceDatacenterSystemNodes) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
o.client = DataSourceGetClient(ctx, req, resp)
}

func (o *dataSourceBlueprintSystemNodes) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (o *dataSourceDatacenterSystemNodes) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "This data source returns Graph DB node IDs of *system* nodes within a Blueprint.\n\n" +
"Optional attributes filter the result list so that it only contains IDs of nodes which match the filters.",
Attributes: blueprint.NodesTypeSystem{}.DataSourceAttributes(),
}
}

func (o *dataSourceBlueprintSystemNodes) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (o *dataSourceDatacenterSystemNodes) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
if o.client == nil {
resp.Diagnostics.AddError(errDataSourceUnconfiguredSummary, errDatasourceUnconfiguredDetail)
return
Expand Down
16 changes: 8 additions & 8 deletions apstra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,13 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource
func() datasource.DataSource { return &dataSourceAsnPools{} },
func() datasource.DataSource { return &dataSourceBlueprintDeploy{} },
func() datasource.DataSource { return &dataSourceBlueprints{} },
func() datasource.DataSource { return &dataSourceBlueprintSystemNodes{} },
func() datasource.DataSource { return &dataSourceBlueprintSystemNode{} },
func() datasource.DataSource { return &dataSourceConfiglet{} },
func() datasource.DataSource { return &dataSourceConfiglets{} },
func() datasource.DataSource { return &dataSourceVirtualNetworkBindingConstructor{} },
func() datasource.DataSource { return &dataSourceDatacenterBlueprint{} },
func() datasource.DataSource { return &dataSourceDatacenterRoutingZone{} },
func() datasource.DataSource { return &dataSourceDatacenterRoutingZones{} },
func() datasource.DataSource { return &dataSourceDatacenterSystemNode{} },
func() datasource.DataSource { return &dataSourceDatacenterSystemNodes{} },
func() datasource.DataSource { return &dataSourceInterfaceMap{} },
func() datasource.DataSource { return &dataSourceInterfaceMaps{} },
func() datasource.DataSource { return &dataSourceIpv4Pool{} },
Expand All @@ -311,14 +313,12 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource
func() datasource.DataSource { return &dataSourcePropertySets{} },
func() datasource.DataSource { return &dataSourceRackType{} },
func() datasource.DataSource { return &dataSourceRackTypes{} },
func() datasource.DataSource { return &dataSourceTag{} },
//func() datasource.DataSource { return &dataSourceTemplateL3Collapsed{} },
//func() datasource.DataSource { return &dataSourceTemplatePodBased{}},
func() datasource.DataSource { return &dataSourceDatacenterRoutingZone{} },
func() datasource.DataSource { return &dataSourceDatacenterRoutingZones{} },
func() datasource.DataSource { return &dataSourceTemplateRackBased{} },
func() datasource.DataSource { return &dataSourceTemplates{} },
func() datasource.DataSource { return &dataSourceDatacenterBlueprint{} },
func() datasource.DataSource { return &dataSourceTag{} },
func() datasource.DataSource { return &dataSourceVirtualNetworkBindingConstructor{} },
func() datasource.DataSource { return &dataSourceVniPool{} },
func() datasource.DataSource { return &dataSourceVniPools{} },
}
Expand All @@ -344,10 +344,10 @@ func (p *Provider) Resources(_ context.Context) []func() resource.Resource {
func() resource.Resource { return &resourcePoolAllocation{} },
func() resource.Resource { return &resourcePropertySet{} },
func() resource.Resource { return &resourceRackType{} },
func() resource.Resource { return &resourceTag{} },
//func() resource.Resource { return &resourceSourceTemplateL3Collapsed{} },
//func() resource.Resource { return &resourceSourceTemplatePodBased{} },
func() resource.Resource { return &resourceTemplateRackBased{} },
func() resource.Resource { return &resourceTag{} },
func() resource.Resource { return &resourceVniPool{} },
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
page_title: "apstra_datacenter_blueprint_system_node Data Source - terraform-provider-apstra"
page_title: "apstra_datacenter_system Data Source - terraform-provider-apstra"
subcategory: ""
description: |-
This data source returns details of a specific system Graph DB node (identified by ID) system nodes within a Blueprint.
---

# apstra_datacenter_blueprint_system_node (Data Source)
# apstra_datacenter_system (Data Source)

This data source returns details of a specific *system* Graph DB node (identified by ID) *system* nodes within a Blueprint.

## Example Usage

```terraform
# This example determines the hostname of the lowest numbered system using
# apstra_datacenter_blueprint_system_nodes data source with a filter to select
# apstra_datacenter_system data source with a filter to select
# system ID 1.
#
# It then uses the returned ID to do a second lookup to get the full details
Expand All @@ -24,20 +24,20 @@ locals {
blueprint_id = "abc-123"
}

data "apstra_datacenter_blueprint_system_nodes" "system_one" {
data "apstra_datacenter_systems" "system_one" {
blueprint_id = local.blueprint_id
filters = {
system_index = 1
}
}

data "apstra_datacenter_blueprint_system_node" "system_one" {
data "apstra_datacenter_system" "system_one" {
blueprint_id = local.blueprint_id
id = one(data.apstra_datacenter_blueprint_system_nodes.system_one.ids)
id = one(data.apstra_datacenter_systems.system_one.ids)
}

locals {
system_one_hostname = data.apstra_datacenter_blueprint_system_node.system_one.hostname
system_one_hostname = data.apstra_datacenter_system.system_one.hostname
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
page_title: "apstra_datacenter_blueprint_system_nodes Data Source - terraform-provider-apstra"
page_title: "apstra_datacenter_systems Data Source - terraform-provider-apstra"
subcategory: ""
description: |-
This data source returns Graph DB node IDs of system nodes within a Blueprint.
Optional attributes filter the result list so that it only contains IDs of nodes which match the filters.
---

# apstra_datacenter_blueprint_system_nodes (Data Source)
# apstra_datacenter_systems (Data Source)

This data source returns Graph DB node IDs of *system* nodes within a Blueprint.

Expand All @@ -17,7 +17,7 @@ Optional attributes filter the result list so that it only contains IDs of nodes
```terraform
# This example outputs a set of graph db node IDs representing all spine
# switches with tag 'junos' and tag 'qfx'
data "apstra_datacenter_blueprint_system_nodes" "juniper_spines" {
data "apstra_datacenter_systems" "juniper_spines" {
blueprint_id = apstra_datacenter_blueprint.example.id
filters = {
role = "spine"
Expand All @@ -27,7 +27,7 @@ data "apstra_datacenter_blueprint_system_nodes" "juniper_spines" {
}

output "qfx_spines" {
value = data.apstra_datacenter_blueprint_system_nodes.juniper_spines.ids
value = data.apstra_datacenter_systems.juniper_spines.ids
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/datacenter_virtual_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This resource creates a Virtual Network within a Blueprint.
# relationship between leaf and access switches, ESI/MLAG redundancy group
# relationships and graph db node IDs of switch and group nodes.
#
# Users are encouraged to use the `apstra_datacenter_blueprint_system_nodes`
# Users are encouraged to use the `apstra_datacenter_systems`
# and `apstra_datacenter_virtual_network_binding_constructor` data sources to
# produce the 'bindings' data.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This example determines the hostname of the lowest numbered system using
# apstra_datacenter_blueprint_system_nodes data source with a filter to select
# apstra_datacenter_system data source with a filter to select
# system ID 1.
#
# It then uses the returned ID to do a second lookup to get the full details
Expand All @@ -10,18 +10,18 @@ locals {
blueprint_id = "abc-123"
}

data "apstra_datacenter_blueprint_system_nodes" "system_one" {
data "apstra_datacenter_systems" "system_one" {
blueprint_id = local.blueprint_id
filters = {
system_index = 1
}
}

data "apstra_datacenter_blueprint_system_node" "system_one" {
data "apstra_datacenter_system" "system_one" {
blueprint_id = local.blueprint_id
id = one(data.apstra_datacenter_blueprint_system_nodes.system_one.ids)
id = one(data.apstra_datacenter_systems.system_one.ids)
}

locals {
system_one_hostname = data.apstra_datacenter_blueprint_system_node.system_one.hostname
system_one_hostname = data.apstra_datacenter_system.system_one.hostname
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This example outputs a set of graph db node IDs representing all spine
# switches with tag 'junos' and tag 'qfx'
data "apstra_datacenter_blueprint_system_nodes" "juniper_spines" {
data "apstra_datacenter_systems" "juniper_spines" {
blueprint_id = apstra_datacenter_blueprint.example.id
filters = {
role = "spine"
Expand All @@ -10,5 +10,5 @@ data "apstra_datacenter_blueprint_system_nodes" "juniper_spines" {
}

output "qfx_spines" {
value = data.apstra_datacenter_blueprint_system_nodes.juniper_spines.ids
value = data.apstra_datacenter_systems.juniper_spines.ids
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# relationship between leaf and access switches, ESI/MLAG redundancy group
# relationships and graph db node IDs of switch and group nodes.
#
# Users are encouraged to use the `apstra_datacenter_blueprint_system_nodes`
# Users are encouraged to use the `apstra_datacenter_systems`
# and `apstra_datacenter_virtual_network_binding_constructor` data sources to
# produce the 'bindings' data.

Expand Down