-
Notifications
You must be signed in to change notification settings - Fork 79
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
Import functionality #225
Conversation
…plementing 'import' functionality'
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 |
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.
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.
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.
Sure.
return true | ||
} | ||
|
||
func generateAltId(internalId *internalResourceId, ref string) string { |
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's AltId
? What this function will generate?
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 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) { |
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.
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.
if ok && isValidInternalId(stringVal) { | |
if _, err := uuid.Parse(stringVal); ok && 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.
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
internalId.String(), altIdSeparator, ref) | ||
} | ||
|
||
// valid = true: |
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.
// valid = true: | |
// valid == true if: |
@@ -15,6 +16,10 @@ func resourceARecord() *schema.Resource { | |||
Update: resourceARecordUpdate, | |||
Delete: resourceARecordDelete, | |||
|
|||
Importer: &schema.ResourceImporter{ | |||
State: stateImporter, |
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.
FYI State
field is deprecated:
https://github.com/hashicorp/terraform-plugin-sdk/blob/v2.4.3/helper/schema/resource_importer.go#L20
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.
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) |
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 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.
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 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.
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.
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.
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.
// - ... 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) { |
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 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.
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.
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. |
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.
For godoc it's better to start type comment with the type name:
// 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. |
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.
// Returns a pointer to parsed internal resource ID, nil otherwise. | |
// newInternalResourceIdFromString returns a pointer to parsed internal resource ID, nil otherwise. |
Co-authored-by: Aleksei Chernevskii <[email protected]>
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. |
@surskitt Yes! Agreed. @achernevskii @skudriavtsev Ideas on a release date? |
Thank you guys for all the good work. Release date atleast? |
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 |
No description provided.