Skip to content

Commit

Permalink
fix: [CDS-82953]: Add force delete option for aws, azure, gcp, k8s, r…
Browse files Browse the repository at this point in the history
…ancher, oci and helm connectors (#743)

* fix: [CDS-82953]: Add force delete option for aws, azure, gcp, k8s, rancher, oci and helm connectors

* add changelog file

* update schema from String to Bool for force delete
* update docs
  • Loading branch information
abosii-harness committed Nov 10, 2023
1 parent e96534e commit a0d5e27
Show file tree
Hide file tree
Showing 26 changed files with 471 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .changelog/743.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
resource/platform_connector_aws: added force deletion support
resource/platform_connector_azure_cloud_provider: added force deletion support
resources/platform_connector_gcp: added force deletion support
resources/platform_connector_helm: added force deletion support
resources/platform_connector_kubernetes: added force deletion support
resources/platform_connector_oci_helm: added force deletion support
resources/platform_connector_rancher: added force deletion support
```
1 change: 1 addition & 0 deletions docs/resources/platform_connector_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ resource "harness_platform_connector_aws" "aws" {
- `description` (String) Description of the resource.
- `equal_jitter_backoff_strategy` (Block List, Max: 1) Equal Jitter BackOff Strategy. (see [below for nested schema](#nestedblock--equal_jitter_backoff_strategy))
- `fixed_delay_backoff_strategy` (Block List, Max: 1) Fixed Delay BackOff Strategy. (see [below for nested schema](#nestedblock--fixed_delay_backoff_strategy))
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `full_jitter_backoff_strategy` (Block List, Max: 1) Full Jitter BackOff Strategy. (see [below for nested schema](#nestedblock--full_jitter_backoff_strategy))
- `inherit_from_delegate` (Block List, Max: 1) Inherit credentials from the delegate. (see [below for nested schema](#nestedblock--inherit_from_delegate))
- `irsa` (Block List, Max: 1) Use IAM role for service accounts. (see [below for nested schema](#nestedblock--irsa))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_azure_cloud_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ resource "harness_platform_connector_azure_cloud_provider" "inherit_from_delegat
- `delegate_selectors` (Set of String) Tags to filter delegates for connection.
- `description` (String) Description of the resource.
- `execute_on_delegate` (Boolean) Execute on delegate or not.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `org_id` (String) Unique identifier of the organization.
- `project_id` (String) Unique identifier of the project.
- `tags` (Set of String) Tags to associate with the resource.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ resource "harness_platform_connector_gcp" "test" {
### Optional

- `description` (String) Description of the resource.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `inherit_from_delegate` (Block List) Inherit configuration from delegate. (see [below for nested schema](#nestedblock--inherit_from_delegate))
- `manual` (Block List, Max: 1) Manual credential configuration. (see [below for nested schema](#nestedblock--manual))
- `org_id` (String) Unique identifier of the organization.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "harness_platform_connector_helm" "test" {
- `credentials` (Block List, Max: 1) Credentials to use for authentication. (see [below for nested schema](#nestedblock--credentials))
- `delegate_selectors` (Set of String) Tags to filter delegates for connection.
- `description` (String) Description of the resource.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `org_id` (String) Unique identifier of the organization.
- `project_id` (String) Unique identifier of the project.
- `tags` (Set of String) Tags to associate with the resource.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ resource "harness_platform_connector_kubernetes" "inheritFromDelegate" {
- `client_key_cert` (Block List, Max: 1) Client key and certificate config for the connector. (see [below for nested schema](#nestedblock--client_key_cert))
- `delegate_selectors` (Set of String) Selectors to use for the delegate.
- `description` (String) Description of the resource.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `inherit_from_delegate` (Block List, Max: 1) Credentials are inherited from the delegate. (see [below for nested schema](#nestedblock--inherit_from_delegate))
- `openid_connect` (Block List, Max: 1) OpenID configuration for the connector. (see [below for nested schema](#nestedblock--openid_connect))
- `org_id` (String) Unique identifier of the organization.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_oci_helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "harness_platform_connector_oci_helm" "test" {
- `credentials` (Block List, Max: 1) Credentials to use for authentication. (see [below for nested schema](#nestedblock--credentials))
- `delegate_selectors` (Set of String) Tags to filter delegates for connection.
- `description` (String) Description of the resource.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `org_id` (String) Unique identifier of the organization.
- `project_id` (String) Unique identifier of the project.
- `tags` (Set of String) Tags to associate with the resource.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/platform_connector_rancher.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ resource "harness_platform_connector_kubernetes" "bearer_token" {
- `bearer_token` (Block List, Max: 1) Bearer token information for the rancher cluster. (see [below for nested schema](#nestedblock--bearer_token))
- `delegate_selectors` (Set of String) Selectors to use for the delegate.
- `description` (String) Description of the resource.
- `force_delete` (Boolean) Enable this flag for force deletion of connector
- `org_id` (String) Unique identifier of the organization.
- `project_id` (String) Unique identifier of the project.
- `tags` (Set of String) Tags to associate with the resource.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.46.4
github.com/docker/docker v24.0.5+incompatible
github.com/harness/harness-go-sdk v0.3.58
github.com/harness/harness-go-sdk v0.3.59
github.com/harness/harness-openapi-go-client v0.0.19
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/harness/harness-go-sdk v0.3.58 h1:urTdoLM3zmsC8o7TgoZ47aU2rlSpRhO/mW+qDalRKe4=
github.com/harness/harness-go-sdk v0.3.58/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-go-sdk v0.3.59 h1:l2aDHzLiWdHy48onBE5iZeclEYMPtHhlsz8iAtgreBg=
github.com/harness/harness-go-sdk v0.3.59/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-openapi-go-client v0.0.19 h1:8XuZvSPZrNqKRLh7Qksdz78WvRMRzRf88LgzxoT5u7k=
github.com/harness/harness-openapi-go-client v0.0.19/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
8 changes: 8 additions & 0 deletions helpers/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ func BuildFieldForBoolean(d *schema.ResourceData, field string) optional.Bool {
return optional.EmptyBool()
}

func BuildFieldBool(d *schema.ResourceData, field string) optional.Bool {
if b, ok := d.GetOk(field); ok {
return optional.NewBool(b.(bool))
}

return optional.EmptyBool()
}

// PipelineResourceImporter defines the importer configuration for all pipeline level resources.
var PipelineResourceImporter = &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand Down
6 changes: 6 additions & 0 deletions internal/service/platform/connector/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func ResourceConnectorAws() *schema.Resource {
},
},
},
"force_delete": {
Description: "Enable this flag for force deletion of connector",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}

Expand Down
50 changes: 50 additions & 0 deletions internal/service/platform/connector/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ func TestAccResourceConnectorAws_Manual_Full_Jitter(t *testing.T) {
})
}

func TestAccResourceConnectorAws_ForceDelete(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
name := id
resourceName := "harness_platform_connector_aws.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceConnectorAws_force_delete(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "inherit_from_delegate.0.delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "force_delete", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_delete"},
},
},
})
}

func testAccResourceConnectorAws_inherit(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_aws" "test" {
Expand Down Expand Up @@ -394,3 +427,20 @@ func testAccResourceConnectorAws_manual_fixed_delay(id string, name string) stri
}
`, id, name)
}

