Skip to content

Commit

Permalink
Merge pull request #603 from Juniper/fabric-settings
Browse files Browse the repository at this point in the history
Introduce support for attributes from `FabricSettings{}` in resource `apstra_datacenter_blueprint`
  • Loading branch information
chrismarget-j authored Mar 5, 2024
2 parents 6110e2c + 35c6016 commit bec13e5
Show file tree
Hide file tree
Showing 15 changed files with 2,451 additions and 463 deletions.
6 changes: 6 additions & 0 deletions apstra/api_versions/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
)

var (
Ge411 = version.MustConstraints(version.NewConstraint(">=" + Apstra411))
Ge420 = version.MustConstraints(version.NewConstraint(">=" + Apstra420))
Ge421 = version.MustConstraints(version.NewConstraint(">=" + Apstra421))
)

type AttributeConstraint struct {
Path path.Path
Constraints version.Constraints
Expand Down
1 change: 1 addition & 0 deletions apstra/api_versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const (
Apstra411 = "4.1.1"
Apstra412 = "4.1.2"
Apstra420 = "4.2.0"
Apstra421 = "4.2.1"
)
102 changes: 102 additions & 0 deletions apstra/blueprint/anti_affinity_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package blueprint

import (
"context"
"math"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/attr"
dataSourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type AntiAffinityPolicy struct {
MaxLinksCountPerSlot types.Int64 `tfsdk:"max_links_count_per_slot"`
MaxLinksCountPerSystemPerSlot types.Int64 `tfsdk:"max_links_count_per_system_per_slot"`
MaxLinksCountPerPort types.Int64 `tfsdk:"max_links_count_per_port"`
MaxLinksCountPerSystemPerPort types.Int64 `tfsdk:"max_links_count_per_system_per_port"`
}

func (o AntiAffinityPolicy) attrTypes() map[string]attr.Type {
return map[string]attr.Type{
"max_links_count_per_slot": types.Int64Type,
"max_links_count_per_system_per_slot": types.Int64Type,
"max_links_count_per_port": types.Int64Type,
"max_links_count_per_system_per_port": types.Int64Type,
}
}

func (o AntiAffinityPolicy) datasourceAttributes() map[string]dataSourceSchema.Attribute {
return map[string]dataSourceSchema.Attribute{
"max_links_count_per_slot": dataSourceSchema.Int64Attribute{
Computed: true,
MarkdownDescription: "Maximum total number of links connected to ports/interfaces of the specified slot regardless of the system" +
"they are targeted to. It controls how many links can be connected to one slot of one system. " +
"Example: A line card slot in a chassis.",
},
"max_links_count_per_system_per_slot": dataSourceSchema.Int64Attribute{
Computed: true,
MarkdownDescription: "Restricts the number of links to a certain system connected to the ports/interfaces in a specific slot. " +
"It controls how many links can be connected to one system to one slot of another system.",
},
"max_links_count_per_port": dataSourceSchema.Int64Attribute{
Computed: true,
MarkdownDescription: "Maximum total number of links connected to the interfaces of the specific port regardless of the system " +
"they are targeted to. It controls how many links can be connected to one port in one system. " +
"Example: Several transformations of one port. In this case, it controls how many transformations can be used in links.",
},
"max_links_count_per_system_per_port": dataSourceSchema.Int64Attribute{
Computed: true,
MarkdownDescription: "Restricts the number of interfaces on a port used to connect to a certain system. It controls " +
"how many links can be connected from one system to one port of another system. This is the one that you will " +
"most likely use, for port breakouts.",
},
}
}

func (o AntiAffinityPolicy) resourceAttributes() map[string]resourceSchema.Attribute {
return map[string]resourceSchema.Attribute{
"max_links_count_per_slot": resourceSchema.Int64Attribute{
Optional: true,
Computed: true,
MarkdownDescription: "Maximum total number of links connected to ports/interfaces of the specified slot regardless of the system" +
"they are targeted to. It controls how many links can be connected to one slot of one system. " +
"Example: A line card slot in a chassis.",
Validators: []validator.Int64{int64validator.Between(0, math.MaxUint8)},
},
"max_links_count_per_system_per_slot": resourceSchema.Int64Attribute{
Optional: true,
Computed: true,
MarkdownDescription: "Restricts the number of links to a certain system connected to the ports/interfaces in a specific slot. " +
"It controls how many links can be connected to one system to one slot of another system.",
Validators: []validator.Int64{int64validator.Between(0, math.MaxUint8)},
},
"max_links_count_per_port": resourceSchema.Int64Attribute{
Optional: true,
Computed: true,
MarkdownDescription: "Maximum total number of links connected to the interfaces of the specific port regardless of the system " +
"they are targeted to. It controls how many links can be connected to one port in one system. " +
"Example: Several transformations of one port. In this case, it controls how many transformations can be used in links.",
Validators: []validator.Int64{int64validator.Between(0, math.MaxUint8)},
},
"max_links_count_per_system_per_port": resourceSchema.Int64Attribute{
Optional: true,
Computed: true,
MarkdownDescription: "Restricts the number of interfaces on a port used to connect to a certain system. It controls " +
"how many links can be connected from one system to one port of another system. This is the one that you will " +
"most likely use, for port breakouts.",
Validators: []validator.Int64{int64validator.Between(0, math.MaxUint8)},
},
}
}

func (o *AntiAffinityPolicy) loadApiData(_ context.Context, in *apstra.AntiAffinityPolicy, _ *diag.Diagnostics) {
o.MaxLinksCountPerPort = types.Int64Value(int64(in.MaxLinksPerPort))
o.MaxLinksCountPerSlot = types.Int64Value(int64(in.MaxLinksPerSlot))
o.MaxLinksCountPerSystemPerPort = types.Int64Value(int64(in.MaxPerSystemLinksPerPort))
o.MaxLinksCountPerSystemPerSlot = types.Int64Value(int64(in.MaxPerSystemLinksPerSlot))
}
Loading

0 comments on commit bec13e5

Please sign in to comment.