-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,890 additions
and
24 deletions.
There are no files selected for viewing
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.