func testAccResourceConnectorAws_force_delete(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_aws" "test" {
identifier = "%[1]s"
name = "%[2]s"
description = "test"
tags = ["foo:bar"]
inherit_from_delegate {
delegate_selectors = ["harness-delegate"]
}
force_delete = true
}
`, id, name)
}
6 changes: 6 additions & 0 deletions internal/service/platform/connector/azure_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func ResourceConnectorAzureCloudProvider() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"force_delete": {
Description: "Enable this flag for force deletion of connector",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}

Expand Down
68 changes: 68 additions & 0 deletions internal/service/platform/connector/azure_cloud_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,50 @@ func TestAccResourceConnectorAzure_ManualDetails_Secret(t *testing.T) {
})
}

func TestAccResourceConnectorAzure_ForceDelete(t *testing.T) {

id := fmt.Sprintf("ConnectorAzure_ForceDelete"+"_%s", utils.RandStringBytes(5))
name := id
updatedName := fmt.Sprintf("%s_updated", name)
resourceName := "harness_platform_connector_azure_cloud_provider.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceConnectorAzure_force_delete(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "force_delete", "true"),
),
},
{
Config: testAccResourceConnectorAzure_inheritFromDelegate_sa(id, updatedName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "force_delete", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_delete"},
},
},
})
}

func testAccResourceConnectorAzure_manualDetails_secret(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_secret_text" "test" {
Expand Down Expand Up @@ -299,3 +343,27 @@ func testAccResourceConnectorAzure_inheritFromDelegate_sa(id string, name string
}
`, id, name)
}

