From bb4c4fbd49fb8c46f3e2043a17103ee8f2e2b184 Mon Sep 17 00:00:00 2001 From: Farbod Ahmadian Date: Thu, 8 Aug 2024 17:04:55 +0200 Subject: [PATCH] cli: show warning when creating token if policy doesn't exist (#16437) --- .changelog/16437.txt | 3 +++ command/acl_token_create.go | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 .changelog/16437.txt diff --git a/.changelog/16437.txt b/.changelog/16437.txt new file mode 100644 index 000000000..2844bac4a --- /dev/null +++ b/.changelog/16437.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: `acl token create` will now emit a warning if the token has a policy that does not yet exist +``` diff --git a/command/acl_token_create.go b/command/acl_token_create.go index 5007839c8..70c09efd6 100644 --- a/command/acl_token_create.go +++ b/command/acl_token_create.go @@ -154,6 +154,14 @@ func (c *ACLTokenCreateCommand) Run(args []string) int { return 1 } + // Show warning if policy doesn't exist + for _, policy := range tk.Policies { + _, _, err := client.ACLPolicies().Info(policy, nil) + if err != nil { + c.Ui.Warn(fmt.Sprintf("Error fetching info on %s policy: %s", policy, err)) + } + } + // Create the bootstrap token token, _, err := client.ACLTokens().Create(tk, nil) if err != nil {