Skip to content

Commit

Permalink
UseStateForUnknown in all computed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed Jan 29, 2025
1 parent a6595bd commit 45850e5
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 109 deletions.
13 changes: 6 additions & 7 deletions pagerdutyplugin/resource_pagerduty_alert_grouping_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@ func (r *resourceAlertGroupingSetting) Schema(_ context.Context, _ resource.Sche
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{
Required: true,
},
"description": schema.StringAttribute{
Computed: true,
Optional: true,
Default: stringdefault.StaticString("Managed by Terraform"),
Computed: true,
Optional: true,
Default: stringdefault.StaticString("Managed by Terraform"),
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"type": schema.StringAttribute{
Required: true,
Expand Down
21 changes: 15 additions & 6 deletions pagerdutyplugin/resource_pagerduty_business_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,30 @@ func (r *resourceBusinessService) Metadata(_ context.Context, _ resource.Metadat
func (r *resourceBusinessService) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"html_url": schema.StringAttribute{Computed: true},
"name": schema.StringAttribute{Required: true},
"point_of_contact": schema.StringAttribute{Optional: true},
"self": schema.StringAttribute{Computed: true},
"summary": schema.StringAttribute{Computed: true},
"team": schema.StringAttribute{Optional: true},
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{Required: true},
"description": schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString("Managed by Terraform"),
},
"html_url": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"point_of_contact": schema.StringAttribute{Optional: true},
"self": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"summary": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"team": schema.StringAttribute{Optional: true},
"type": schema.StringAttribute{
Optional: true,
Computed: true,
Expand Down
62 changes: 28 additions & 34 deletions pagerdutyplugin/resource_pagerduty_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/PagerDuty/go-pagerduty"
"github.com/PagerDuty/terraform-provider-pagerduty/util"
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
Expand All @@ -19,8 +20,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
)

type resourceExtension struct{ client *pagerduty.Client }
Expand All @@ -37,53 +36,48 @@ 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,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"html_url": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"type": schema.StringAttribute{
Optional: true, Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"endpoint_url": schema.StringAttribute{
Optional: true,
Computed: true,
Sensitive: true,
Optional: true,
Computed: true,
Sensitive: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"summary": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"extension_objects": schema.SetAttribute{
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{setplanmodifier.RequiresReplace()},
},
"extension_schema": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"config": schema.StringAttribute{
Optional: true,
Computed: true,
CustomType: jsontypes.NormalizedType{},
Optional: true,
Computed: true,
CustomType: jsontypes.NormalizedType{},
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
},
}
Expand Down
56 changes: 39 additions & 17 deletions pagerdutyplugin/resource_pagerduty_extension_servicenow.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,47 @@ func (r *resourceExtensionServiceNow) Metadata(_ context.Context, _ resource.Met
func (r *resourceExtensionServiceNow) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Computed: true},
"name": schema.StringAttribute{Optional: true, Computed: true},
"html_url": schema.StringAttribute{Computed: true},
"type": schema.StringAttribute{Optional: true, Computed: true},
"endpoint_url": schema.StringAttribute{Optional: true, Sensitive: true},
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{
Optional: true,
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,
Sensitive: true,
},
"extension_objects": schema.SetAttribute{
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
Required: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{setplanmodifier.RequiresReplace()},
},
"extension_schema": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"snow_user": schema.StringAttribute{Required: true},
"snow_password": schema.StringAttribute{
Required: true,
Sensitive: true,
},
"summary": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"snow_user": schema.StringAttribute{Required: true},
"snow_password": schema.StringAttribute{Required: true, Sensitive: true},
"summary": schema.StringAttribute{Optional: true, Computed: true},
"sync_options": schema.StringAttribute{
Required: true,
Validators: []validator.String{
Expand Down Expand Up @@ -293,6 +313,7 @@ func buildPagerdutyExtensionServiceNow(ctx context.Context, model *resourceExten

func buildExtensionServiceNowObjects(ctx context.Context, set types.Set, diags *diag.Diagnostics) []pagerduty.APIObject {
var target []string

diags.Append(set.ElementsAs(ctx, &target, false)...)

list := []pagerduty.APIObject{}
Expand All @@ -313,6 +334,7 @@ func flattenExtensionServiceNow(src *pagerduty.Extension, snowPassword *string,
}

b, _ := json.Marshal(src.Config)

var config pagerDutyExtensionServiceNowConfig
_ = json.Unmarshal(b, &config)

Expand Down
27 changes: 14 additions & 13 deletions pagerdutyplugin/resource_pagerduty_incident_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/PagerDuty/go-pagerduty"
"github.com/PagerDuty/terraform-provider-pagerduty/util"
"github.com/PagerDuty/terraform-provider-pagerduty/util/validate"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
Expand All @@ -35,10 +35,8 @@ func (r *resourceIncidentType) Schema(_ context.Context, _ resource.SchemaReques
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{
Required: true,
Expand All @@ -59,7 +57,11 @@ func (r *resourceIncidentType) Schema(_ context.Context, _ resource.SchemaReques
Required: true,
},
"description": schema.StringAttribute{Optional: true},
"enabled": schema.BoolAttribute{Optional: true, Computed: true},
"enabled": schema.BoolAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
},
"type": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
Expand Down Expand Up @@ -123,7 +125,7 @@ func (r *resourceIncidentType) Create(ctx context.Context, req resource.CreateRe
return
}

model, err = requestGetIncidentType(ctx, r.client, id, plan.ParentType, true, &resp.Diagnostics)
model, err = requestGetIncidentType(ctx, r.client, id, plan.ParentType, true)
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error reading PagerDuty incident type %s", id),
Expand All @@ -149,7 +151,7 @@ func (r *resourceIncidentType) Read(ctx context.Context, req resource.ReadReques
return
}

state, err := requestGetIncidentType(ctx, r.client, id.ValueString(), parent.ValueString(), false, &resp.Diagnostics)
state, err := requestGetIncidentType(ctx, r.client, id.ValueString(), parent.ValueString(), false)
if err != nil {
if util.IsNotFoundError(err) {
resp.State.RemoveResource(ctx)
Expand Down Expand Up @@ -193,7 +195,6 @@ func (r *resourceIncidentType) Update(ctx context.Context, req resource.UpdateRe
"Can not update value of field \"parent_type\"",
"",
)

}

incidentType, err := r.client.UpdateIncidentType(ctx, id, plan)
Expand All @@ -209,7 +210,7 @@ func (r *resourceIncidentType) Update(ctx context.Context, req resource.UpdateRe
return
}

model, err = flattenIncidentType(ctx, r.client, incidentType, model.ParentType.ValueString(), &resp.Diagnostics)
model, err = flattenIncidentType(ctx, r.client, incidentType, model.ParentType.ValueString())
if err != nil {
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...)
}
Expand Down Expand Up @@ -242,7 +243,7 @@ type resourceIncidentTypeModel struct {
Type types.String `tfsdk:"type"`
}

func requestGetIncidentType(ctx context.Context, client *pagerduty.Client, id, parent string, retryNotFound bool, diags *diag.Diagnostics) (resourceIncidentTypeModel, error) {
func requestGetIncidentType(ctx context.Context, client *pagerduty.Client, id, parent string, retryNotFound bool) (resourceIncidentTypeModel, error) {
var model resourceIncidentTypeModel

err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
Expand All @@ -257,7 +258,7 @@ func requestGetIncidentType(ctx context.Context, client *pagerduty.Client, id, p
return retry.RetryableError(err)
}

model, err = flattenIncidentType(ctx, client, incidentType, parent, diags)
model, err = flattenIncidentType(ctx, client, incidentType, parent)
if err != nil {
return retry.NonRetryableError(err)
}
Expand All @@ -268,7 +269,7 @@ func requestGetIncidentType(ctx context.Context, client *pagerduty.Client, id, p
return model, err
}

func flattenIncidentType(ctx context.Context, client *pagerduty.Client, response *pagerduty.IncidentType, parent string, diags *diag.Diagnostics) (resourceIncidentTypeModel, error) {
func flattenIncidentType(ctx context.Context, client *pagerduty.Client, response *pagerduty.IncidentType, parent string) (resourceIncidentTypeModel, error) {
if parent != response.Parent.ID {
incidentType, err := client.GetIncidentType(ctx, parent, pagerduty.GetIncidentTypeOptions{})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
Expand All @@ -39,26 +40,24 @@ func (r *resourceJiraCloudAccountMappingRule) Schema(_ context.Context, _ resour
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"name": schema.StringAttribute{
Required: true,
Validators: []validator.String{stringvalidator.LengthAtMost(100)},
},
"account_mapping": schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"autocreate_jql_disabled_reason": schema.StringAttribute{
Computed: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"autocreate_jql_disabled_until": schema.StringAttribute{
Computed: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
},
Blocks: map[string]schema.Block{
Expand All @@ -76,9 +75,10 @@ func (r *resourceJiraCloudAccountMappingRule) Schema(_ context.Context, _ resour
Attributes: map[string]schema.Attribute{
"autocreate_jql": schema.StringAttribute{Optional: true},
"create_issue_on_incident_trigger": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
},
"sync_notes_user": schema.StringAttribute{Optional: true},
},
Expand Down
Loading

0 comments on commit 45850e5

Please sign in to comment.