Skip to content

Commit

Permalink
add vra_deployment.recreate_if_expired_at attribute, fix vmware#473
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Biegert <[email protected]>
  • Loading branch information
Jonathan Biegert committed Apr 18, 2024
1 parent afc822e commit 1c6ae3a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions vra/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vra-sdk-go/pkg/client"
Expand All @@ -39,6 +40,30 @@ func resourceDeployment() *schema.Resource {
ReadContext: resourceDeploymentRead,
UpdateContext: resourceDeploymentUpdate,
DeleteContext: resourceDeploymentDelete,

CustomizeDiff: customdiff.ForceNewIf(
"recreate_if_expired_at",
func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
planTimeStr, ok := d.GetOk("recreate_if_expired_at")
if !ok {
log.Printf("[DEBUG] Don't special-handle expired deployment, recreate_if_expired_at = %#v", planTimeStr)
return false // don't check expiration
}
planTime, err := strfmt.ParseDateTime(planTimeStr.(string))
if err != nil {
log.Printf("[DEBUG] Failed to parse DateTime variable recreate_if_expired_at: %#v", planTime)
return false
}
expirationTimeStr := d.Get("lease_expire_at")
expirationTime, err := strfmt.ParseDateTime(expirationTimeStr.(string))
if err != nil {
log.Printf("[DEBUG] Failed to parse DateTime attribute lease_expire_at: %#v", expirationTimeStr)
return false
}
log.Printf("checking if expirationTime %s < planTime %s", expirationTime, planTime)
return time.Time(expirationTime).Before(time.Time(planTime))
}),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -175,6 +200,13 @@ func resourceDeployment() *schema.Resource {
Computed: true,
Description: "The status of the deployment with respect to its life cycle operations.",
},

"recreate_if_expired_at": {
Type: schema.TypeString,
Optional: true,
Default: nil,
Description: "If set to `plantimestamp()`, then the deployment will be recreated when it has expired.",
},
},

Timeouts: &schema.ResourceTimeout{
Expand Down

0 comments on commit 1c6ae3a

Please sign in to comment.