Skip to content

Commit

Permalink
Merge pull request #775 from Juniper/refactor-freeform-models-to-free…
Browse files Browse the repository at this point in the history
…form-package

Move `freeform*` files from `apstra/blueprint` to `apstra/freeform`
  • Loading branch information
chrismarget-j authored Aug 9, 2024
2 parents 7714c95 + 909a086 commit cb1dae3
Show file tree
Hide file tree
Showing 27 changed files with 112 additions and 110 deletions.
17 changes: 4 additions & 13 deletions apstra/blueprint/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"golang.org/x/exp/constraints"
)

type Blueprint struct {
Expand Down Expand Up @@ -748,11 +747,11 @@ func (o *Blueprint) LoadFabricSettings(ctx context.Context, settings *apstra.Fab
}
}

o.DefaultIpLinksToGenericMtu = int64AttrValueFromPtr(settings.ExternalRouterMtu)
o.DefaultSviL3Mtu = int64AttrValueFromPtr(settings.DefaultSviL3Mtu)
o.EsiMacMsb = int64AttrValueFromPtr(settings.EsiMacMsb)
o.DefaultIpLinksToGenericMtu = utils.Int64AttrValueFromPtr(settings.ExternalRouterMtu)
o.DefaultSviL3Mtu = utils.Int64AttrValueFromPtr(settings.DefaultSviL3Mtu)
o.EsiMacMsb = utils.Int64AttrValueFromPtr(settings.EsiMacMsb)
o.EvpnType5Routes = boolAttrValueFromFeatureswitchEnumPtr(settings.EvpnGenerateType5HostRoutes)
o.FabricMtu = int64AttrValueFromPtr(settings.FabricL3Mtu)
o.FabricMtu = utils.Int64AttrValueFromPtr(settings.FabricL3Mtu)
o.Ipv6Applications = boolAttrValueFromBoolPtr(settings.Ipv6Enabled)
o.JunosEvpnMaxNexthopAndInterfaceNumber = boolAttrValueFromFeatureswitchEnumPtr(settings.JunosEvpnMaxNexthopAndInterfaceNumber)
o.JunosEvpnRoutingInstanceModeMacVrf = boolAttrValueFromFeatureswitchEnumPtr(settings.JunosEvpnRoutingInstanceVlanAware)
Expand Down Expand Up @@ -968,11 +967,3 @@ func boolAttrValueFromFeatureswitchEnumPtr(fs *apstra.FeatureSwitchEnum) types.B

return types.BoolValue(fs.Value == apstra.FeatureSwitchEnumEnabled.Value)
}

