Skip to content

Commit

Permalink
Merge branch 'investigation/nested-objects-readonly-props-diffing' of…
Browse files Browse the repository at this point in the history
… github.com:dikhan/terraform-provider-openapi into investigation/nested-objects-readonly-props-diffing
  • Loading branch information
dikhan committed Sep 2, 2019
2 parents cb28dc2 + a82a318 commit 8be8c38
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions openapi/openapi_spec_resource_schema_definition_property.go
Expand Up @@ -2,6 +2,7 @@ package openapi

import (
"fmt"

"github.com/dikhan/terraform-provider-openapi/openapi/terraformutils"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -65,7 +66,7 @@ func (s *specSchemaDefinitionProperty) getTerraformCompliantPropertyName() strin
// as TypeList with MaxItems limited to 1. This will solve the current limitation in Terraform SDK 0.12 where blocks can only be
// translated to lists and sets, maps can not be used to represent complex objects at the moment as it will result into undefined behavior.
// TODO: unit test this method
func (s *specSchemaDefinitionProperty) shouldEnableLegacyComplexObjectBlockConfiguration() bool {
func (s *specSchemaDefinitionProperty) isLegacyComplexObjectExtensionEnabled() bool {
if !s.isObjectProperty() {
return false
}
Expand Down Expand Up @@ -204,12 +205,14 @@ func (s *specSchemaDefinitionProperty) terraformObjectSchema() (*schema.Resource
func (s *specSchemaDefinitionProperty) shouldUseLegacyTerraformSDKBlockApproachForComplexObjects() (bool, error) {
isPropertyWithNestedObjects, err := s.isPropertyWithNestedObjects()
if err != nil {
return isPropertyWithNestedObjects, err
return false, err
}
// is of type object and in turn contains at lesat one nested property that is an object.
if isPropertyWithNestedObjects {
return isPropertyWithNestedObjects, nil
return true, nil
}
return s.shouldEnableLegacyComplexObjectBlockConfiguration(), nil
// or is of type object and also has the EnableLegacyComplexObjectBlockConfiguration set to true
return s.isLegacyComplexObjectExtensionEnabled(), nil
}

// terraformSchema returns the terraform schema for a the given specSchemaDefinitionProperty
Expand All @@ -226,7 +229,7 @@ func (s *specSchemaDefinitionProperty) terraformSchema() (*schema.Schema, error)
switch s.Type {
case typeObject:
// TODO: add coverage for this logic if not already done
shouldUseLegacyTerraformSDKApproachForBlocks, err := s.shouldUseLegacyTerraformSDKBlockApproachForComplexObjects()
shouldUseLegacyTerraformSDKApproachForBlocks, err := s.shouldUseLegacyTerraformSDKBlockApproachForComplexObjects() // handle the error
if shouldUseLegacyTerraformSDKApproachForBlocks {
terraformSchema.Type = schema.TypeList
terraformSchema.MaxItems = 1
Expand Down

0 comments on commit 8be8c38

Please sign in to comment.