TF Plan to ACI Payload Converter (DCNE-164)#1276
TF Plan to ACI Payload Converter (DCNE-164)#1276harismalk wants to merge 10 commits intoCiscoDevNet:masterfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1276 +/- ##
=======================================
Coverage 84.85% 84.85%
=======================================
Files 95 95
Lines 34992 34992
=======================================
Hits 29694 29694
Misses 3936 3936
Partials 1362 1362 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| To export a Terraform Plan as an ACI Payload: | ||
|
|
||
| 1. Navigate to conversion directory |
There was a problem hiding this comment.
It would be nice to run the code without changing the working directory to conversion
| } | ||
|
|
||
| func traverseOrCreatePath(dnMap map[string]*TreeNode, rootNode *TreeNode, resourceType, dn string) *TreeNode { | ||
| pathSegments := strings.Split(dn, "/") |
There was a problem hiding this comment.
This is likely not enough to handle complex dn patterns. There's a function in our provider that could be utilized here. Let me look for it.
cmd/conversion/main.go
Outdated
| } `json:"change"` | ||
| } | ||
|
|
||
| func runTerraform() (string, error) { |
There was a problem hiding this comment.
would it be possible to have this as a method on the Plan struct? where the method is called something like getPlanOutput
| planBin := "plan.bin" | ||
| planJSON := "plan.json" |
There was a problem hiding this comment.
should we pass these to the function as arguments?
| return planJSON, nil | ||
| } | ||
|
|
||
| func readPlan(jsonFile string) (Plan, error) { |
There was a problem hiding this comment.
is there a reason why you separated this from the runTerraform() ?
| var plan Plan | ||
| data, err := os.ReadFile(jsonFile) | ||
| if err != nil { | ||
| return plan, fmt.Errorf("failed to read input file: %w", err) | ||
| } | ||
|
|
||
| if err := json.Unmarshal(data, &plan); err != nil { |
There was a problem hiding this comment.
| var plan Plan | |
| data, err := os.ReadFile(jsonFile) | |
| if err != nil { | |
| return plan, fmt.Errorf("failed to read input file: %w", err) | |
| } | |
| if err := json.Unmarshal(data, &plan); err != nil { | |
| data, err := os.ReadFile(jsonFile) | |
| if err != nil { | |
| return plan, fmt.Errorf("failed to read input file: %w", err) | |
| } | |
| var plan Plan | |
| if err := json.Unmarshal(data, &plan); err != nil { |
| payload := createFunc(values, status) | ||
| return payload | ||
| } | ||
| return nil |
There was a problem hiding this comment.
Should we log something or provide some alternative action when the resourceType does not exist?
| } | ||
|
|
||
| func generateUniqueKeyForNonDnNode(resourceType string, attributes map[string]interface{}) string { | ||
| return fmt.Sprintf("%s-%v", resourceType, attributes["name"]) |
There was a problem hiding this comment.
what if attributes does not contain name?
|
|
||
| childKey := childDn | ||
| if childDn == "" { | ||
| childKey = generateUniqueKeyForNonDnNode(childClassName, childAttributes) |
There was a problem hiding this comment.
what is a non dn node? a rn without identifier?
|
|
||
| classNames := parseClassNames(pathSegments, resourceType) | ||
|
|
||
| for i := 1; i < len(pathSegments); i++ { |
There was a problem hiding this comment.
why not start loop with 0 then classnames can just be indexed with i?
| func GetDnToAciClassMap(childClass string, parentPrefix string) string { | ||
| rnMapping := make(map[string]map[string]string) | ||
|
|
||
| resp, err := http.Get("https://pubhub.devnetcloud.com/media/model-doc-latest/docs/doc/jsonmeta/aci-meta.json") |
There was a problem hiding this comment.
So every time this function is called we are retrieving the full meta?
Should we do this one time and cache it in memory or store it as static file in the repo?
As static file we might want because what happens when the meta from devnet deviates from the meta information we are using in the generator? Other option is to create a template in the generator that construct the information you need here.
| if pathSegments[i] == "uni" { | ||
| break | ||
| } | ||
| className := dict.GetDnToAciClassMap(classNames[len(classNames)-1], prefix) |
There was a problem hiding this comment.
see comment in the function itself
Fixes #586