github.com/terraform-linters/tflint-ruleset-azurerm@v0.26.0/rules/generator-utils/schema.go (about)

     1  package utils
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  )
     7  
     8  // Schema describes the provider schemas for all providers throughout the configuration tree.
     9  type Schema struct {
    10  	ProviderSchemas ProviderSchemas `json:"provider_schemas"`
    11  }
    12  
    13  // ProviderSchemas describes the provider schemas for all providers throughout the configuration tree.
    14  type ProviderSchemas struct {
    15  	Azurerm ProviderSchema `json:"registry.terraform.io/hashicorp/azurerm"`
    16  }
    17  
    18  // ProviderSchema describes the schemas for all resources.
    19  type ProviderSchema struct {
    20  	ResourceSchemas map[string]ResourceSchema `json:"resource_schemas"`
    21  }
    22  
    23  // ResourceSchema describes the schemas for all resources.
    24  type ResourceSchema struct {
    25  	Block BlockSchema `json:"block"`
    26  }
    27  
    28  // BlockSchema A block representation contains "attributes" and "block_types" (which represent nested blocks).
    29  type BlockSchema struct {
    30  	Attributes map[string]AttributeSchema `json:"attributes"`
    31  	BlockTypes map[string]ResourceSchema  `json:"block_types"`
    32  }
    33  
    34  // AttributeSchema contains Type and Sensitive
    35  type AttributeSchema struct {
    36  	Type      interface{} `json:"type"`
    37  	Sensitive bool        `json:"sensitive"`
    38  }
    39  
    40  // LoadProviderSchema loads provider schema file and deserialize into an object
    41  func LoadProviderSchema(path string) ProviderSchema {
    42  	src, err := ioutil.ReadFile(path)
    43  	if err != nil {
    44  		panic(err)
    45  	}
    46  
    47  	var schema Schema
    48  	if err := json.Unmarshal(src, &schema); err != nil {
    49  		panic(err)
    50  	}
    51  	return schema.ProviderSchemas.Azurerm
    52  }