Skip to content

Commit

Permalink
Merge branch 'main' into CDS-57560
Browse files Browse the repository at this point in the history
  • Loading branch information
RishabhGupta34 committed May 5, 2023
2 parents e1f7ecd + 71ba35a commit 1ed6a64
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .changelog/522.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/platform_manual_freeze - Added quarterly recurrence support for manual deployment freeze resource in Harness terraform provider
```
17 changes: 9 additions & 8 deletions docs/data-sources/platform_manual_freeze.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,35 @@ data "harness_platform_manual_freeze" "example" {

Read-Only:

- `end_time` (Number)
- `start_time` (Number)
- `end_time` (Number) End time of the freeze
- `start_time` (Number) Start time of the freeze


<a id="nestedatt--freeze_windows"></a>
### Nested Schema for `freeze_windows`

Read-Only:

- `duration` (String)
- `end_time` (String)
- `duration` (String) Duration of the freeze
- `end_time` (String) End time of the freeze
- `recurrence` (List of Object) (see [below for nested schema](#nestedobjatt--freeze_windows--recurrence))
- `start_time` (String)
- `time_zone` (String)
- `start_time` (String) Start time of the freeze
- `time_zone` (String) Timezone

<a id="nestedobjatt--freeze_windows--recurrence"></a>
### Nested Schema for `freeze_windows.recurrence`

Read-Only:

- `recurrence_spec` (List of Object) (see [below for nested schema](#nestedobjatt--freeze_windows--recurrence--recurrence_spec))
- `type` (String)
- `type` (String) Recurrence type(Daily, Weekly, Monthly, Yearly)

<a id="nestedobjatt--freeze_windows--recurrence--recurrence_spec"></a>
### Nested Schema for `freeze_windows.recurrence.recurrence_spec`

Read-Only:

- `until` (String)
- `until` (String) Recurrence until timestamp
- `value` (Number) Value of n, for n months recurrence


17 changes: 9 additions & 8 deletions docs/resources/platform_manual_freeze.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,36 @@ resource "harness_platform_manual_freeze" "example" {

Read-Only:

- `end_time` (Number)
- `start_time` (Number)
- `end_time` (Number) End time of the freeze
- `start_time` (Number) Start time of the freeze


<a id="nestedatt--freeze_windows"></a>
### Nested Schema for `freeze_windows`

Read-Only:

- `duration` (String)
- `end_time` (String)
- `duration` (String) Duration of the freeze
- `end_time` (String) End time of the freeze
- `recurrence` (List of Object) (see [below for nested schema](#nestedobjatt--freeze_windows--recurrence))
- `start_time` (String)
- `time_zone` (String)
- `start_time` (String) Start time of the freeze
- `time_zone` (String) Timezone

<a id="nestedobjatt--freeze_windows--recurrence"></a>
### Nested Schema for `freeze_windows.recurrence`

Read-Only:

- `recurrence_spec` (List of Object) (see [below for nested schema](#nestedobjatt--freeze_windows--recurrence--recurrence_spec))
- `type` (String)
- `type` (String) Recurrence type(Daily, Weekly, Monthly, Yearly)

<a id="nestedobjatt--freeze_windows--recurrence--recurrence_spec"></a>
### Nested Schema for `freeze_windows.recurrence.recurrence_spec`

Read-Only:

- `until` (String)
- `until` (String) Recurrence until timestamp
- `value` (Number) Value of n, for n months recurrence

## Import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func DataSourceManualFreeze() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"value": {
Description: "Every n months recurrence",
Type: schema.TypeInt,
Computed: true,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ func TestAccDataSourceResourceGroup(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.type", "Daily"),
),
},
{
Config: testAccDataSourceManualFreezeQuarterly(name, accountId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", name),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "account_id", accountId),
resource.TestCheckResourceAttr(resourceName, "scope", "project"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.type", "Monthly"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.value", "3"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.until", "2023-12-31 11:59 PM"),
),
},
},
})
}
Expand Down Expand Up @@ -77,7 +89,72 @@ func testAccDataSourceManualFreeze(name string, accountId string) string {
recurrence:
type: Daily
notificationRules: []
orgIdentifier: %[1]s
projectIdentifier: %[1]s
tags: {}
EOT
}
data "harness_platform_manual_freeze" "test" {
identifier = harness_platform_manual_freeze.test.identifier
account_id = harness_platform_manual_freeze.test.account_id
org_id = harness_platform_manual_freeze.test.org_id
project_id = harness_platform_manual_freeze.test.project_id
}
`, name, accountId)
}

