Skip to content

Commit 4a40f9d

Browse files
authored
πŸ› fix inconsistent results after apply (#146)
After the change where we allow customers to configure the `space` at the provider level, I found two issues when running Terraform apply: Error 1: Error: Provider returned invalid result object after apply After the apply operation, the provider still indicated an unknown value for mondoo_integration_slack.space.space_id. All values must be known after apply, so this is always a bug in the provider and should be reported in the provider's own repository. Terraform will still save the other known object values in the state. Error 2: Error: Provider produced inconsistent result after apply When applying changes to mondoo_integration_slack.space, provider "provider[\"registry.terraform.io/hashicorp/mondoo\"]" produced an unexpected new value: .space_id: was null, but now cty.StringVal("silly-hamilton-515695"). This is a bug in the provider, which should be reported in the provider's own issue tracker. This change fixes both of these issues. Note that we didn't catch this issue for the lack of acceptance tests on all integration resources, I added tests for two integrations, Slack and Shodan, but we probably need to do the rest of them soon. Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
1 parent f3869d3 commit 4a40f9d

19 files changed

Lines changed: 305 additions & 1 deletion

β€Žinternal/provider/custom_framework_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func (r *customFrameworkResource) Schema(_ context.Context, _ resource.SchemaReq
7878
"space_id": schema.StringAttribute{
7979
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
8080
Optional: true,
81+
Computed: true,
82+
PlanModifiers: []planmodifier.String{
83+
stringplanmodifier.UseStateForUnknown(),
84+
},
8185
},
8286
"mrn": schema.StringAttribute{
8387
MarkdownDescription: "Mondoo Resource Name.",

β€Žinternal/provider/framework_assignment_resource.goβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/path"
88
"github.com/hashicorp/terraform-plugin-framework/resource"
99
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1012
"github.com/hashicorp/terraform-plugin-framework/types"
1113
"github.com/hashicorp/terraform-plugin-log/tflog"
1214
)
@@ -41,6 +43,10 @@ func (r *frameworkAssignmentResource) Schema(_ context.Context, _ resource.Schem
4143
"space_id": schema.StringAttribute{
4244
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
4345
Optional: true,
46+
Computed: true,
47+
PlanModifiers: []planmodifier.String{
48+
stringplanmodifier.UseStateForUnknown(),
49+
},
4450
},
4551
"framework_mrn": schema.ListAttribute{
4652
MarkdownDescription: "Compliance Framework MRN.",

β€Žinternal/provider/gql.goβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ func (c *ExtendedGqlClient) DeleteFramework(ctx context.Context, mrn string) err
908908
// the provided MRN and if it exists, it compares the space configured at the provider level (if any).
909909
func (c *ExtendedGqlClient) ImportIntegration(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) (*Integration, bool) {
910910
mrn := req.ID
911+
ctx = tflog.SetField(ctx, "mrn", mrn)
912+
tflog.Debug(ctx, "importing integration")
911913
integration, err := c.GetClientIntegration(ctx, mrn)
912914
if err != nil {
913915
resp.Diagnostics.

β€Žinternal/provider/integration_aws_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (r *integrationAwsResource) Schema(ctx context.Context, req resource.Schema
9595
"space_id": schema.StringAttribute{
9696
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
9797
Optional: true,
98+
Computed: true,
99+
PlanModifiers: []planmodifier.String{
100+
stringplanmodifier.UseStateForUnknown(),
101+
},
98102
},
99103
"mrn": schema.StringAttribute{
100104
Computed: true,

β€Žinternal/provider/integration_aws_serverless_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ func (r *integrationAwsServerlessResource) Schema(ctx context.Context, req resou
211211
"space_id": schema.StringAttribute{
212212
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
213213
Optional: true,
214+
Computed: true,
215+
PlanModifiers: []planmodifier.String{
216+
stringplanmodifier.UseStateForUnknown(),
217+
},
214218
},
215219
"mrn": schema.StringAttribute{
216220
Computed: true,

β€Žinternal/provider/integration_azure_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (r *integrationAzureResource) Schema(ctx context.Context, req resource.Sche
5959
"space_id": schema.StringAttribute{
6060
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
6161
Optional: true,
62+
Computed: true,
63+
PlanModifiers: []planmodifier.String{
64+
stringplanmodifier.UseStateForUnknown(),
65+
},
6266
},
6367
"mrn": schema.StringAttribute{
6468
Computed: true,

β€Žinternal/provider/integration_domain_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func (r *integrationDomainResource) Schema(ctx context.Context, req resource.Sch
4848
"space_id": schema.StringAttribute{
4949
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
5050
Optional: true,
51+
Computed: true,
52+
PlanModifiers: []planmodifier.String{
53+
stringplanmodifier.UseStateForUnknown(),
54+
},
5155
},
5256
"mrn": schema.StringAttribute{
5357
Computed: true,

β€Žinternal/provider/integration_gcp_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (r *integrationGcpResource) Schema(ctx context.Context, req resource.Schema
5656
"space_id": schema.StringAttribute{
5757
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
5858
Optional: true,
59+
Computed: true,
60+
PlanModifiers: []planmodifier.String{
61+
stringplanmodifier.UseStateForUnknown(),
62+
},
5963
},
6064
"mrn": schema.StringAttribute{
6165
Computed: true,

β€Žinternal/provider/integration_github_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (r *integrationGithubResource) Schema(ctx context.Context, req resource.Sch
9595
"space_id": schema.StringAttribute{
9696
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
9797
Optional: true,
98+
Computed: true,
99+
PlanModifiers: []planmodifier.String{
100+
stringplanmodifier.UseStateForUnknown(),
101+
},
98102
},
99103
"mrn": schema.StringAttribute{
100104
Computed: true,

β€Žinternal/provider/integration_ms365_resource.goβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (r *integrationMs365Resource) Schema(ctx context.Context, req resource.Sche
5555
"space_id": schema.StringAttribute{
5656
MarkdownDescription: "Mondoo Space Identifier. If it is not provided, the provider space is used.",
5757
Optional: true,
58+
Computed: true,
59+
PlanModifiers: []planmodifier.String{
60+
stringplanmodifier.UseStateForUnknown(),
61+
},
5862
},
5963
"mrn": schema.StringAttribute{
6064
Computed: true,

0 commit comments

Comments
Β (0)