-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Jira Cloud integration
Add data source for Jira Cloud account mapping Add resource for Jira Cloud account mapping rule Update dependency to PagerDuty/go-pagerduty module Fix Document PAGERDUTY_ACC_JIRA_ACCOUNT_MAPPING_ID Fix Jira Cloud accounts mapping Update in vendor/
- Loading branch information
Showing
14 changed files
with
1,779 additions
and
4 deletions.
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
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
95 changes: 95 additions & 0 deletions
95
pagerdutyplugin/data_source_pagerduty_jira_cloud_account_mapping.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,95 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/PagerDuty/go-pagerduty" | ||
"github.com/PagerDuty/terraform-provider-pagerduty/util" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
) | ||
|
||
type dataSourceJiraCloudAccountMapping struct{ client *pagerduty.Client } | ||
|
||
var _ datasource.DataSourceWithConfigure = (*dataSourceJiraCloudAccountMapping)(nil) | ||
|
||
func (*dataSourceJiraCloudAccountMapping) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = "pagerduty_jira_cloud_account_mapping" | ||
} | ||
|
||
func (*dataSourceJiraCloudAccountMapping) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{Computed: true}, | ||
"base_url": schema.StringAttribute{Computed: true}, | ||
"subdomain": schema.StringAttribute{Required: true}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *dataSourceJiraCloudAccountMapping) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...) | ||
} | ||
|
||
func (d *dataSourceJiraCloudAccountMapping) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
log.Println("[INFO] Reading PagerDuty jira cloud account mapping") | ||
|
||
var searchSubdomain types.String | ||
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("subdomain"), &searchSubdomain)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
var found *pagerduty.JiraCloudAccountsMapping | ||
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError { | ||
response, err := d.client.ListJiraCloudAccountsMappings(ctx, pagerduty.ListJiraCloudAccountsMappingsOptions{}) | ||
if err != nil { | ||
if util.IsBadRequestError(err) { | ||
return retry.NonRetryableError(err) | ||
} | ||
return retry.RetryableError(err) | ||
} | ||
|
||
for _, m := range response.AccountsMappings { | ||
if m.PagerDutyAccount.Subdomain == searchSubdomain.ValueString() { | ||
found = &m | ||
break | ||
} | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
fmt.Sprintf("Error reading PagerDuty jira cloud account mapping with subdomain %s", searchSubdomain), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
if found == nil { | ||
resp.Diagnostics.AddError( | ||
fmt.Sprintf("Unable to locate any jira cloud account mapping with the subdomain %s", searchSubdomain), | ||
"", | ||
) | ||
return | ||
} | ||
|
||
model := dataSourceJiraCloudAccountMappingModel{ | ||
ID: types.StringValue(found.ID), | ||
BaseURL: types.StringValue(found.JiraCloudAccount.BaseURL), | ||
Subdomain: types.StringValue(found.PagerDutyAccount.Subdomain), | ||
} | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...) | ||
} | ||
|
||
type dataSourceJiraCloudAccountMappingModel struct { | ||
ID types.String `tfsdk:"id"` | ||
BaseURL types.String `tfsdk:"base_url"` | ||
Subdomain types.String `tfsdk:"subdomain"` | ||
} |
40 changes: 40 additions & 0 deletions
40
pagerdutyplugin/data_source_pagerduty_jira_cloud_account_mapping_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,40 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccDataSourcePagerDutyJiraCloudAccountMapping_Basic(t *testing.T) { | ||
subdomain := os.Getenv("PAGERDUTY_SUBDOMAIN") | ||
if subdomain == "" { | ||
t.Skip("Missing env variable PAGERDUTY_SUBDOMAIN") | ||
return | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePagerDutyJiraCloudAccountMappingConfig(subdomain), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.pagerduty_jira_cloud_account_mapping.by_subdomain", "subdomain", subdomain), | ||
resource.TestCheckResourceAttrSet("data.pagerduty_jira_cloud_account_mapping.by_subdomain", "id"), | ||
resource.TestCheckResourceAttrSet("data.pagerduty_jira_cloud_account_mapping.by_subdomain", "base_url"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourcePagerDutyJiraCloudAccountMappingConfig(subdomain string) string { | ||
return fmt.Sprintf(` | ||
data "pagerduty_jira_cloud_account_mapping" "by_subdomain" { | ||
subdomain = "%s" | ||
} | ||
`, subdomain) | ||
} |
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
Oops, something went wrong.