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

feat: [PL-58650]: Terraform Changes for Add support for configuring recovery duration in AWS Secrets Manager Connector for secret deletion flow #1140

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/data-sources/platform_connector_aws_secret_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data "harness_platform_connector_aws_secret_manager" "example" {
- `secret_name_prefix` (String) A prefix to be added to all secrets.
- `tags` (Set of String) Tags to associate with the resource.
- `use_put_secret` (Boolean) Whether to update secret value using putSecretValue action.
- `force_delete_without_recovery` (Boolean) Whether to force delete secret value or not.
- `recovery_window_in_days` (Long) recovery duration in days in AWS Secrets Manager.

<a id="nestedatt--credentials"></a>
### Nested Schema for `credentials`
Expand Down
45 changes: 45 additions & 0 deletions docs/resources/platform_connector_aws_secret_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,49 @@ resource "harness_platform_connector_aws_secret_manager" "test" {
}
}
}
# Force delete true
resource "harness_platform_connector_aws_secret_manager" "test" {
identifier = "identifier"
name = "name"
description = "test"
tags = ["foo:bar"]
default = true
secret_name_prefix = "test"
region = "us-east-1"
delegate_selectors = ["harness-delegate"]
force_delete_without_recovery = true
credentials {
assume_role {
role_arn = "somerolearn"
external_id = "externalid"
duration = 900
}
}
}
# With recovery duration of 15 days
resource "harness_platform_connector_aws_secret_manager" "test" {
identifier = "identifier"
name = "name"
description = "test"
tags = ["foo:bar"]
default = true
secret_name_prefix = "test"
region = "us-east-1"
delegate_selectors = ["harness-delegate"]
recovery_window_in_days = 15
credentials {
assume_role {
role_arn = "somerolearn"
external_id = "externalid"
duration = 900
}
}
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -97,6 +140,8 @@ resource "harness_platform_connector_aws_secret_manager" "test" {
- `tags` (Set of String) Tags to associate with the resource.
- `default` (Boolean) Use as Default Secrets Manager.
- `use_put_secret` (Boolean) Whether to update secret value using putSecretValue action.
- `force_delete_without_recovery` (Boolean) Whether to force delete secret value or not.
- `recovery_window_in_days` (Long) recovery duration in days in AWS Secrets Manager.

### Read-Only

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,46 @@ resource "harness_platform_connector_aws_secret_manager" "test" {
}
}
}


# Force delete true
resource "harness_platform_connector_aws_secret_manager" "test" {
identifier = "identifier"
name = "name"
description = "test"
tags = ["foo:bar"]

secret_name_prefix = "test"
region = "us-east-1"
delegate_selectors = ["harness-delegate"]
default = true
force_delete_without_recovery = true
credentials {
assume_role {
role_arn = "somerolearn"
external_id = "externalid"
duration = 900
}
}
}