func testAccDataSourceManualFreezeQuarterly(name string, accountId string) string {
return fmt.Sprintf(`
resource "harness_platform_organization" "test" {
identifier = "%[1]s"
name = "%[1]s"
}
resource "harness_platform_project" "test" {
identifier = "%[1]s"
name = "%[1]s"
color = "#0063F7"
org_id = harness_platform_organization.test.identifier
}
resource "harness_platform_manual_freeze" "test" {
identifier = "%[1]s"
account_id = "%[2]s"
org_id = harness_platform_project.test.org_id
project_id = harness_platform_project.test.id
yaml = <<-EOT
freeze:
name: %[1]s
identifier: %[1]s
entityConfigs:
- name: r1
entities:
- filterType: All
type: Org
- filterType: All
type: Project
- filterType: All
type: Service
- filterType: All
type: EnvType
status: Disabled
description: hi
windows:
- timeZone: Asia/Calcutta
startTime: 2023-05-03 04:16 PM
duration: 30m
recurrence:
type: Monthly
spec:
value: 3
until: 2023-12-31 11:59 PM
notificationRules: []
orgIdentifier: %[1]s
projectIdentifier: %[1]s
tags: {}
EOT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func ResourceManualFreeze() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"value": {
Description: "Every n months recurrence",
Type: schema.TypeInt,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -298,6 +303,7 @@ func expandRecurrenceSpec(recurrence nextgen.Recurrence) []interface{} {
var result []interface{}
if recurrence.Spec != nil {
result = append(result, map[string]interface{}{
"value": recurrence.Spec.Value,
"until": recurrence.Spec.Until,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,52 @@ func TestAccResourceManualFreezeWithRecurrence(t *testing.T) {
},
},
})
}

func TestAccResourceManualFreezeWithQuarterlyRecurrence(t *testing.T) {
name := t.Name()
id := fmt.Sprintf("%s_%s", name, utils.RandStringBytes(5))
updatedName := fmt.Sprintf("%s_updated", name)
resourceName := "harness_platform_manual_freeze.test"
accountId := os.Getenv("HARNESS_ACCOUNT_ID")

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccResourceGroupDestroy(resourceName),
Steps: []resource.TestStep{
{
Config: testAccResourceManualFreezeQuarterly(id, name, accountId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "account_id", accountId),
resource.TestCheckResourceAttr(resourceName, "scope", "project"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.type", "Monthly"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.value", "3"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.until", "2023-12-31 11:59 PM"),
),
},
{
Config: testAccResourceManualFreezeQuarterly(id, updatedName, accountId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
resource.TestCheckResourceAttr(resourceName, "account_id", accountId),
resource.TestCheckResourceAttr(resourceName, "scope", "project"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.type", "Monthly"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.value", "3"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.until", "2023-12-31 11:59 PM"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: acctest.ProjectResourceImportStateIdFunc(resourceName),
},
},
})
}

func TestAccResourceManualFreeze_WithoutRecurrence(t *testing.T) {
Expand Down Expand Up @@ -135,6 +180,46 @@ func TestAccResourceManualFreeze_DeleteUnderlyingResource(t *testing.T) {
})
}

func TestAccResourceQuarterlyManualFreeze_DeleteUnderlyingResource(t *testing.T) {
id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5))
name := id
resourceName := "harness_platform_manual_freeze.test"
accountId := os.Getenv("HARNESS_ACCOUNT_ID")

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceManualFreezeQuarterly(id, name, accountId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", id),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "account_id", accountId),
resource.TestCheckResourceAttr(resourceName, "scope", "project"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.type", "Monthly"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.value", "3"),
resource.TestCheckResourceAttr(resourceName, "freeze_windows.0.recurrence.0.recurrence_spec.0.until", "2023-12-31 11:59 PM"),
),
},
{
PreConfig: func() {
acctest.TestAccConfigureProvider()
c, ctx := acctest.TestAccGetPlatformClientWithContext()
_, err := c.FreezeCRUDApi.DeleteFreeze(ctx, c.AccountId, id, &nextgen.FreezeCRUDApiDeleteFreezeOpts{
OrgIdentifier: optional.NewString(id),
ProjectIdentifier: optional.NewString(id),
})
require.NoError(t, err)
},
Config: testAccResourceManualFreeze(id, name, accountId),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccResourceGroupDestroy(resourceName string) resource.TestCheckFunc {
return func(state *terraform.State) error {
manualFreeze, _ := testAccGetManualFreeze(resourceName, state)
Expand Down Expand Up @@ -222,7 +307,7 @@ func testAccResourceManualFreeze(id string, name string, accountId string) strin
`, id, name, accountId)
}

func testAccResourceManualFreezeWithoutRecurrence(id string, name string, accountId string) string {
func testAccResourceManualFreezeQuarterly(id string, name string, accountId string) string {
return fmt.Sprintf(`
resource "harness_platform_organization" "test" {
identifier = "%[1]s"
Expand Down Expand Up @@ -262,6 +347,58 @@ func testAccResourceManualFreezeWithoutRecurrence(id string, name string, accoun
- timeZone: Asia/Calcutta
startTime: 2023-05-03 04:16 PM
duration: 30m
recurrence:
type: Monthly
spec:
value: 3
until: 2023-12-31 11:59 PM
notificationRules: []
tags: {}
EOT
}
`, id, name, accountId)
}

func testAccResourceManualFreezeWithoutRecurrence(id string, name string, accountId string) string {
return fmt.Sprintf(`
resource "harness_platform_organization" "test" {
identifier = "%[1]s"
name = "%[2]s"
}
resource "harness_platform_project" "test" {
identifier = "%[1]s"
name = "%[2]s"
color = "#0063F7"
org_id = harness_platform_organization.test.identifier
}
resource "harness_platform_manual_freeze" "test" {
identifier = "%[1]s"
account_id = "%[3]s"
org_id = harness_platform_project.test.org_id
project_id = harness_platform_project.test.id
yaml = <<-EOT
freeze:
name: %[2]s
identifier: %[1]s
entityConfigs:
- name: r1
entities:
- filterType: All
type: Org
- filterType: All
type: Project
- filterType: All
type: Service
- filterType: All
type: EnvType
status: Disabled
description: hi
windows:
- timeZone: Asia/Calcutta
startTime: 2025-05-07 04:16 PM
duration: 30m
notificationRules: []
tags: {}
EOT
Expand Down

0 comments on commit 1ed6a64

Please sign in to comment.