Documentation ¶
Index ¶
- Constants
- func GenerateResourceSpec(r ResourceConfig) (specresource.Resource, error)
- func MapTerraformAttributeToKubernetes(terraformAttributeName string) string
- func MapTerraformAttributeToModel(terraformAttributeName string) string
- func WriteFormattedSourceFile(wd, path string, contents string) error
- type AfterHook
- type AttributeGenerator
- type AttributesGenerator
- type BeforeHook
- type CRUDAutoOptions
- type DataSourceConfig
- type GenerateConfig
- type GeneratorConfig
- type Hooks
- type ModelFieldGenerator
- type ModelFieldsGenerator
- type ResourceConfig
- type ResourceGenerator
- func (g *ResourceGenerator) GenerateAutoCRUDCode() string
- func (g *ResourceGenerator) GenerateAutoCRUDHooksCode() string
- func (g *ResourceGenerator) GenerateCRUDStubCode() string
- func (g *ResourceGenerator) GenerateModelCode() string
- func (g *ResourceGenerator) GenerateResourceCode() string
- func (g *ResourceGenerator) GenerateSchemaFunctionCode() string
- type ResourcesListGenerator
- type SchemaGenerator
- type TerraformPluginGenOpenAPIConfig
- type Timeouts
Constants ¶
const ( BoolAttributeType = "BoolAttribute" StringAttributeType = "StringAttribute" NumberAttributeType = "NumberAttribute" Int64AttributeType = "Int64Attribute" MapAttributeType = "MapAttribute" ListAttributeType = "ListAttribute" ObjectAttributeType = "ObjectAttribute" SingleNestedAttributeType = "SingleNestedAttribute" ListNestedAttributeType = "ListNestedAttribute" )
const ( BoolElementType = "BoolType" StringElementType = "StringType" NumberElementType = "NumberType" Int64ElementType = "Int64Type" )
const ( BoolModelType = "Bool" StringModelType = "String" NumberModelType = "Number" Int64ModelType = "Int64" )
const ( BoolPlanModifierType = "Bool" StringPlanModifierType = "String" NumberPlanModifierType = "Number" Int64PlanModifierType = "Int64" )
const ( BoolPlanModifierPackage = "boolplanmodifier" StringPlanModifierPackage = "stringplanmodifier" NumberPlanModifierPackage = "numberplanmodifier" Int64PlanModifierPackage = "int64planmodifier" )
Variables ¶
This section is empty.
Functions ¶
func GenerateResourceSpec ¶
func GenerateResourceSpec(r ResourceConfig) (specresource.Resource, error)
GenerateResourceSpec uses the supplied configuration to generate the framework IR JSON from an OpenAPI spec then marshalls the IR into a spec.Resource
func MapTerraformAttributeToKubernetes ¶
MapTerraformAttributeToKubernetes maps a string containing snake_case into camelCase
func WriteFormattedSourceFile ¶
WriteFormattedSourceFile runs Go code through format before writing to a file
Types ¶
type AttributeGenerator ¶
type AttributeGenerator struct { Name string AttributeType string ElementType string PlanModifierType string PlanModifierPackage string Required bool Description string Computed bool Sensitive bool Immutable bool NestedAttributes AttributesGenerator }
func (AttributeGenerator) String ¶
func (g AttributeGenerator) String() string
type AttributesGenerator ¶
type AttributesGenerator []AttributeGenerator
func GenerateAttributes ¶
func GenerateAttributes(attrs specresource.Attributes, ignored, computed, required, sensitive, immutable []string, path string) AttributesGenerator
FIXME this function has too many parameters now, should maybe be part of ResourceGenerator.
func (AttributesGenerator) String ¶
func (g AttributesGenerator) String() string
type BeforeHook ¶
type CRUDAutoOptions ¶
type CRUDAutoOptions struct { WaitForDeletion bool `hcl:"wait_for_deletion,optional"` Hooks *Hooks `hcl:"hooks,block"` }
CRUDAutoOptions configures options for the autocrud template
type DataSourceConfig ¶
type DataSourceConfig struct { }
DataSourceConfig configures code generation for a Terraform data source
type GenerateConfig ¶
type GenerateConfig struct { Schema bool `hcl:"schema,optional"` Overrides bool `hcl:"overrides,optional"` Model bool `hcl:"model,optional"` CRUDAuto bool `hcl:"autocrud,optional"` CRUDAutoOptions *CRUDAutoOptions `hcl:"autocrud_options,block"` CRUDStubs bool `hcl:"crud_stubs,optional"` Timeouts *Timeouts `hcl:"timeouts,block"` }
GenerateConfig configures the options for what we should generate
type GeneratorConfig ¶
type GeneratorConfig struct { Resources []ResourceConfig `hcl:"resource,block"` DataSource []DataSourceConfig `hcl:"data,block"` }
GeneratorConfig is the top level code generator configuration
func ParseHCLConfig ¶
func ParseHCLConfig(filename string) (GeneratorConfig, error)
ParseHCLConfig parses the .hcl configuraiton file and produces a GeneratorConfig
type Hooks ¶
type Hooks struct { BeforeHook *BeforeHook `hcl:"before,block"` AfterHook *AfterHook `hcl:"after,block"` }
Hooks configures which hooks to include for autocrud template if necessary
type ModelFieldGenerator ¶
type ModelFieldGenerator struct { // ModelFieldName is the name the attribute has in the model struct, e.g ApiVersion FieldName string Type string ElementType string // AttributeName is the name of the attribute in the terraform schema api_version AttributeName string AttributeType string // ManifestFieldName is the name the attribute has in the Kubernetes manifest, e.g apiVersion ManifestFieldName string NestedFields ModelFieldsGenerator }
func (ModelFieldGenerator) String ¶
func (g ModelFieldGenerator) String() string
type ModelFieldsGenerator ¶
type ModelFieldsGenerator []ModelFieldGenerator
func GenerateModelFields ¶
func GenerateModelFields(attrs specresource.Attributes, ignored []string, path string) ModelFieldsGenerator
func (ModelFieldsGenerator) String ¶
func (g ModelFieldsGenerator) String() string
type ResourceConfig ¶
type ResourceConfig struct { // Name is the terraform name of this resource Name string `hcl:"name,label"` // Package is the name of the Go package for the source files for this resource Package string `hcl:"package"` // OutputFilenamePrefix is a prefix to be added to all source files generated // for this resource OutputFilenamePrefix string `hcl:"output_filename_prefix"` // APIVersion is the Kubernetes API version of the resource APIVersion string `hcl:"api_version"` // Kind is the Kubernetes kind of the resource Kind string `hcl:"kind"` // Description is a Markdown description for the resource Description string `hcl:"description"` // IgnoredAttributes is a list of attribute paths to omit from the resource IgnoredAttributes []string `hcl:"ignored_attributes,optional"` // RequiredAttributes is a list of attribute paths to mark as required in the schema RequiredAttributes []string `hcl:"required_attributes,optional"` // ComputedAttributes is a list of attribute paths to mark as computed in the schema ComputedAttributes []string `hcl:"computed_attributes,optional"` // SensitiveAttributes is a list of attribute paths to mark as sensitive in the schema SensitiveAttributes []string `hcl:"sensitive_attributes,optional"` // ImmutableAttributes is a list of attribute paths to mark as requiring a forced // replacement if changed in the schema ImmutableAttributes []string `hcl:"immutable_attributes,optional"` // Generate controls generator specific options Generate GenerateConfig `hcl:"generate,block"` // OpenAPIConfig configures options for the OpenAPI to Framework IR generator OpenAPIConfig TerraformPluginGenOpenAPIConfig `hcl:"openapi,block"` // Disabled tells the generator to skip this configuration Disabled bool `hcl:"disabled,optional"` }
ResourceConfig configures code generation for a Terraform resource
type ResourceGenerator ¶
type ResourceGenerator struct { GeneratedTimestamp time.Time ResourceConfig ResourceConfig Schema SchemaGenerator ModelFields ModelFieldsGenerator }
func NewResourceGenerator ¶
func NewResourceGenerator(cfg ResourceConfig, spec specresource.Resource) ResourceGenerator
func (*ResourceGenerator) GenerateAutoCRUDCode ¶
func (g *ResourceGenerator) GenerateAutoCRUDCode() string
func (*ResourceGenerator) GenerateAutoCRUDHooksCode ¶
func (g *ResourceGenerator) GenerateAutoCRUDHooksCode() string
func (*ResourceGenerator) GenerateCRUDStubCode ¶
func (g *ResourceGenerator) GenerateCRUDStubCode() string
func (*ResourceGenerator) GenerateModelCode ¶
func (g *ResourceGenerator) GenerateModelCode() string
func (*ResourceGenerator) GenerateResourceCode ¶
func (g *ResourceGenerator) GenerateResourceCode() string
func (*ResourceGenerator) GenerateSchemaFunctionCode ¶
func (g *ResourceGenerator) GenerateSchemaFunctionCode() string
type ResourcesListGenerator ¶
type ResourcesListGenerator struct { GeneratedTimestamp time.Time Resources []ResourceConfig Packages []string }
func (ResourcesListGenerator) String ¶
func (p ResourcesListGenerator) String() string
type SchemaGenerator ¶
type SchemaGenerator struct { Name string Description string Attributes AttributesGenerator Imports []string }
func (SchemaGenerator) String ¶
func (g SchemaGenerator) String() string
type TerraformPluginGenOpenAPIConfig ¶
type TerraformPluginGenOpenAPIConfig struct { // Filename is the filename for the OpenAPI JSON specification Filename string `hcl:"filename"` // CreatePath is the POST path for the resource in the OpenAPI spec, e.g. /api/v1/namespaces/{namespace}/configmaps CreatePath string `hcl:"create_path"` // ReadPath is the GET path for the resource in the OpenAPI spec, e.g. /api/v1/namespaces/{namespace}/configmaps/{name} ReadPath string `hcl:"read_path"` }
TerraformPluginGenOpenAPIConfig supplies configuration to tfplugingen-openapi See: https://github.com/hashicorp/terraform-plugin-codegen-openapi