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

fix: add vra_deployment.recreate_if_expired_at attribute #514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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/retry"
"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