diff --git a/pagerdutyplugin/import_pagerduty_extension_test.go b/pagerdutyplugin/import_pagerduty_extension_test.go index 52095a1f9..218a503fb 100644 --- a/pagerdutyplugin/import_pagerduty_extension_test.go +++ b/pagerdutyplugin/import_pagerduty_extension_test.go @@ -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"}, + }, + }, + }) +} diff --git a/pagerdutyplugin/resource_pagerduty_extension.go b/pagerdutyplugin/resource_pagerduty_extension.go index 476653e0f..071e6f821 100644 --- a/pagerdutyplugin/resource_pagerduty_extension.go +++ b/pagerdutyplugin/resource_pagerduty_extension.go @@ -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, @@ -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), diff --git a/pagerdutyplugin/resource_pagerduty_extension_test.go b/pagerdutyplugin/resource_pagerduty_extension_test.go index c63934d5d..cbd132ed0 100644 --- a/pagerdutyplugin/resource_pagerduty_extension_test.go +++ b/pagerdutyplugin/resource_pagerduty_extension_test.go @@ -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 = <