Skip to content

Commit

Permalink
Finalize Terraform differences between old and new versions of api #3347
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored Nov 16, 2023
2 parents 110e6a2 + 0a34a3b commit 49a367f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion submodules/msgraph-metadata
2 changes: 1 addition & 1 deletion submodules/rest-api-specs
Submodule rest-api-specs updated 534 files
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ type TerraformResourceDefinition struct {
// ReadMethod defines the Read Method associated with this Resource.
ReadMethod TerraformMethodDefinition `json:"readMethod"`

// Resource specifies the Resource within this API Version within the Service where
// the details for this Resource can be found.
Resource string `json:"resource"`

// ResourceIdName specifies the name of the Resource ID type used for this Resource.
ResourceIdName string `json:"resourceIdName"`

// SchemaModelName specifies the name of the Schema model for this Terraform Resource
SchemaModelName string `json:"schemaModelName"`

// UpdateMethod defines the Update Method associated with this Resource.
UpdateMethod *TerraformMethodDefinition `json:"updateMethod,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TerraformResourceTestConfig struct {

// OtherTests is a map of key (TestName) to value (a slice of Test Configurations) which
// should be output as Acceptance Tests.
OtherTests *map[string][]string `json:"otherTests,omitempty"`
OtherTests map[string][]string `json:"otherTests"`

// RequiresImport specifies the Terraform Configuration used for the RequiresImport test
// This test typically provisions the Basic test and then tries to provision the exact
Expand Down
8 changes: 5 additions & 3 deletions tools/data-api/internal/repositories/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ func (s *ServicesRepositoryImpl) ProcessTerraformDefinitions(serviceName string)
}

if tests.OtherTests == nil {
tests.OtherTests = pointer.To(make(map[string][]string))
tests.OtherTests = make(map[string][]string)
}
otherTests := *tests.OtherTests
otherTests := tests.OtherTests

if otherTests[testName] == nil {
otherTests[testName] = make([]string, 0)
Expand All @@ -586,7 +586,7 @@ func (s *ServicesRepositoryImpl) ProcessTerraformDefinitions(serviceName string)

otherTest = append(otherTest, otherTestConfig)
otherTests[testName] = otherTest
tests.OtherTests = &otherTests
tests.OtherTests = otherTests
}

resource.Tests = tests
Expand Down Expand Up @@ -614,7 +614,9 @@ func parseTerraformDefinitionResourceFromFilePath(resourcePath string, file os.D
definition.GenerateSchema = resourceDefinition.GenerateSchema
definition.ApiVersion = resourceDefinition.ApiVersion
definition.Generate = resourceDefinition.Generate
definition.Resource = resourceDefinition.Resource
definition.ResourceIdName = resourceDefinition.ResourceIdName
definition.SchemaModelName = resourceDefinition.SchemaModelName
definition.Label = resourceDefinition.Label

definition.CreateMethod = MethodDefinition{
Expand Down
2 changes: 1 addition & 1 deletion tools/data-api/internal/repositories/terraform_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,6 @@ type TerraformResourceTestsDefinition struct {
RequiresImportConfiguration string
CompleteConfiguration *string
Generate bool
OtherTests *map[string][]string
OtherTests map[string][]string
TemplateConfiguration *string
}
10 changes: 5 additions & 5 deletions tools/data-api/models/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ type FieldMappingDefinition struct {
Type MappingDefinitionType `json:"type"`

// DirectAssignment specifies the mapping information when Type is set to DirectAssignment.
DirectAssignment *FieldMappingDirectAssignmentDefinition `json:"directAssignment,omitempty"`
DirectAssignment *FieldMappingDirectAssignmentDefinition `json:"directAssignment"`

// ModelToModel specifies the mapping information when Type is set to ModelToModel.
ModelToModel *FieldMappingModelToModelDefinition `json:"modelToModel,omitempty"`
ModelToModel *FieldMappingModelToModelDefinition `json:"modelToModel"`

// Manual contains additional metadata when Type is set to Manual.
Manual *FieldManualMappingDefinition `json:"manual,omitempty"`
Expand Down Expand Up @@ -342,7 +342,7 @@ type TerraformSchemaFieldDefinition struct {
Documentation TerraformSchemaDocumentationDefinition `json:"documentation"`

// Validation specifies the validation criteria for this field, for example a set of fixed values
Validation *TerraformSchemaValidationDefinition `json:"validation,omitempty"`
Validation *TerraformSchemaValidationDefinition `json:"validation"`
}

type ResourceDocumentationDefinition struct {
Expand Down Expand Up @@ -435,7 +435,7 @@ const (
)

type TerraformSchemaFieldObjectDefinition struct {
NestedObject *TerraformSchemaFieldObjectDefinition `json:"nestedObject,omitempty"`
NestedObject *TerraformSchemaFieldObjectDefinition `json:"nestedObject"`

// ReferenceName is the name of the Reference associated with this ObjectDefinition.
ReferenceName *string `json:"referenceName"`
Expand Down Expand Up @@ -477,7 +477,7 @@ type TerraformResourceTestsDefinition struct {

// OtherTests is a map of key (TestName) to value (a slice of Test Configurations) which
// should be output as Acceptance Tests.
OtherTests *map[string][]string `json:"otherTests"`
OtherTests map[string][]string `json:"otherTests"`

// TemplateConfiguration is an optional Terraform Configuration which should be used
// as the Template for each of the Tests defined above, which should include any parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func writeTestsHclToFile(directory, resourceName string, tests dataApiModels.Ter
}

if tests.OtherTests != nil {
for otherTestName, v := range *tests.OtherTests {
for otherTestName, v := range tests.OtherTests {
for i, test := range v {
otherTestFileName := path.Join(directory, fmt.Sprintf("%s-Resource-Other-%s-%d-Test.hcl", resourceName, otherTestName, i))
if err := writeStringToFile(otherTestFileName, test); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ type TerraformResourceDefinition struct {
// ReadMethod defines the Read Method associated with this Resource.
ReadMethod TerraformMethodDefinition `json:"readMethod"`

// Resource specifies the Resource within this API Version within the Service where
// the details for this Resource can be found.
Resource string `json:"resource"`

// ResourceIdName specifies the name of the Resource ID type used for this Resource.
ResourceIdName string `json:"resourceIdName"`

// SchemaModelName specifies the name of the Schema model for this Terraform Resource
SchemaModelName string `json:"schemaModelName"`

// UpdateMethod defines the Update Method associated with this Resource.
UpdateMethod *TerraformMethodDefinition `json:"updateMethod,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TerraformResourceTestConfig struct {

// OtherTests is a map of key (TestName) to value (a slice of Test Configurations) which
// should be output as Acceptance Tests.
OtherTests *map[string][]string `json:"otherTests,omitempty"`
OtherTests map[string][]string `json:"otherTests"`

// RequiresImport specifies the Terraform Configuration used for the RequiresImport test
// This test typically provisions the Basic test and then tries to provision the exact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func buildTerraformResourceDefinition(resourceLabel string, input resourcemanager.TerraformResourceDetails) (*dataApiModels.TerraformResourceDefinition, error) {
// TODO: ExampleUsage should probably go out into a file - perhaps `Resource-ExampleUsage.hcl`?
output := dataApiModels.TerraformResourceDefinition{
ApiVersion: input.ApiVersion, // NOTE: this needs to be populated elsewhere
ApiVersion: input.ApiVersion,
Category: input.Documentation.Category,
CreateMethod: dataApiModels.TerraformMethodDefinition{
Generate: input.CreateMethod.Generate,
Expand All @@ -33,8 +33,10 @@ func buildTerraformResourceDefinition(resourceLabel string, input resourcemanage
Name: input.ReadMethod.MethodName,
TimeoutInMinutes: input.ReadMethod.TimeoutInMinutes,
},
ResourceIdName: input.ResourceIdName,
UpdateMethod: nil,
Resource: input.Resource,
ResourceIdName: input.ResourceIdName,
SchemaModelName: input.SchemaModelName,
UpdateMethod: nil,
}
if input.UpdateMethod != nil {
output.UpdateMethod = &dataApiModels.TerraformMethodDefinition{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package dataapigeneratorjson

import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
dataApiModels "github.com/hashicorp/pandora/tools/importer-rest-api-specs/components/dataapigeneratorjson/models"
"github.com/hashicorp/pandora/tools/sdk/resourcemanager"
)

func mapTerraformResourceTestDefinition(input resourcemanager.TerraformResourceTestsDefinition) dataApiModels.TerraformResourceTestConfig {
testConfig := dataApiModels.TerraformResourceTestConfig{
return dataApiModels.TerraformResourceTestConfig{
BasicConfig: input.BasicConfiguration,
CompleteConfig: input.CompleteConfiguration,
Generate: input.Generate,
OtherTests: input.OtherTests,
RequiresImport: input.RequiresImportConfiguration,
TemplateConfig: input.TemplateConfiguration,
}
if len(input.OtherTests) > 0 {
testConfig.OtherTests = pointer.To(input.OtherTests)
}
return testConfig
}

0 comments on commit 49a367f

Please sign in to comment.