func int64AttrValueFromPtr[A constraints.Integer](a *A) types.Int64 {
if a == nil {
return types.Int64Null()
}

return types.Int64Value(int64(*a))
}
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_allocation_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformAllocGroup) Schema(_ context.Context, _ datasource.Sc
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a Freeform Allocation Group.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformAllocGroup{}.DataSourceAttributes(),
Attributes: freeform.FreeformAllocGroup{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformAllocGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformAllocGroup
var config freeform.FreeformAllocGroup
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformConfigTemplate) Schema(_ context.Context, _ datasourc
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Config Template.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformConfigTemplate{}.DataSourceAttributes(),
Attributes: freeform.FreeformConfigTemplate{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformConfigTemplate) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformConfigTemplate
var config freeform.FreeformConfigTemplate
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformLink) Schema(_ context.Context, _ datasource.SchemaRe
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Link.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformLink{}.DataSourceAttributes(),
Attributes: freeform.FreeformLink{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformLink) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformLink
var config freeform.FreeformLink
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_property_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformPropertySet) Schema(_ context.Context, _ datasource.S
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Property Set.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformPropertySet{}.DataSourceAttributes(),
Attributes: freeform.FreeformPropertySet{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformPropertySet) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformPropertySet
var config freeform.FreeformPropertySet
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformResource) Schema(_ context.Context, _ datasource.Sche
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Resource.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformResource{}.DataSourceAttributes(),
Attributes: freeform.FreeformResource{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformResource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformResource
var config freeform.FreeformResource
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_resource_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformResourceGenerator) Schema(_ context.Context, _ dataso
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Resource Generator.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformResourceGenerator{}.DataSourceAttributes(),
Attributes: freeform.FreeformResourceGenerator{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformResourceGenerator) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformResourceGenerator
var config freeform.FreeformResourceGenerator
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformResourceGroup) Schema(_ context.Context, _ datasource
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform Resource Group.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformResourceGroup{}.DataSourceAttributes(),
Attributes: freeform.FreeformResourceGroup{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformResourceGroup) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformResourceGroup
var config freeform.FreeformResourceGroup
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
6 changes: 3 additions & 3 deletions apstra/data_source_freeform_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/Juniper/terraform-provider-apstra/apstra/freeform"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -34,12 +34,12 @@ func (o *dataSourceFreeformSystem) Schema(_ context.Context, _ datasource.Schema
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryFreeform + "This data source provides details of a specific Freeform System.\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.FreeformSystem{}.DataSourceAttributes(),
Attributes: freeform.FreeformSystem{}.DataSourceAttributes(),
}
}

func (o *dataSourceFreeformSystem) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.FreeformSystem
var config freeform.FreeformSystem
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand All @@ -20,7 +20,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type freeformEndpoint struct {
type FreeformEndpoint struct {
InterfaceName types.String `tfsdk:"interface_name"`
InterfaceId types.String `tfsdk:"interface_id"`
TransformationId types.Int64 `tfsdk:"transformation_id"`
Expand All @@ -29,7 +29,7 @@ type freeformEndpoint struct {
Tags types.Set `tfsdk:"tags"`
}

func (o freeformEndpoint) attrTypes() map[string]attr.Type {
func (o FreeformEndpoint) attrTypes() map[string]attr.Type {
return map[string]attr.Type{
"interface_name": types.StringType,
"interface_id": types.StringType,
Expand All @@ -40,7 +40,7 @@ func (o freeformEndpoint) attrTypes() map[string]attr.Type {
}
}

func (o freeformEndpoint) DatasourceAttributes() map[string]dataSourceSchema.Attribute {
func (o FreeformEndpoint) DatasourceAttributes() map[string]dataSourceSchema.Attribute {
return map[string]dataSourceSchema.Attribute{
"interface_name": dataSourceSchema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -72,7 +72,7 @@ func (o freeformEndpoint) DatasourceAttributes() map[string]dataSourceSchema.Att
}
}

func (o freeformEndpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
func (o FreeformEndpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
return map[string]resourceSchema.Attribute{
"interface_name": resourceSchema.StringAttribute{
Required: true,
Expand Down Expand Up @@ -110,7 +110,7 @@ func (o freeformEndpoint) ResourceAttributes() map[string]resourceSchema.Attribu
}
}

func (o *freeformEndpoint) request(ctx context.Context, systemId string, diags *diag.Diagnostics) *apstra.FreeformEndpoint {
func (o *FreeformEndpoint) request(ctx context.Context, systemId string, diags *diag.Diagnostics) *apstra.FreeformEndpoint {
var ipNet4, ipNet6 *net.IPNet
if !o.Ipv4Address.IsNull() {
var ip4 net.IP
Expand Down Expand Up @@ -140,7 +140,7 @@ func (o *freeformEndpoint) request(ctx context.Context, systemId string, diags *
}
}

func (o *freeformEndpoint) loadApiData(ctx context.Context, in apstra.FreeformEndpoint, diags *diag.Diagnostics) {
func (o *FreeformEndpoint) loadApiData(ctx context.Context, in apstra.FreeformEndpoint, diags *diag.Diagnostics) {
if in.Interface.Id == nil {
diags.AddError(
fmt.Sprintf("api returned nil interface Id for system %s", in.SystemId),
Expand All @@ -164,15 +164,15 @@ func (o *freeformEndpoint) loadApiData(ctx context.Context, in apstra.FreeformEn
}

func newFreeformEndpointMap(ctx context.Context, in [2]apstra.FreeformEndpoint, diags *diag.Diagnostics) types.Map {
endpoints := make(map[string]freeformEndpoint, len(in))
endpoints := make(map[string]FreeformEndpoint, len(in))
for i := range in {
var endpoint freeformEndpoint
var endpoint FreeformEndpoint
endpoint.loadApiData(ctx, in[i], diags)
endpoints[in[i].SystemId.String()] = endpoint
}
if diags.HasError() {
return types.MapNull(types.ObjectType{AttrTypes: freeformEndpoint{}.attrTypes()})
return types.MapNull(types.ObjectType{AttrTypes: FreeformEndpoint{}.attrTypes()})
}

return utils.MapValueOrNull(ctx, types.ObjectType{AttrTypes: freeformEndpoint{}.attrTypes()}, endpoints, diags)
return utils.MapValueOrNull(ctx, types.ObjectType{AttrTypes: FreeformEndpoint{}.attrTypes()}, endpoints, diags)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down Expand Up @@ -82,7 +82,7 @@ func (o FreeformLink) DataSourceAttributes() map[string]dataSourceSchema.Attribu
MarkdownDescription: "Endpoints assigned to the Link",
Computed: true,
NestedObject: dataSourceSchema.NestedAttributeObject{
Attributes: freeformEndpoint{}.DatasourceAttributes(),
Attributes: FreeformEndpoint{}.DatasourceAttributes(),
},
},
"tags": dataSourceSchema.SetAttribute{
Expand Down Expand Up @@ -128,7 +128,7 @@ func (o FreeformLink) ResourceAttributes() map[string]resourceSchema.Attribute {
},
"endpoints": resourceSchema.MapNestedAttribute{
NestedObject: resourceSchema.NestedAttributeObject{
Attributes: freeformEndpoint{}.ResourceAttributes(),
Attributes: FreeformEndpoint{}.ResourceAttributes(),
},
PlanModifiers: []planmodifier.Map{mapplanmodifier.RequiresReplace()},
MarkdownDescription: "Endpoints of the Link",
Expand All @@ -154,7 +154,7 @@ func (o *FreeformLink) Request(ctx context.Context, diags *diag.Diagnostics) *ap
return nil
}

var endpoints map[string]freeformEndpoint
var endpoints map[string]FreeformEndpoint
diags.Append(o.Endpoints.ElementsAs(ctx, &endpoints, false)...)
if diags.HasError() {
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down Expand Up @@ -197,5 +197,5 @@ func (o *FreeformResourceGenerator) LoadApiData(_ context.Context, in *apstra.Fr
o.AllocatedFrom = types.StringPointerValue((*string)(in.AllocatedFrom))
}
o.ContainerId = types.StringValue(string(in.ContainerId))
o.SubnetPrefixLen = int64AttrValueFromPtr(in.SubnetPrefixLen)
o.SubnetPrefixLen = utils.Int64AttrValueFromPtr(in.SubnetPrefixLen)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package freeform

import (
"context"
Expand Down
Loading

0 comments on commit cb1dae3

Please sign in to comment.