Skip to content
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

New Resource: azurerm_key_vault_secret #269

Merged
merged 7 commits into from
Aug 25, 2017
Merged

Conversation

tombuildsstuff
Copy link
Contributor

Adds the azurerm_key_vault_secret resource - with support for setting secrets at particular versions.

Note this doesn't implement the Enabled, Activation Date or Expiration Date fields due to us being unable to make API calls for a disabled secret (due to the way the API's designed.

Tests pass:

$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 120m -run TestAccAzureRMKeyVaultSec
=== RUN   TestAccAzureRMKeyVaultSecret_importBasic
--- PASS: TestAccAzureRMKeyVaultSecret_importBasic (75.62s)
=== RUN   TestAccAzureRMKeyVaultSecret_importComplete
--- PASS: TestAccAzureRMKeyVaultSecret_importComplete (84.79s)
=== RUN   TestAccAzureRMKeyVaultSecret_basic
--- PASS: TestAccAzureRMKeyVaultSecret_basic (80.49s)
=== RUN   TestAccAzureRMKeyVaultSecret_complete
--- PASS: TestAccAzureRMKeyVaultSecret_complete (82.81s)
=== RUN   TestAccAzureRMKeyVaultSecret_update
--- PASS: TestAccAzureRMKeyVaultSecret_update (98.13s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	421.867s
$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 120m -run TestAccAzureRMKeyVaultSecret_validateName
=== RUN   TestAccAzureRMKeyVaultSecret_validateName
--- PASS: TestAccAzureRMKeyVaultSecret_validateName (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	0.017s
$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 120m -run TestAccAzureRMKeyVaultSecret_parseID
=== RUN   TestAccAzureRMKeyVaultSecret_parseID
--- PASS: TestAccAzureRMKeyVaultSecret_parseID (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	0.018s

Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, couple of potential panics that should be caught, but otherwise looks good.

keyVaultBaseUrl := d.Get("vault_uri").(string)
value := d.Get("value").(string)
contentType := d.Get("content_type").(string)
tags := d.Get("tags").(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tags is optional, this cast will panic on a nil "tags" block:

tags { }

With the complex types here, easier to try the cast to verify against potential panics.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

& repeated other areas 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree, but afaik HCL is returning an empty map here - given we use this pattern throughout the provider - example from azurerm_resource_group:

$ cat main.tf
resource "azurerm_resource_group" "test"{
  name = "tom"
  location = "westus"
  tags { }
}
$ envchain azurerm terraform plan -refresh
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

  + azurerm_resource_group.test
      location: "westus"
      name:     "tom"
      tags.%:   "<computed>"


Plan: 1 to add, 0 to change, 0 to destroy.
✔ ~/code/src/tmp/jake
17:01 $ envchain azurerm terraform apply
azurerm_resource_group.test: Creating...
  location: "" => "westus"
  name:     "" => "tom"
  tags.%:   "" => "<computed>"
azurerm_resource_group.test: Creation complete (ID: /subscriptions/xxxxxxxxxx/resourceGroups/tom)

d.Set("version", respID.Version)
d.Set("content_type", resp.ContentType)

flattenAndSetTags(d, resp.Tags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complex types should always check the returned error from d.Set(), more opportunities for things to go wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given this affects every resource in the Provider - I'm going to make this a separate task & do this across everything

@ghost
Copy link

ghost commented Apr 1, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants