diff --git a/client/project_deployment_retention.go b/client/project_deployment_retention.go index 5eaae325..8c05a7fb 100644 --- a/client/project_deployment_retention.go +++ b/client/project_deployment_retention.go @@ -126,7 +126,12 @@ func (c *Client) GetDeploymentRetention(ctx context.Context, projectID, teamID s body: "", }, &p) if p.DeploymentExpiration == nil { - return DeploymentExpiration{}, fmt.Errorf("deployment retention not found") + return DeploymentExpiration{ + ExpirationPreview: 36500, + ExpirationProduction: 36500, + ExpirationCanceled: 36500, + ExpirationErrored: 36500, + }, nil } return *p.DeploymentExpiration, err } diff --git a/vercel/data_source_project_deployment_retention.go b/vercel/data_source_project_deployment_retention.go index cdb91735..9a5c6ac2 100644 --- a/vercel/data_source_project_deployment_retention.go +++ b/vercel/data_source_project_deployment_retention.go @@ -110,10 +110,6 @@ func (r *projectDeploymentRetentionDataSource) Read(ctx context.Context, req dat } out, err := r.client.GetDeploymentRetention(ctx, config.ProjectID.ValueString(), config.TeamID.ValueString()) - if client.NotFound(err) { - resp.State.RemoveResource(ctx) - return - } if err != nil { resp.Diagnostics.AddError( "Error reading project deployment retention", diff --git a/vercel/data_source_project_deployment_retention_test.go b/vercel/data_source_project_deployment_retention_test.go index 1773b21d..d75560c2 100644 --- a/vercel/data_source_project_deployment_retention_test.go +++ b/vercel/data_source_project_deployment_retention_test.go @@ -21,10 +21,15 @@ func TestAcc_ProjectDeploymentRetentionDataSource(t *testing.T) { Config: testAccProjectDeploymentRetentionDataSourceConfig(nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), - resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "1m"), - resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "unlimited"), - resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), - resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_errored", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_preview", "1m"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_production", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_errored", "unlimited"), + + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example_2", "expiration_preview", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example_2", "expiration_production", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example_2", "expiration_canceled", "unlimited"), + resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example_2", "expiration_errored", "unlimited"), ), }, }, @@ -53,5 +58,20 @@ data "vercel_project_deployment_retention" "example" { project_id = vercel_project_deployment_retention.example.project_id %[3]s } + +resource "vercel_project" "example_2" { + name = "test-acc-example-project-2-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } +} + +data "vercel_project_deployment_retention" "example_2" { + project_id = vercel_project.example_2.id + %[3]s +} `, projectName, testGithubRepo(), teamIDConfig()) } diff --git a/vercel/resource_project_deployment_retention.go b/vercel/resource_project_deployment_retention.go index 8c9125aa..165e95d8 100644 --- a/vercel/resource_project_deployment_retention.go +++ b/vercel/resource_project_deployment_retention.go @@ -3,7 +3,6 @@ package vercel import ( "context" "fmt" - "strings" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -303,24 +302,10 @@ func (r *projectDeploymentRetentionResource) Update(ctx context.Context, req res } } -// splitID is a helper function for splitting an import ID into the corresponding parts. -// It also validates whether the ID is in a correct format. -func splitProjectDeploymentRetentionID(id string) (teamID, projectID string, ok bool) { - attributes := strings.Split(id, "/") - if len(attributes) == 2 { - return attributes[0], attributes[1], true - } - if len(attributes) == 1 { - return "", attributes[0], true - } - - return "", "", false -} - // ImportState takes an identifier and reads all the project deployment retention information from the Vercel API. // The results are then stored in terraform state. func (r *projectDeploymentRetentionResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - teamID, projectID, ok := splitProjectDeploymentRetentionID(req.ID) + teamID, projectID, ok := splitInto1Or2(req.ID) if !ok { resp.Diagnostics.AddError( "Error importing project deployment retention", diff --git a/vercel/resource_project_deployment_retention_test.go b/vercel/resource_project_deployment_retention_test.go index 63cbc4dd..e1ff42cb 100644 --- a/vercel/resource_project_deployment_retention_test.go +++ b/vercel/resource_project_deployment_retention_test.go @@ -65,6 +65,16 @@ func TestAcc_ProjectDeploymentRetention(t *testing.T) { resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_errored", "1m"), ), }, + { + Config: testAccProjectDeploymentRetentionsConfigAllUnlimited(nameSuffix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "unlimited"), + resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "unlimited"), + resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), + resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_errored", "unlimited"), + ), + }, }, }) } @@ -115,6 +125,29 @@ resource "vercel_project_deployment_retention" "example" { `, projectName, testGithubRepo(), teamIDConfig()) } +func testAccProjectDeploymentRetentionsConfigAllUnlimited(projectName string) string { + return fmt.Sprintf(` +resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } +} + +resource "vercel_project_deployment_retention" "example" { + project_id = vercel_project.example.id + %[3]s + expiration_preview = "unlimited" + expiration_production = "unlimited" + expiration_canceled = "unlimited" + expiration_errored = "unlimited" +} +`, projectName, testGithubRepo(), teamIDConfig()) +} + func testAccProjectDeploymentRetentionsConfigWithMissingFields(projectName string) string { return fmt.Sprintf(` resource "vercel_project" "example" { diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index f23b34f0..9f7994a1 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -3,7 +3,6 @@ package vercel import ( "context" "fmt" - "strings" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -412,24 +411,10 @@ func (r *projectEnvironmentVariableResource) Delete(ctx context.Context, req res }) } -// splitID is a helper function for splitting an import ID into the corresponding parts. -// It also validates whether the ID is in a correct format. -func splitProjectEnvironmentVariableID(id string) (teamID, projectID, envID string, ok bool) { - attributes := strings.Split(id, "/") - if len(attributes) == 3 { - return attributes[0], attributes[1], attributes[2], true - } - if len(attributes) == 2 { - return "", attributes[0], attributes[1], true - } - - return "", "", "", false -} - // ImportState takes an identifier and reads all the project environment variable information from the Vercel API. // The results are then stored in terraform state. func (r *projectEnvironmentVariableResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - teamID, projectID, envID, ok := splitProjectEnvironmentVariableID(req.ID) + teamID, projectID, envID, ok := splitInto2Or3(req.ID) if !ok { resp.Diagnostics.AddError( "Error importing project environment variable", diff --git a/vercel/resource_shared_environment_variable.go b/vercel/resource_shared_environment_variable.go index 448864d8..ca66fa85 100644 --- a/vercel/resource_shared_environment_variable.go +++ b/vercel/resource_shared_environment_variable.go @@ -3,7 +3,6 @@ package vercel import ( "context" "fmt" - "strings" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -421,21 +420,10 @@ func (r *sharedEnvironmentVariableResource) Delete(ctx context.Context, req reso }) } -// splitID is a helper function for splitting an import ID into the corresponding parts. -// It also validates whether the ID is in a correct format. -func splitSharedEnvironmentVariableID(id string) (teamID, envID string, ok bool) { - attributes := strings.Split(id, "/") - if len(attributes) == 2 { - return attributes[0], attributes[1], true - } - - return "", "", false -} - // ImportState takes an identifier and reads all the shared environment variable information from the Vercel API. // The results are then stored in terraform state. func (r *sharedEnvironmentVariableResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - teamID, envID, ok := splitSharedEnvironmentVariableID(req.ID) + teamID, envID, ok := splitInto1Or2(req.ID) if !ok { resp.Diagnostics.AddError( "Error importing shared environment variable",