-
Notifications
You must be signed in to change notification settings - Fork 555
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
Add vault_config_ui_custom_message resource #2154
Add vault_config_ui_custom_message resource #2154
Conversation
6ba3ca5
to
c9be60e
Compare
clean up unnecessary code
I've added the do-not-merge label for now, because this change should only be adopted once Vault v.1.16.0 is release. |
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.
Looking great so far! Thanks @marcboudreau ! Just a few adjustments needed from what I can see. Great work! :)
CHANGELOG.md
Outdated
@@ -1,5 +1,8 @@ | |||
## Unreleased | |||
|
|||
FEATURES: | |||
* Add new resource `vault_config_ui_custom_message`: ([#2154](https://github.com/hashicorp/terraform-provider-vault/pull/2154)). |
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.
* Add new resource `vault_config_ui_custom_message`: ([#2154](https://github.com/hashicorp/terraform-provider-vault/pull/2154)). | |
* Add new resource `vault_config_ui_custom_message`. Requires Vault 1.16+: ([#2154](https://github.com/hashicorp/terraform-provider-vault/pull/2154)). |
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.
Could we move this down to the "FEATURES" block below?
|
||
func configUICustomMessageResource() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: configUICustomMessageCreate, |
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.
Since this endpoint is only available in Vault 1.16 we can add a minimum version requirement to the entire resource
CreateContext: configUICustomMessageCreate, | |
CreateContext: provider.MountCreateContextWrapper(configUICustomMessageCreate, provider.VaultVersion116), | |
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.
If we add this, then we are safe to merge before Vault 1.16 is released. We usually do a TFVP release shortly after the Vault release. So this will allow us to not have to scramble to get things merged and in sync between the two projects. :)
} | ||
|
||
if secret == nil || secret.Data == nil { | ||
return diag.Errorf("response from Vault server is empty") |
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 believe this block will tell us that the resource does not exist in Vault. In this case, we will want to unset the ID and return nil to signal to Terraform that this object should be removed from state.
return diag.Errorf("response from Vault server is empty") | |
log.Printf("[WARN] Custom message not found, removing from state") | |
d.SetId("") | |
return nil |
|
||
resource.Test(t, resource.TestCase{ | ||
ProviderFactories: providerFactories, | ||
PreCheck: func() { testutil.TestAccPreCheck(t) }, |
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.
PreCheck: func() { testutil.TestAccPreCheck(t) }, | |
PreCheck: func() { testutil.TestAccPreCheck(t) }, | |
SkipIfAPIVersionLT(t, testProvider.Meta(), provider.VaultVersion116) | |
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 will make sure the test doesn't run against Vault versions that don't support this resource.
@@ -146,7 +150,9 @@ func configUICustomMessageRead(ctx context.Context, d *schema.ResourceData, meta | |||
} | |||
|
|||
if secret == nil || secret.Data == nil { | |||
return diag.Errorf("response from Vault server is empty") | |||
log.Printf("response from Vault server is empty") |
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 need to prepend the log with a level. I would recommend either DEBUG or WARN:
log.Printf("response from Vault server is empty") | |
log.Printf("[DEBUG] response from Vault server is empty for %q, removing from state", id) |
|
||
log.Printf("[DEBUG] Reading custom message %q", id) | ||
secret, e := client.Sys().ReadUICustomMessage(id) | ||
if e != 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.
Does this endpoint return a 404 error if the resource isn't found or is the next if block how we know the resource does not exist in Vault? If Vault does return a 404, we should remove it from TF state (d.setId("")
) here as well.
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.
Here is an example of doing this check:
terraform-provider-vault/vault/resource_approle_auth_backend_role.go
Lines 299 to 307 in 9f97824
if err != nil { | |
if util.Is404(err) { | |
log.Printf("[DEBUG] AppRole auth backend role %q not found, removing from state", path) | |
d.SetId("") | |
return nil | |
} else { | |
return diag.Errorf("error deleting AppRole auth backend role %q, err=%s", path, err) | |
} | |
} |
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.
Vault does indeed return an HTTP 404 error if no message with the ID provided to the ReadUICustomMessage function exists.
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.
Approved as long as we make the request changes. Thanks @marcboudreau !
Clearing out the 4.0.0 milestone for now and we will do another release closer to Vault GA. |
fix debug log message format
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.
LGTM! Thanks @marcboudreau !
Description
This PR introduces a new resource named vault_config_ui_custom_message to the provider to allow managing the newly introduced UI Custom Messages in Vault v.1.16.0.
Checklist
Output from acceptance testing:
Community Note