Skip to content

Commit 9bc6a64

Browse files
authored
Merge pull request #19 from jetstack/id_use_state_unknown
Fix service account updates with no changes
2 parents 2892e1b + 474ec55 commit 9bc6a64

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

internal/provider/application_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/hashicorp/terraform-plugin-framework/path"
1515
"github.com/hashicorp/terraform-plugin-framework/resource"
1616
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
17+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
18+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1719
"github.com/hashicorp/terraform-plugin-framework/types"
1820
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1921
)
@@ -41,6 +43,9 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest
4143
Attributes: map[string]schema.Attribute{
4244
"id": schema.StringAttribute{
4345
Computed: true,
46+
PlanModifiers: []planmodifier.String{
47+
stringplanmodifier.UseStateForUnknown(),
48+
},
4449
},
4550
"name": schema.StringAttribute{
4651
Required: true,

internal/provider/certificate_template_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1517
"github.com/hashicorp/terraform-plugin-framework/types"
1618
)
1719

@@ -38,6 +40,9 @@ func (r *certificateTemplateResource) Schema(_ context.Context, _ resource.Schem
3840
Attributes: map[string]schema.Attribute{
3941
"id": schema.StringAttribute{
4042
Computed: true,
43+
PlanModifiers: []planmodifier.String{
44+
stringplanmodifier.UseStateForUnknown(),
45+
},
4146
},
4247
"name": schema.StringAttribute{
4348
Required: true,

internal/provider/plugin_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/hashicorp/terraform-plugin-framework/path"
1515
"github.com/hashicorp/terraform-plugin-framework/resource"
1616
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
17+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
18+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1719
"github.com/hashicorp/terraform-plugin-framework/types"
1820
)
1921

@@ -40,6 +42,9 @@ func (r *pluginResource) Schema(_ context.Context, _ resource.SchemaRequest, res
4042
Attributes: map[string]schema.Attribute{
4143
"id": schema.StringAttribute{
4244
Computed: true,
45+
PlanModifiers: []planmodifier.String{
46+
stringplanmodifier.UseStateForUnknown(),
47+
},
4348
},
4449
"type": schema.StringAttribute{
4550
Required: true,

internal/provider/registry_account_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1517
"github.com/hashicorp/terraform-plugin-framework/types"
1618
)
1719

@@ -38,6 +40,9 @@ func (r *registryAccountResource) Schema(_ context.Context, _ resource.SchemaReq
3840
Attributes: map[string]schema.Attribute{
3941
"id": schema.StringAttribute{
4042
Computed: true,
43+
PlanModifiers: []planmodifier.String{
44+
stringplanmodifier.UseStateForUnknown(),
45+
},
4146
},
4247
"name": schema.StringAttribute{
4348
Required: true,

internal/provider/service_account_resource.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1517
"github.com/hashicorp/terraform-plugin-framework/types"
1618
)
1719

@@ -38,6 +40,9 @@ func (r *serviceAccountResource) Schema(_ context.Context, _ resource.SchemaRequ
3840
Attributes: map[string]schema.Attribute{
3941
"id": schema.StringAttribute{
4042
Computed: true,
43+
PlanModifiers: []planmodifier.String{
44+
stringplanmodifier.UseStateForUnknown(),
45+
},
4146
},
4247
"name": schema.StringAttribute{
4348
Required: true,
@@ -201,8 +206,24 @@ func (r *serviceAccountResource) Read(ctx context.Context, req resource.ReadRequ
201206
state.ID = types.StringValue(sa.ID)
202207
state.Name = types.StringValue(sa.Name)
203208
state.Owner = types.StringValue(sa.Owner)
204-
state.PublicKey = types.StringValue(sa.PublicKey)
205-
state.CredentialLifetime = types.Int32Value(sa.CredentialLifetime)
209+
if sa.PublicKey != state.PublicKey.ValueString() {
210+
state.PublicKey = types.StringValue(sa.PublicKey)
211+
}
212+
if sa.CredentialLifetime != state.CredentialLifetime.ValueInt32() {
213+
state.CredentialLifetime = types.Int32Value(sa.CredentialLifetime)
214+
}
215+
if sa.JwksURI != state.JwksURI.ValueString() {
216+
state.JwksURI = types.StringValue(sa.JwksURI)
217+
}
218+
if sa.IssuerURL != state.IssuerURL.ValueString() {
219+
state.IssuerURL = types.StringValue(sa.IssuerURL)
220+
}
221+
if sa.Audience != state.Audience.ValueString() {
222+
state.Audience = types.StringValue(sa.Audience)
223+
}
224+
if sa.Subject != state.Subject.ValueString() {
225+
state.Subject = types.StringValue(sa.Subject)
226+
}
206227

207228
scopes := []types.String{}
208229
for _, v := range sa.Scopes {

internal/provider/team_resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
15+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
16+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1517
"github.com/hashicorp/terraform-plugin-framework/types"
1618
)
1719

@@ -38,6 +40,9 @@ func (r *teamResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
3840
Attributes: map[string]schema.Attribute{
3941
"id": schema.StringAttribute{
4042
Computed: true,
43+
PlanModifiers: []planmodifier.String{
44+
stringplanmodifier.UseStateForUnknown(),
45+
},
4146
},
4247
"name": schema.StringAttribute{
4348
Required: true,

0 commit comments

Comments
 (0)