Skip to content

Commit

Permalink
Allow resource extension's endpoint_url to be imported as null
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed Jun 11, 2024
1 parent a90d94f commit 5acd5ee
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 6 deletions.
26 changes: 26 additions & 0 deletions pagerdutyplugin/import_pagerduty_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,29 @@ func TestAccPagerDutyExtension_import(t *testing.T) {
},
})
}

func TestAccPagerDutyExtension_import_WithoutEndpointURL(t *testing.T) {
extension_name := fmt.Sprintf("tf-%s", acctest.RandString(5))
name := fmt.Sprintf("tf-%s", acctest.RandString(5))
url := "https://example.com/receive_a_pagerduty_webhook"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(),
CheckDestroy: testAccCheckPagerDutyExtensionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyExtensionConfig(name, extension_name, url, "false", "any"),
},
{
Config: testAccCheckPagerDutyExtensionConfig_NoEndpointURL(name, extension_name, "false", "any"),
},
{
ResourceName: "pagerduty_extension.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"config"},
},
},
})
}
37 changes: 31 additions & 6 deletions pagerdutyplugin/resource_pagerduty_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,36 @@ func (r *resourceExtension) Metadata(_ context.Context, _ resource.MetadataReque
func (r *resourceExtension) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{Optional: true, Computed: true},
"id": schema.StringAttribute{Computed: true},
"html_url": schema.StringAttribute{Computed: true},
"type": schema.StringAttribute{Optional: true, Computed: true},
"endpoint_url": schema.StringAttribute{Optional: true, Sensitive: true},
"summary": schema.StringAttribute{Computed: true},
"name": schema.StringAttribute{Optional: true, Computed: true},
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"html_url": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"type": schema.StringAttribute{
Optional: true, Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"endpoint_url": schema.StringAttribute{
Optional: true,
Computed: true,
Sensitive: true,
},
"summary": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"extension_objects": schema.SetAttribute{
Required: true,
ElementType: types.StringType,
Expand Down Expand Up @@ -317,6 +341,7 @@ func flattenExtension(response *pagerduty.Extension, accessToken *string, diags
ID: types.StringValue(response.ID),
Name: types.StringValue(response.Name),
HTMLURL: types.StringValue(response.HTMLURL),
Type: types.StringValue(response.Type),
Summary: types.StringValue(response.Summary),
EndpointURL: types.StringValue(response.EndpointURL),
Config: flattenExtensionConfig(response.Config, accessToken, diags),
Expand Down
62 changes: 62 additions & 0 deletions pagerdutyplugin/resource_pagerduty_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,65 @@ EOF
`, name, extension_name, url, restrict, notify_types)
}

func testAccCheckPagerDutyExtensionConfig_NoEndpointURL(name, extension_name, notify_types, restrict string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
name = "%[1]v"
email = "%[1]v@foo.test"
color = "green"
role = "user"
job_title = "foo"
description = "foo"
}
resource "pagerduty_escalation_policy" "foo" {
name = "%[1]v"
description = "bar"
num_loops = 2
rule {
escalation_delay_in_minutes = 10
target {
type = "user_reference"
id = pagerduty_user.foo.id
}
}
}
resource "pagerduty_service" "foo" {
name = "%[1]v"
description = "foo"
auto_resolve_timeout = 1800
acknowledgement_timeout = 1800
escalation_policy = pagerduty_escalation_policy.foo.id
incident_urgency_rule {
type = "constant"
urgency = "high"
}
}
data "pagerduty_extension_schema" "foo" {
name = "Generic V2 Webhook"
}
resource "pagerduty_extension" "foo"{
name = "%s"
endpoint_url = null # sensitive
extension_schema = data.pagerduty_extension_schema.foo.id
extension_objects = [pagerduty_service.foo.id]
config = <<EOF
{
"restrict": "%v",
"notify_types": {
"resolve": %[4]v,
"acknowledge": %[4]v,
"assignments": %[4]v
}
}
EOF
}
`, name, extension_name, restrict, notify_types)
}

0 comments on commit 5acd5ee

Please sign in to comment.