From 14bd20dc0aa59851f32eb751a1811aa5429b31ce Mon Sep 17 00:00:00 2001 From: Alex Lake Date: Tue, 5 May 2020 13:18:39 -0700 Subject: [PATCH 1/2] Add a retain option --- circleci/resource_circleci_environment_variable.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/circleci/resource_circleci_environment_variable.go b/circleci/resource_circleci_environment_variable.go index d9607ec7..6efc256f 100644 --- a/circleci/resource_circleci_environment_variable.go +++ b/circleci/resource_circleci_environment_variable.go @@ -70,6 +70,12 @@ func resourceCircleCIEnvironmentVariable() *schema.Resource { return hashString(value.(string)) }, }, + "retain_on_destroy": { + Description: "Set to true to prevent terraform from deleting the environment variable when this resource is destroyed.", + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, SchemaVersion: 1, StateUpgraders: []schema.StateUpgrader{ @@ -212,6 +218,12 @@ func resourceCircleCIEnvironmentVariableDelete(d *schema.ResourceData, m interfa organization := getOrganization(d, providerClient) projectName := d.Get("project").(string) envName := d.Get("name").(string) + shouldRetain := d.Get("retain_on_destroy").(bool) + + if shouldRetain { + d.SetId("") + return nil + } err := providerClient.DeleteEnvVar(organization, projectName, envName) if err != nil { From 5c97985f3e60e7bac18d33ef162275295c3b0338 Mon Sep 17 00:00:00 2001 From: ajlake Date: Tue, 5 May 2020 17:17:40 -0700 Subject: [PATCH 2/2] Update resource_circleci_environment_variable.go --- circleci/resource_circleci_environment_variable.go | 1 + 1 file changed, 1 insertion(+) diff --git a/circleci/resource_circleci_environment_variable.go b/circleci/resource_circleci_environment_variable.go index 6efc256f..bdfa3918 100644 --- a/circleci/resource_circleci_environment_variable.go +++ b/circleci/resource_circleci_environment_variable.go @@ -74,6 +74,7 @@ func resourceCircleCIEnvironmentVariable() *schema.Resource { Description: "Set to true to prevent terraform from deleting the environment variable when this resource is destroyed.", Type: schema.TypeBool, Optional: true, + ForceNew: true, Default: false, }, },