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

Add subject alternative names to azurerm_key_vault_certificate #2123

Conversation

draggeta
Copy link
Contributor

@draggeta draggeta commented Oct 20, 2018

Because of hacktober I decided to just try my hand at this. Either way. This allows you to specify subject alternative names for the azurerm_key_vault_certificate resource. All combinations of FQDNs, email addresses and UPNs are possible.

Test results:

PS > go test -timeout 180m -v -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc" github.com\terraform-providers\terraform-provider-azurerm\azurerm -run ^TestAccAzureRMKeyVaultCertificate_basicGenerateSans$
=== RUN   TestAccAzureRMKeyVaultCertificate_basicGenerateSans
--- PASS: TestAccAzureRMKeyVaultCertificate_basicGenerateSans (222.49s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm       232.421s

Closes #479
Also fixes #1309

@ghost ghost added the size/M label Oct 20, 2018
@draggeta draggeta changed the title Add subject alternative names to azurerm_keyvault_certificate Add subject alternative names to azurerm_key_vault_certificate Oct 20, 2018
@ghost ghost added size/L and removed size/M labels Oct 22, 2018
@draggeta
Copy link
Contributor Author

draggeta commented Oct 25, 2018

This is now somehow failing on linting with gofmt -s. I've written to the file with -w and it still outputs no diff in git for me. Both on a Ubuntu and Windows device.

@tombuildsstuff do you have any idea how I can fix this?

draggeta and others added 2 commits October 26, 2018 14:53
- SANS: when item was undefined, it always cause a diff in the plan
- SANS: made the block optional as it should be
}
}

return policy
}

func expandKeyVaultSanProperty(input []interface{}) *[]string {
Copy link
Collaborator

@katbyte katbyte Oct 27, 2018

Choose a reason for hiding this comment

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

There is a utils.ExpandStringArray that does exactly this

@katbyte
Copy link
Collaborator

katbyte commented Oct 27, 2018

Hi @draggeta,

We have a make fmt command we use to run, an gofmt and a make lint CI runs to check gofmt and more

I ran it and pushed up the changes

@tombuildsstuff
Copy link
Contributor

@draggeta we're currently using Go 1.10 on this project (but Go 1.11 is the latest) - we'll be moving to this in the near future; of particular note between the two versions is how go fmt can return different results (which I believe may be causing the issue here?)

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @draggeta

I've taken a look through and left a couple of comments but this otherwise LGTM; if we can fix those up we should be able to run the tests and get this merged :)

Thanks!

azurerm/resource_arm_key_vault_certificate.go Outdated Show resolved Hide resolved
azurerm/resource_arm_key_vault_certificate.go Outdated Show resolved Hide resolved
azurerm/resource_arm_key_vault_certificate.go Outdated Show resolved Hide resolved
azurerm/resource_arm_key_vault_certificate.go Outdated Show resolved Hide resolved
tombuildsstuff and others added 4 commits October 27, 2018 22:04
Co-Authored-By: draggeta <draggeta@users.noreply.github.com>
Co-Authored-By: draggeta <draggeta@users.noreply.github.com>
Co-Authored-By: draggeta <draggeta@users.noreply.github.com>
Co-Authored-By: draggeta <draggeta@users.noreply.github.com>
@draggeta
Copy link
Contributor Author

draggeta commented Oct 27, 2018

@tombuildsstuff Well, that explains a lot, I'm using 1.11 😄

As for the changes. I implemented them, but now I always end up with 1 item for the SAN when importing or when it is not defined. That was why I had written the code like I did. I had forgotten about it.

Am I correct in my assumption that this should be fixed with a DiffSuppressFunc?

@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Oct 27, 2018

@draggeta heh - thanks for pushing those changes too :)

Am I correct in my assumption that this should be fixed with a DiffSuppressFunc?

Kinda; since this is a list we'll make this Computed instead (which we can do here) - given one item's being returned from Azure this means an item's being returned even if there's no items in that list; it also means we'll want to ensure we always set the items in that block (e.g. upns) - I'll push an updated review, but this otherwise looks good to me 👍


if upns := san.Upns; upns != nil {
sanOutput["upns"] = *upns
}
Copy link
Contributor

Choose a reason for hiding this comment

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

in retrospect (since they're returned from the API) - we'll want to always flatten these fields (even if there's no items returned) - as such we should be able to make this:

sanOutput["emails"] = utils.FlattenStringArray(san.Emails)
sanOutput["dns_names"] = utils.FlattenStringArray(san.DNSNames)
sanOutput["upns"] = utils.FlattenStringArray(san.Upns)

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @draggeta

Thanks for pushing those changes - this now LGTM 👍 - I'll kick off the test suite shortly

Thanks!

@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Oct 30, 2018

Ignoring a known test failure - the tests pass - thanks for this @draggeta :):

screenshot 2018-10-30 at 15 44 10

@tombuildsstuff tombuildsstuff merged commit ad9334a into hashicorp:master Oct 30, 2018
tombuildsstuff added a commit that referenced this pull request Oct 30, 2018
@draggeta draggeta deleted the add-subject-alternative-names-to-key-vault-certificates branch October 30, 2018 21:58
@tombuildsstuff
Copy link
Contributor

hi @draggeta

Just to let you know that this has been released as a part of v1.18 of the AzureRM Provider (the full changelog is available here). You can upgrade to this by specifying the version in the provider block (as shown below) and then running terraform init -upgrade

provider "azurerm" {
  version = "=1.18.0"
}

Thanks!

@ghost
Copy link

ghost commented Mar 6, 2019

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants