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

Import functionality #225

Merged
merged 5 commits into from
Aug 9, 2022
Merged

Import functionality #225

merged 5 commits into from
Aug 9, 2022

Conversation

skudriavtsev
Copy link
Collaborator

@skudriavtsev skudriavtsev commented Jul 25, 2022

No description provided.

@surskitt
Copy link

surskitt commented Aug 2, 2022

Is this a new PR for this functionality? Is it ready to be merged and released?

func newInternalResourceIdFromString(id string) *internalResourceId {
newUUID, err := uuid.Parse(id)
if err != nil {
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.

Shouldn't we add a log message here, or even panic?

How the user will know if the id is not parsed, and why it's not parsed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure.

return true
}

func generateAltId(internalId *internalResourceId, ref string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's AltId? What this function will generate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This AltId is an ID which is alternative to Terraform resource's ID. Sometimes we cannot use NIOS object's reference as a Terraform resource's ID because the reference may get changed.

if found {
stringVal, ok := rawValue.(string)
// TODO: do we need this after changing internalId's implementation?
if ok && isValidInternalId(stringVal) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make the check for uuid validity inline instead of creating a new isValidInternalId function, which only purpose is to be used in this if statement.

Suggested change
if ok && isValidInternalId(stringVal) {
if _, err := uuid.Parse(stringVal); ok && err == nil {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As of now, this is just for one place in the code, but there is no guarantee that this will not be changed in the future for some reason. That is why I decided to abstract from particular format here. Let it be defined in the code which determines alternative/internal ID's logic.

infoblox/provider.go Outdated Show resolved Hide resolved
internalId.String(), altIdSeparator, ref)
}

// valid = true:
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
// valid = true:
// valid == true if:

@@ -15,6 +16,10 @@ func resourceARecord() *schema.Resource {
Update: resourceARecordUpdate,
Delete: resourceARecordDelete,

Importer: &schema.ResourceImporter{
State: stateImporter,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but I planned to clean up all the deprecated fields/types later. Probably it is possible to do it now easily. I will try.

objMgr := ibclient.NewObjectManager(m.(ibclient.IBConnector), "Terraform", "")
hostRec, err = objMgr.SearchHostRecordByAltId(internalId, ref, eaNameForInternalId)
hostRec, err = objMgr.SearchHostRecordByAltId(internalId.String(), ref, eaNameForInternalId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this SearchHostRecordByAltId function is defined in the infoblox-go-client?

AltId property is terraform-provider specific, so this func should be defined in this repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not Terraform specific. Actually, it is a combined searching, by a NIOS object's reference at 1st, then (if not found) by an EA with the given name and value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess, this issue is not in the scope of this review, so I will create a separate ticket in the infoblox-go-client repo, and resolve this thread.

Copy link
Collaborator

Choose a reason for hiding this comment

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

// - ... and separated by the delimiter
// - ... and the 1st one is a valid internal ID
// - ... and the 2nd one is not empty
func getAltIdFields(altId string) (internalId *internalResourceId, ref string, valid bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you return the error value instead of valid bool value?

This will simplify the functions logic down the stack. Each time you're using the valid argument, you format the error in the caller function anyway (here, here, and here).

Instead of formatting error in the caller function each time, just format it in getAltIdFields, and return instead of valid return argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably you are right. I do not remember the exact reason. I will try to use the canonical way, and if there will be a real reason why to choose the opposite, I will document it with a comment.

@@ -21,36 +22,89 @@ const (
altIdSeparator = "|"
)

func generateInternalId() string {
return uuid.NewString()
// Internal ID represents an immutable ID during resource's lifecycle.
Copy link
Collaborator

Choose a reason for hiding this comment

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

For godoc it's better to start type comment with the type name:

Suggested change
// Internal ID represents an immutable ID during resource's lifecycle.
// internalResourceId represents an immutable ID during resource's lifecycle.

if len(idParts) != 2 {
err = fmt.Errorf("invalid internal ID for host record: '%s'", altId)
return
// Returns a pointer to parsed internal resource ID, nil otherwise.
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
// Returns a pointer to parsed internal resource ID, nil otherwise.
// newInternalResourceIdFromString returns a pointer to parsed internal resource ID, nil otherwise.

infoblox/provider.go Outdated Show resolved Hide resolved
Co-authored-by: Aleksei Chernevskii <[email protected]>
@skudriavtsev skudriavtsev merged commit 57c847c into infobloxopen:master Aug 9, 2022
@surskitt
Copy link

This is great to see.

I have to ask now, when should we expect to see it in a release?

Would you recommend against us building the provider from the current master just to perform the resource importing we've needed? I'm intending on just using it for the import then downgrading back to the stable release.

@SudoSpartanDan
Copy link

@surskitt Yes! Agreed. @achernevskii @skudriavtsev Ideas on a release date?

@collenkhanyile
Copy link

Thank you guys for all the good work. Release date atleast?

@ranjishmp
Copy link
Collaborator

Release date yet to confirm as QA team is yet to validate. Also we are planning to include Data Source support for all the possible resources along with this release. This is under development now

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.

6 participants