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

azurerm_batch_certificate: Allow empty password when format is pfx #10642

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func resourceBatchCertificate() *schema.Resource {

"password": {
Type: schema.TypeString,
Optional: true, // Required if `format` is "Pfx"
Optional: true, // Cannot be used when `format` is "Cer"
Sensitive: true,
},

Expand Down Expand Up @@ -271,9 +271,6 @@ func resourceBatchCertificateDelete(d *schema.ResourceData, meta interface{}) er
}

func validateBatchCertificateFormatAndPassword(format string, password string) error {
if format == "Pfx" && password == "" {
return fmt.Errorf("Batch Certificate Password is required when Format is `Pfx`")
}
if format == "Cer" && password != "" {
return fmt.Errorf(" Batch Certificate Password must not be specified when Format is `Cer`")
}
Expand Down
20 changes: 13 additions & 7 deletions azurerm/internal/services/batch/batch_certificate_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
type BatchCertificateResource struct {
}

func TestAccBatchCertificate_Pfx(t *testing.T) {
func TestAccBatchCertificate_PfxWithPassword(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_certificate", "test")
r := BatchCertificateResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.pfx(data),
Config: r.pfxWithPassword(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("format").HasValue("Pfx"),
Expand All @@ -42,9 +42,15 @@ func TestAccBatchCertificate_PfxWithoutPassword(t *testing.T) {

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.pfxWithoutPassword(data),
ExpectError: regexp.MustCompile("Password is required"),
Config: r.pfxWithoutPassword(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("format").HasValue("Pfx"),
check.That(data.ResourceName).Key("thumbprint").HasValue("42c107874fd0e4a9583292a2f1098e8fe4b2edda"),
check.That(data.ResourceName).Key("thumbprint_algorithm").HasValue("sha1"),
),
},
data.ImportStep("certificate"),
})
}

Expand Down Expand Up @@ -92,7 +98,7 @@ func (t BatchCertificateResource) Exists(ctx context.Context, clients *clients.C
return utils.Bool(resp.CertificateProperties != nil), nil
}

func (BatchCertificateResource) pfx(data acceptance.TestData) string {
func (BatchCertificateResource) pfxWithPassword(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -113,7 +119,7 @@ resource "azurerm_batch_account" "test" {
resource "azurerm_batch_certificate" "test" {
resource_group_name = azurerm_resource_group.test.name
account_name = azurerm_batch_account.test.name
certificate = filebase64("testdata/batch_certificate.pfx")
certificate = filebase64("testdata/batch_certificate_password.pfx")
format = "Pfx"
password = "terraform"
thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda"
Expand Down Expand Up @@ -143,7 +149,7 @@ resource "azurerm_batch_account" "test" {
resource "azurerm_batch_certificate" "test" {
resource_group_name = azurerm_resource_group.test.name
account_name = azurerm_batch_account.test.name
certificate = filebase64("testdata/batch_certificate.pfx")
certificate = filebase64("testdata/batch_certificate_nopassword.pfx")
format = "Pfx"
thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda"
thumbprint_algorithm = "SHA1"
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion website/docs/r/batch_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following arguments are supported:

* `format` - (Required) The format of the certificate. Possible values are `Cer` or `Pfx`.

* `password` - (Optional) The password to access the certificate's private key. This must and can only be specified when `format` is `Pfx`.
* `password` - (Optional) The password to access the certificate's private key. This can only be specified when `format` is `Pfx`.

* `thumbprint` - (Required) The thumbprint of the certificate. At this time the only supported value is 'SHA1'.

Expand Down