Skip to content

Commit

Permalink
dataapiv2 - Various Fixes to the terraform side (#3291)
Browse files Browse the repository at this point in the history
* Populate ApiVersion

* fix resourceLabel

* Hardcode GenerateModel,GenerateIdValidationFunction,GenerateSchema to true similar to C# generation

* Set ModelToModelMappings

* Set ModelToModelMappings into the api

* Address review
  • Loading branch information
mbfrahry authored Nov 8, 2023
1 parent a267fa1 commit f1fb416
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/data-api/internal/endpoints/v1/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (api Api) terraform(w http.ResponseWriter, r *http.Request) {
func mapTerraformResources(input map[string]repositories.TerraformResourceDetails) map[string]models.TerraformResourceDetails {
output := make(map[string]models.TerraformResourceDetails, 0)

for name, resource := range input {
output[name] = models.TerraformResourceDetails{
for _, resource := range input {
output[resource.Label] = models.TerraformResourceDetails{
ApiVersion: resource.ApiVersion,
CreateMethod: models.MethodDefinition{
Generate: resource.CreateMethod.Generate,
Expand Down
2 changes: 2 additions & 0 deletions tools/data-api/internal/repositories/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func parseTerraformDefinitionResourceFromFilePath(resourcePath string, file os.D
definition.ApiVersion = resourceDefinition.ApiVersion
definition.Generate = resourceDefinition.Generate
definition.ResourceIdName = resourceDefinition.ResourceIdName
definition.Label = resourceDefinition.Label

definition.CreateMethod = MethodDefinition{
Generate: resourceDefinition.CreateMethod.Generate,
Expand Down Expand Up @@ -632,6 +633,7 @@ func parseTerraformDefinitionResourceMappingsFromFilePath(resourcePath string, f
SdkModelName: modelToModelMapping.SdkModelName,
})
}
mappings.ModelToModels = modelToModels
}

return mappings, nil
Expand Down
1 change: 1 addition & 0 deletions tools/data-api/internal/repositories/terraform_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TerraformResourceDetails struct {
GenerateModel bool
GenerateIdValidation bool
GenerateSchema bool
Label string
Mappings MappingDefinition
ReadMethod MethodDefinition
Resource string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func mapTerraformSchemaMappings(input resourcemanager.MappingDefinition) (*dataA
if len(*outputFieldMappings) > 0 {
output.FieldMappings = outputFieldMappings
}

modelToModelMappings = uniqueAndSortModelToModelMappings(modelToModelMappings)
if len(modelToModelMappings) > 0 {
output.ModelToModelMappings = &modelToModelMappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func FindCandidates(input services.Resource, resourceDefinitions map[string]defi
Generate: true,
GenerateSchema: true,
GenerateIdValidation: true,
GenerateModel: true,
ReadMethod: *getMethod,
Resource: apiResourceName,
ResourceIdName: resourceIdName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (pipelineTask) generateTerraformDetails(data *models.AzureApiDefinition, lo
continue
}

resourceDetails.ApiVersion = data.ApiVersion
resourceDetails.SchemaModels = *modelsForResource
resourceDetails.Mappings = *mappings
resourceDetails.Tests.Generate = true
Expand Down

0 comments on commit f1fb416

Please sign in to comment.