func testAccResourceConnectorAzure_force_delete(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_azure_cloud_provider" "test" {
identifier = "%[1]s"
name = "%[2]s"
description = "test"
tags = ["foo:bar"]
credentials {
type = "InheritFromDelegate"
azure_inherit_from_delegate_details {
auth {
type = "SystemAssignedManagedIdentity"
}
}
}
azure_environment_type = "AZURE"
delegate_selectors = ["harness-delegate"]
force_delete = true
}
`, id, name)
}
3 changes: 2 additions & 1 deletion internal/service/platform/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func resourceConnectorDelete(ctx context.Context, d *schema.ResourceData, meta i

_, httpResp, err := c.ConnectorsApi.DeleteConnector(ctx, c.AccountId, d.Id(), &nextgen.ConnectorsApiDeleteConnectorOpts{
OrgIdentifier: helpers.BuildField(d, "org_id"),
ProjectIdentifier: helpers.BuildField(d, "project_id")})
ProjectIdentifier: helpers.BuildField(d, "project_id"),
ForceDelete: helpers.BuildFieldBool(d, "force_delete")})

if err != nil {
return helpers.HandleApiError(err, d, httpResp)
Expand Down
6 changes: 6 additions & 0 deletions internal/service/platform/connector/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func ResourceConnectorGcp() *schema.Resource {
},
},
},
"force_delete": {
Description: "Enable this flag for force deletion of connector",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}

Expand Down
50 changes: 50 additions & 0 deletions internal/service/platform/connector/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ func TestAccResourceConnectorGcp_Manual(t *testing.T) {
})
}

func TestAccResourceConnectorGcp_ForceDelete(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
name := id
resourceName := "harness_platform_connector_gcp.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceConnectorGcp_force_delete(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "identifier", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "inherit_from_delegate.0.delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "force_delete", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_delete"},
},
},
})
}

func testAccResourceConnectorGcp_inherit(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_gcp" "test" {
Expand Down Expand Up @@ -121,3 +154,20 @@ func testAccResourceConnectorGcp_manual(id string, name string) string {
}
`, id, name)
}

func testAccResourceConnectorGcp_force_delete(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_gcp" "test" {
identifier = "%[1]s"
name = "%[2]s"
description = "test"
tags = ["foo:bar"]
inherit_from_delegate {
delegate_selectors = ["harness-delegate"]
}
force_delete = true
}
`, id, name)
}
6 changes: 6 additions & 0 deletions internal/service/platform/connector/http_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func ResourceConnectorHelm() *schema.Resource {
},
},
},
"force_delete": {
Description: "Enable this flag for force deletion of connector",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}

Expand Down
Loading

0 comments on commit a0d5e27

Please sign in to comment.