-
Notifications
You must be signed in to change notification settings - Fork 212
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
[ORCA-4601] Add support for Event Orchestration Cache Variables #822
Merged
imjaroiswebdev
merged 9 commits into
PagerDuty:master
from
c-kaieong:ORCA-4601-add-support-for-cache-variables
Apr 3, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5a52e41
Add support for Cache Variables
c-kaieong 715a6d1
Address PR comments
c-kaieong 1548a81
Add documentation for Cache Variables
c-kaieong 246a50c
Change some reference syntax
c-kaieong 5398ecb
Update KB links
c-kaieong ca69c98
Rebase and point to dev branch again
c-kaieong 0527854
Update to newer GO client version
c-kaieong 24b7ea3
Remove unneeded sleep calls and rename orch/service resources
c-kaieong 1727dfc
Update go client dependency
c-kaieong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pagerduty/data_source_pagerduty_event_orchestration_global_cache_variable.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/heimweh/go-pagerduty/pagerduty" | ||
) | ||
|
||
func dataSourcePagerDutyEventOrchestrationGlobalCacheVariable() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourcePagerDutyEventOrchestrationGlobalCacheVariableRead, | ||
Schema: map[string]*schema.Schema{ | ||
"event_orchestration": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"condition": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: dataSourceEventOrchestrationCacheVariableConditionSchema, | ||
}, | ||
}, | ||
"configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: dataSourceEventOrchestrationCacheVariableConfigurationSchema, | ||
}, | ||
}, | ||
"disabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePagerDutyEventOrchestrationGlobalCacheVariableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return dataSourceEventOrchestrationCacheVariableRead(ctx, d, meta, pagerduty.CacheVariableTypeGlobal) | ||
} |
272 changes: 272 additions & 0 deletions
272
pagerduty/data_source_pagerduty_event_orchestration_global_cache_variable_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
func TestAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariable_Basic(t *testing.T) { | ||
on := fmt.Sprintf("tf-orchestration-%s", acctest.RandString(5)) | ||
name := fmt.Sprintf("tf_global_cache_variable_%s", acctest.RandString(5)) | ||
irn := "pagerduty_event_orchestration_global_cache_variable.orch_cv" | ||
n := "data.pagerduty_event_orchestration_global_cache_variable.by_id" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
// find by id | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByIdConfig(on, name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariable(irn, n), | ||
), | ||
}, | ||
// find by id, ignore name | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByIdNameConfig(on, name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariable(irn, n), | ||
), | ||
}, | ||
// find by name | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByNameConfig(on, name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariable(irn, n), | ||
), | ||
}, | ||
// id and name are both not set | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableIdNameNullConfig(on, name), | ||
ExpectError: regexp.MustCompile("Invalid Event Orchestration Cache Variable data source configuration: ID and name cannot both be null"), | ||
}, | ||
// bad event_orchestration | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadOrchConfig(on, name), | ||
ExpectError: regexp.MustCompile("Unable to find a Cache Variable with ID '(.+)' on PagerDuty Event Orchestration 'bad-orchestration-id'"), | ||
}, | ||
// bad id | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadIdConfig(on, name), | ||
ExpectError: regexp.MustCompile("Unable to find a Cache Variable with ID 'bad-cache-var-id' on PagerDuty Event Orchestration '(.+)'"), | ||
}, | ||
// bad name | ||
{ | ||
Config: testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadNameConfig(on, name), | ||
ExpectError: regexp.MustCompile("Unable to find a Cache Variable on Event Orchestration '(.+)' with name 'bad-cache-var-name'"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariable(src, n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
|
||
srcR := s.RootModule().Resources[src] | ||
srcA := srcR.Primary.Attributes | ||
|
||
r := s.RootModule().Resources[n] | ||
a := r.Primary.Attributes | ||
|
||
if a["id"] == "" { | ||
return fmt.Errorf("Expected the Event Orchestration Cache Variable ID to be set") | ||
} | ||
|
||
testAtts := []string{ | ||
"id", "name", "configuration.0.type", "configuration.0.ttl_seconds", | ||
} | ||
|
||
for _, att := range testAtts { | ||
if a[att] != srcA[att] { | ||
return fmt.Errorf("Expected the Event Orchestration Cache Variable %s to be: %s, but got: %s", att, srcA[att], a[att]) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBaseConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByIdConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
id = pagerduty_event_orchestration_global_cache_variable.orch_cv.id | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByIdNameConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
id = pagerduty_event_orchestration_global_cache_variable.orch_cv.id | ||
name = "No such name" | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableByNameConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%[1]s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%[2]s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%[2]s" | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableIdNameNullConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadOrchConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = "bad-orchestration-id" | ||
id = pagerduty_event_orchestration_global_cache_variable.orch_cv.id | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadIdConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
id = "bad-cache-var-id" | ||
} | ||
`, on, name) | ||
} | ||
|
||
func testAccDataSourcePagerDutyEventOrchestrationGlobalCacheVariableBadNameConfig(on, name string) string { | ||
return fmt.Sprintf(` | ||
resource "pagerduty_event_orchestration" "orch" { | ||
name = "%s" | ||
} | ||
|
||
resource "pagerduty_event_orchestration_global_cache_variable" "orch_cv" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "%s" | ||
|
||
configuration { | ||
type = "trigger_event_count" | ||
ttl_seconds = 60 | ||
} | ||
} | ||
|
||
data "pagerduty_event_orchestration_global_cache_variable" "by_id" { | ||
event_orchestration = pagerduty_event_orchestration.orch.id | ||
name = "bad-cache-var-name" | ||
} | ||
`, on, name) | ||
} |
51 changes: 51 additions & 0 deletions
51
pagerduty/data_source_pagerduty_event_orchestration_service_cache_variable.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/heimweh/go-pagerduty/pagerduty" | ||
) | ||
|
||
func dataSourcePagerDutyEventOrchestrationServiceCacheVariable() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourcePagerDutyEventOrchestrationServiceCacheVariableRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"condition": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: dataSourceEventOrchestrationCacheVariableConditionSchema, | ||
}, | ||
}, | ||
"configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: dataSourceEventOrchestrationCacheVariableConfigurationSchema, | ||
}, | ||
}, | ||
"disabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePagerDutyEventOrchestrationServiceCacheVariableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return dataSourceEventOrchestrationCacheVariableRead(ctx, d, meta, pagerduty.CacheVariableTypeService) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think before sending this PR for review to José we'll need to point this branch to your branch of the API Client, so the checks can pass and the acceptance tests are passing locally. At least that's what we used to do in previous EO PRs, then after both PRs are reviewed/approved we'd merge the API Client and point this branch to the new version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@c-kaieong not sure if the provider or internal docs have the instructions but this command should do it:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The internal docs show how to point to a local directory, but not a branch. I'll add that in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/PagerDuty/terraform-provider-pagerduty-internal/pull/8