-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TF Plan to ACI Payload Converter (DCNE-164) #1276
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you briefly
|
||
To export a Terraform Plan as an ACI Payload: | ||
|
||
1. Navigate to conversion directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if attributes does not contain name?
|
||
childKey := childDn | ||
if childDn == "" { | ||
childKey = generateUniqueKeyForNonDnNode(childClassName, childAttributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment in the function itself
Fixes #586