-
Couldn't load subscription status.
- Fork 50
tailscale/resource_acl: relax policy validation during plan steps #554
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,9 +6,11 @@ package tailscale | |||||
| import ( | ||||||
| "context" | ||||||
| "fmt" | ||||||
| "regexp" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/hashicorp/go-cty/cty" | ||||||
| "github.com/hashicorp/terraform-plugin-log/tflog" | ||||||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||||
|
|
||||||
|
|
@@ -25,6 +27,8 @@ If tests are defined in the ACL (the top-level "tests" section), ACL validation | |||||
| // TODO: use an exported variable when https://github.com/hashicorp/terraform-plugin-sdk/issues/803 has been addressed. | ||||||
| const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66" | ||||||
|
|
||||||
| var syntaxErrorMessage = regexp.MustCompile(`^ACL validation failed: line \d+, column \d+:`) | ||||||
|
|
||||||
| func resourceACL() *schema.Resource { | ||||||
| return &schema.Resource{ | ||||||
| Description: resourceACLDescription, | ||||||
|
|
@@ -42,7 +46,17 @@ func resourceACL() *schema.Resource { | |||||
| if rd.Get("acl").(string) == "" { | ||||||
| return nil | ||||||
| } | ||||||
| return client.PolicyFile().Validate(ctx, rd.Get("acl").(string)) | ||||||
| err := client.PolicyFile().Validate(ctx, rd.Get("acl").(string)) | ||||||
| if err != nil && syntaxErrorMessage.MatchString(err.Error()) { | ||||||
| return err | ||||||
| } else if err != nil { | ||||||
| // non-syntax errors are logged but do not fail the plan operation | ||||||
| tflog.Debug(ctx, "ACL validation unsuccessful due to advisory error", map[string]interface{}{"error": err}) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can soften the wording and call them warnings, but the validation failures are not necessarily undefined dependencies. The provider should not characterize what caused the error if it just forwards what the BE returned, which can change in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hence the use of "may" |
||||||
| return nil | ||||||
| } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From our conversations, warnings might be counterproductive and confuse people, but we should not make the information completely unavailable. |
||||||
|
|
||||||
| tflog.Debug(ctx, "ACL validation successful") | ||||||
| return nil | ||||||
| }, | ||||||
| Schema: map[string]*schema.Schema{ | ||||||
| "acl": { | ||||||
|
|
||||||
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.
Maybe include a comment about what assumptions this makes about the control server.
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 do you mean by assumptions about the control server?
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.
The assumption that all syntax errors present as an error in this form, and that if this change, the logic breaks.