terraform/internal/command/jsonprovider/schema.go
Daniel Schmidt 871451122f actions: move schema to single action type and remove linked resources
we want to leave the door open to evolve the design in the future based on feedback
2025-09-15 17:09:22 +02:00

89 lines
2.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package jsonprovider
import (
"github.com/hashicorp/terraform/internal/providers"
)
type Schema struct {
Version uint64 `json:"version"`
Block *Block `json:"block,omitempty"`
}
// marshalSchema is a convenience wrapper around mashalBlock. Schema version
// should be set by the caller.
func marshalSchema(schema providers.Schema) *Schema {
if schema.Body == nil {
return &Schema{}
}
var ret Schema
ret.Block = marshalBlock(schema.Body)
ret.Version = uint64(schema.Version)
return &ret
}
func marshalSchemas(schemas map[string]providers.Schema) map[string]*Schema {
if schemas == nil {
return map[string]*Schema{}
}
ret := make(map[string]*Schema, len(schemas))
for k, v := range schemas {
ret[k] = marshalSchema(v)
}
return ret
}
type IdentitySchema struct {
Version uint64 `json:"version"`
Attributes map[string]*IdentityAttribute `json:"attributes,omitempty"`
}
func marshalIdentitySchema(schema providers.Schema) *IdentitySchema {
var ret IdentitySchema
ret.Version = uint64(schema.IdentityVersion)
ret.Attributes = make(map[string]*IdentityAttribute, len(schema.Identity.Attributes))
for k, v := range schema.Identity.Attributes {
ret.Attributes[k] = marshalIdentityAttribute(v)
}
return &ret
}
func marshalIdentitySchemas(schemas map[string]providers.Schema) map[string]*IdentitySchema {
if schemas == nil {
return map[string]*IdentitySchema{}
}
ret := make(map[string]*IdentitySchema, len(schemas))
for k, v := range schemas {
if v.Identity != nil {
ret[k] = marshalIdentitySchema(v)
}
}
return ret
}
type ActionSchema struct {
ConfigSchema *Block `json:"block,omitempty"`
}
func marshalActionSchemas(schemas map[string]providers.ActionSchema) map[string]*ActionSchema {
ret := make(map[string]*ActionSchema, len(schemas))
for name, schema := range schemas {
ret[name] = marshalActionSchema(schema)
}
return ret
}
func marshalActionSchema(schema providers.ActionSchema) *ActionSchema {
return &ActionSchema{
ConfigSchema: marshalBlock(schema.ConfigSchema),
}
}