Skip to content

Commit

Permalink
fix: in more updated version of terraform, failing test is executed w…
Browse files Browse the repository at this point in the history
…ay faster during the time now comparison in our validation to check if certificate to be renewed. Updating to 1 day to make sure we always need renewal
  • Loading branch information
luispresuelVenafi committed Jan 21, 2025
1 parent cb9042c commit 29f9e03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions venafi/resource_venafi_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ func checkForRenew(cert x509.Certificate, expirationWindow int) (renewRequired b
renewWindow := time.Duration(expirationWindow) * time.Hour
certDuration := getCertDuration(&cert)
validExpirationWindow(certDuration, renewWindow)
// time now + 90 will be after (date) cert After?
// if yes, renew is required
renewRequired = time.Now().Add(renewWindow).After(cert.NotAfter)
return renewRequired
}
Expand Down
4 changes: 2 additions & 2 deletions venafi/resource_venafi_certificate_vaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func TestVAASSignedCertWithUnacceptableDNServiceGeneratedCSR(t *testing.T) {

func TestVAASSignedCertUpdateRenew(t *testing.T) {
/*
This test focuses on the renewal feature. We need to set the expiration window to be the same as the certificate
This test focuses on the renewal feature. We need to set the expiration window to be the same or greater as the certificate
duration in order for the renew to take action. ExpectNonEmptyPlan is set true since we will always be able to
update the certificate on terraform plan re-apply. This is applicable for test purposes only, in a real scenario
the expiration window should not be too long, thus the terraform plan should be empty after a re-apply (once a
Expand All @@ -417,7 +417,7 @@ func TestVAASSignedCertUpdateRenew(t *testing.T) {
data.cn = rand + "." + domain
data.private_key_password = "123xxx"
data.key_algo = rsa2048
data.expiration_window = 90 * 24 // 90 days
data.expiration_window = 91 * 24 // 91 days, certificate always will require renewal
//
config := fmt.Sprintf(vaasConfig, vaasProvider, data.cn, data.key_algo, data.private_key_password, data.expiration_window)
t.Logf("Testing Cloud certificate with config:\n %s", config)
Expand Down

0 comments on commit 29f9e03

Please sign in to comment.