-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from volcengine/feat/ecs
Feat/ecs
- Loading branch information
Showing
11 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package common | ||
|
||
import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
func resourceSpecial(resource *schema.Resource, data map[string]interface{}, convert map[string]ResponseConvert) { | ||
if len(resource.Schema) > 0 { | ||
mappings := map[string]string{} | ||
//构造一下反向映射 | ||
if len(convert) > 0 { | ||
for k, v := range convert { | ||
if v.TargetField != "" { | ||
mappings[v.TargetField] = k | ||
} | ||
} | ||
} | ||
|
||
for k, v := range resource.Schema { | ||
var ( | ||
key string | ||
isMapping bool | ||
ok bool | ||
val interface{} | ||
next *schema.Resource | ||
) | ||
if key, ok = mappings[k]; ok { | ||
isMapping = true | ||
} else { | ||
key = DownLineToHump(k) | ||
} | ||
switch v.Type { | ||
case schema.TypeSet: | ||
if val, ok = data[key]; !ok { | ||
setSchemaSetSpecial(key, k, data, isMapping) | ||
} else { | ||
if val == nil { | ||
setSchemaSetSpecial(key, k, data, isMapping) | ||
} else { | ||
break | ||
} | ||
} | ||
//不存在转换映射的情况下 判断一下schemaKey是否存在 不存在则set | ||
if !isMapping { | ||
if val, ok = data[k]; !ok { | ||
setSchemaSetSpecial(key, k, data, isMapping) | ||
} else { | ||
if val == nil { | ||
setSchemaSetSpecial(key, k, data, isMapping) | ||
} | ||
} | ||
} | ||
break | ||
default: | ||
break | ||
} | ||
if v.Elem != nil { | ||
if next, ok = v.Elem.(*schema.Resource); ok { | ||
if val, ok = data[key]; ok { | ||
if nextData, ok2 := val.(map[string]interface{}); ok2 { | ||
resourceSpecial(next, nextData, convert) | ||
data[key] = nextData | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
func setSchemaSetSpecial(targetKey string, sourceKey string, data map[string]interface{}, isMapping bool) { | ||
data[targetKey] = new(schema.Set) | ||
if !isMapping { | ||
//不存在转换映射的情况下 自动补齐一个下划线类型的key上去 | ||
data[sourceKey] = new(schema.Set) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters