Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

harismalk
Copy link
Collaborator

@harismalk harismalk commented Aug 22, 2024

Fixes #586

@lhercot lhercot requested review from samiib and sajagana August 22, 2024 15:53
@codecov-commenter
Copy link

codecov-commenter commented Aug 25, 2024

Codecov Report

Attention: Patch coverage is 76.53631% with 84 lines in your changes missing coverage. Please review.

Project coverage is 84.85%. Comparing base (176a6cb) to head (1c80161).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...provider/resource_aci_access_interface_override.go 71.42% 2 Missing ⚠️
...nternal/provider/resource_aci_custom_qos_policy.go 71.42% 2 Missing ⚠️
...rovider/resource_aci_data_plane_policing_policy.go 71.42% 2 Missing ⚠️
internal/provider/resource_aci_endpoint_tag_ip.go 71.42% 2 Missing ⚠️
internal/provider/resource_aci_endpoint_tag_mac.go 71.42% 2 Missing ⚠️
...ovider/resource_aci_epg_useg_ad_group_attribute.go 71.42% 2 Missing ⚠️
.../provider/resource_aci_epg_useg_block_statement.go 71.42% 2 Missing ⚠️
...al/provider/resource_aci_epg_useg_dns_attribute.go 71.42% 2 Missing ⚠️
...nal/provider/resource_aci_epg_useg_ip_attribute.go 71.42% 2 Missing ⚠️
...al/provider/resource_aci_epg_useg_mac_attribute.go 71.42% 2 Missing ⚠️
... and 33 more
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.
📢 Have feedback on the report? Share it here.

@lhercot lhercot requested a review from akinross August 26, 2024 15:25
Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you briefly

README.md Outdated Show resolved Hide resolved

To export a Terraform Plan as an ACI Payload:

1. Navigate to conversion directory
Copy link
Collaborator

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

cmd/conversion/main.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
}

func traverseOrCreatePath(dnMap map[string]*TreeNode, rootNode *TreeNode, resourceType, dn string) *TreeNode {
pathSegments := strings.Split(dn, "/")
Copy link
Collaborator

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.

@harismalk harismalk changed the title Revised converter and documentation TF Plan to ACI Payload Converter Aug 29, 2024
} `json:"change"`
}

func runTerraform() (string, error) {
Copy link
Collaborator

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

Comment on lines +39 to +40
planBin := "plan.bin"
planJSON := "plan.json"
Copy link
Collaborator

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) {
Copy link
Collaborator

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() ?

Comment on lines +62 to +68
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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"])
Copy link
Collaborator

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)
Copy link
Collaborator

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++ {
Copy link
Collaborator

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?

Comment on lines +11 to +14
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")
Copy link
Collaborator

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)
Copy link
Collaborator

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

@akinross akinross changed the title TF Plan to ACI Payload Converter TF Plan to ACI Payload Converter (DCNE-164) Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NDI PCV integration with terraform (DCNE-164)
4 participants