# With recovery duration of 15 days
resource "harness_platform_connector_aws_secret_manager" "test" {
identifier = "identifier"
name = "name"
description = "test"
tags = ["foo:bar"]

secret_name_prefix = "test"
region = "us-east-1"
delegate_selectors = ["harness-delegate"]
default = true
recovery_window_in_days = 15
credentials {
assume_role {
role_arn = "somerolearn"
external_id = "externalid"
duration = 900
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func ResourceConnectorAwsSM() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"force_delete_without_recovery": {
Description: "Whether to force delete secret value or not.",
Type: schema.TypeBool,
Optional: true,
},
"recovery_window_in_days": {
Description: "Recovery duration in days in AWS Secrets Manager.",
Type: schema.TypeInt,
Optional: true,
},
"credentials": {
Description: "Credentials to connect to AWS.",
Type: schema.TypeList,
Expand Down Expand Up @@ -193,6 +203,14 @@ func buildConnectorAwsSM(d *schema.ResourceData) *nextgen.ConnectorInfo {
connector.AwsSecretManager.UsePutSecret = attr.(bool)
}

if attr, ok := d.GetOk("recovery_window_in_days"); ok {
connector.AwsSecretManager.RecoveryWindowInDays = int64(attr.(int))
}

if attr, ok := d.GetOk("force_delete_without_recovery"); ok {
connector.AwsSecretManager.ForceDeleteWithoutRecovery = attr.(bool)
}

if attr, ok := d.GetOk("credentials"); ok {
config := attr.([]interface{})[0].(map[string]interface{})
connector.AwsSecretManager.Credential = &nextgen.AwsSecretManagerCredential{}
Expand Down Expand Up @@ -247,6 +265,9 @@ func readConnectorAwsSM(d *schema.ResourceData, connector *nextgen.ConnectorInfo
d.Set("delegate_selectors", connector.AwsSecretManager.DelegateSelectors)
d.Set("default", connector.AwsSecretManager.Default_)
d.Set("use_put_secret", connector.AwsSecretManager.UsePutSecret)
d.Set("recovery_window_in_days", connector.AwsSecretManager.RecoveryWindowInDays)
d.Set("force_delete_without_recovery", connector.AwsSecretManager.ForceDeleteWithoutRecovery)


switch connector.AwsSecretManager.Credential.Type_ {
case nextgen.AwsSecretManagerAuthTypes.AssumeIAMRole:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ func DatasourceConnectorAwsSM() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"force_delete_without_recovery": {
Description: "Whether to force delete secret value or not.",
Type: schema.TypeBool,
Optional: true,
},
"recovery_window_in_days": {
Description: "Recovery duration in days in AWS Secrets Manager.",
Type: schema.TypeInt,
Optional: true,
},
"delegate_selectors": {
Description: "Tags to filter delegates for connection.",
Type: schema.TypeSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,140 @@ func TestAccResourceConnectorAwsSM_manualWithUsePutSecretFalse(t *testing.T) {
})
}

func TestAccResourceConnectorAwsSM_manualWithForceDeleteWithoutRecovery(t *testing.T) {

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

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: TestAccResourceConnectorAwsSM_manualWithForceDeleteWithoutRecovery(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, "delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"),
resource.TestCheckResourceAttr(resourceName, "use_put_secret", "false"),
resource.TestCheckResourceAttr(resourceName, "force_delete_without_recovery", "true"),
),
},

{
Config: TestAccResourceConnectorAwsSM_manualWithForceDeleteWithoutRecovery(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, "delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"),
resource.TestCheckResourceAttr(resourceName, "use_put_secret", "false"),
resource.TestCheckResourceAttr(resourceName, "force_delete_without_recovery", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccResourceConnectorAwsSM_manualWithForceDeleteWithoutRecovery(id, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_aws_secret_manager" "test" {
id = "%s"
identifier = "%s"
name = "%s"
description = "test"
tags = ["test"]
delegate_selectors = ["test"]
secret_name_prefix = "test"
use_put_secret = "false"
force_delete_without_recovery = true
}
`, id, id, name)
}

func TestAccResourceConnectorAwsSM_manualWithRecoveryWindow(t *testing.T) {

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

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccConnectorDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: TestAccResourceConnectorAwsSM_manualWithRecoveryWindow(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, "delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"),
resource.TestCheckResourceAttr(resourceName, "recovery_window_in_days", "15"),
),
},
{
Config: TestAccResourceConnectorAwsSM_manualWithRecoveryWindow(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, "delegate_selectors.#", "1"),
resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"),
resource.TestCheckResourceAttr(resourceName, "recovery_window_in_days", "15"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccResourceConnectorAwsSM_manualWithRecoveryWindow(id, name string) string {
return fmt.Sprintf(`
resource "harness_platform_connector_aws_secret_manager" "test" {
id = "%s"
identifier = "%s"
name = "%s"
description = "test"
tags = ["test"]
delegate_selectors = ["test"]
secret_name_prefix = "test"
recovery_window_in_days = 15
}
`, id, id, name)
}


func TestProjectResourceConnectorAwsSM_manual(t *testing.T) {

Expand Down