-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_network_interface & azurerm_arm_loadbalancer: fixing d.Set() set errors and some additional validation #1403
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.
Left some comments inline, but this is otherwise off to a good start :)
azurerm/helpers/validate/azure.go
Outdated
//todo, match subscription/{guid} and provider/name.name perhaps? | ||
if matched := regexp.MustCompile(`(/subscriptions/)|(/providers/)`).Match([]byte(v)); !matched { | ||
errors = append(errors, fmt.Errorf("azure resource ID %q should start with with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'", k)) | ||
} |
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.
IMO we'd be better to just call parseAzureResourceID
here?
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.
tenants
are also a possible prefix too e.g. /tenants/000/subscriptions/000/...
_, errors := Ip4Address(tc.Ip, "test") | ||
|
||
if len(errors) < tc.Errors { | ||
t.Fatalf("Expected AzureResourceId to have an error for '%q'", tc.Ip) |
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.
minor technically '%q'
can be just %q
azurerm/resource_arm_loadbalancer.go
Outdated
Required: true, | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.StringNotEmpty, |
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.
there's a generic validation function in Core for "no default value" which may be better to use?
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 didn't know about that one! validation.NoZeroValues
is perfect.
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.
a few minor comments, otherwise LGTM 👍
return idObj, nil | ||
} | ||
|
||
func composeAzureResourceID(idObj *ResourceID) (id string, err 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.
I don't see anything using this apart from the Tests, in which case can we remove this?
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 removed the top level one, and kept this and the tests here on the new function
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.
sorry, I meant since this is Private and it's not being used within this Package, I think this is dead code?
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: azure.ValidateResourceId, |
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 an IP Address, not a Resource ID?
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.
Whoops, got copy paste happy it seems
// into a ResourceID. We make assumptions about the structure of URLs, | ||
// which is obviously not good, but the best thing available given the | ||
// SDK. | ||
func ParseAzureResourceID(id string) (*ResourceID, 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.
are we also going to call this method from the existing method to give us a migration path whilst refactoring?
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.
Thats a good idea, now threading down to new method
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
a result of investigating #1318