diff --git a/docs/resources/application.md b/docs/resources/application.md index 3ed9e50f..c49934a1 100644 --- a/docs/resources/application.md +++ b/docs/resources/application.md @@ -72,7 +72,7 @@ resource "juju_application" "placement_example" { ### Read-Only - `id` (String) The ID of this resource. -- `principal` (Boolean) Whether this is a Principal application +- `principal` (Boolean, Deprecated) Whether this is a Principal application ### Nested Schema for `charm` diff --git a/internal/provider/resource_application.go b/internal/provider/resource_application.go index 7515aff7..c413423f 100644 --- a/internal/provider/resource_application.go +++ b/internal/provider/resource_application.go @@ -66,9 +66,12 @@ type applicationResourceModel struct { Expose types.List `tfsdk:"expose"` ModelName types.String `tfsdk:"model"` Placement types.String `tfsdk:"placement"` - Principal types.Bool `tfsdk:"principal"` - Trust types.Bool `tfsdk:"trust"` - UnitCount types.Int64 `tfsdk:"units"` + // TODO - remove Principal when we version the schema + // and remove deprecated elements. Once we create upgrade + // functionality it can be removed from the structure. + Principal types.Bool `tfsdk:"principal"` + Trust types.Bool `tfsdk:"trust"` + UnitCount types.Int64 `tfsdk:"units"` // ID required by the testing framework ID types.String `tfsdk:"id"` } @@ -163,6 +166,7 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest PlanModifiers: []planmodifier.Bool{ boolplanmodifier.UseStateForUnknown(), }, + DeprecationMessage: "Principal is computed only and not needed. This attribute will be removed in the next major version of the provider.", }, "id": schema.StringAttribute{ Computed: true, @@ -414,8 +418,8 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq // Save plan into Terraform state plan.Constraints = types.StringValue(readResp.Constraints.String()) - plan.Principal = types.BoolValue(readResp.Principal) plan.Placement = types.StringValue(readResp.Placement) + plan.Principal = types.BoolNull() plan.ApplicationName = types.StringValue(createResp.AppName) planCharm.Revision = types.Int64Value(int64(readResp.Revision)) planCharm.Base = types.StringValue(readResp.Base) @@ -492,7 +496,7 @@ func (r *applicationResource) Read(ctx context.Context, req resource.ReadRequest // Use the response to fill in state state.Placement = types.StringValue(response.Placement) - state.Principal = types.BoolValue(response.Principal) + state.Principal = types.BoolNull() state.UnitCount = types.Int64Value(int64(response.Units)) state.Trust = types.BoolValue(response.Trust) @@ -688,6 +692,7 @@ func (r *applicationResource) Update(ctx context.Context, req resource.UpdateReq } plan.ID = types.StringValue(newAppID(plan.ModelName.ValueString(), plan.ApplicationName.ValueString())) + plan.Principal = types.BoolNull() r.trace("Updated", applicationResourceModelForLogging(ctx, &plan)) resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) } @@ -835,7 +840,6 @@ func applicationResourceModelForLogging(_ context.Context, app *applicationResou "constraints": app.Constraints.ValueString(), "model": app.ModelName.ValueString(), "placement": app.Placement.ValueString(), - "principal": app.Principal.ValueBoolPointer(), "expose": app.Expose.String(), "trust": app.Trust.ValueBoolPointer(), "units": app.UnitCount.ValueInt64(), diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 6c24ec78..0e388a77 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -37,9 +37,6 @@ func TestAcc_ResourceApplication_Edge(t *testing.T) { resource.TestCheckResourceAttr("juju_application.this", "charm.0.name", "jameinel-ubuntu-lite"), resource.TestCheckResourceAttr("juju_application.this", "trust", "true"), resource.TestCheckResourceAttr("juju_application.this", "expose.#", "1"), - // We do not have access to this data during creation, only during read. - // Therefor it's set to the bool default - resource.TestCheckResourceAttr("juju_application.this", "principal", "true"), ), }, { @@ -102,8 +99,6 @@ func TestAcc_ResourceApplication_Edge(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_application.this", "model", modelName), resource.TestCheckResourceAttr("juju_application.this", "constraints", "arch=amd64 cores=1 mem=4096M"), - resource.TestCheckResourceAttr("juju_application.this", "principal", "true"), - resource.TestCheckResourceAttr("juju_application.subordinate", "principal", "false"), ), }, { @@ -227,7 +222,6 @@ func TestAcc_ResourceApplication_Minimal(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", charmName), resource.TestCheckResourceAttr(resourceName, "charm.#", "1"), resource.TestCheckResourceAttr(resourceName, "charm.0.name", charmName), - resource.TestCheckResourceAttr(resourceName, "principal", "true"), ), }, { @@ -269,7 +263,6 @@ func TestAcc_ResourceApplication_Stable(t *testing.T) { resource.TestCheckResourceAttr("juju_application.this", "charm.0.name", "jameinel-ubuntu-lite"), resource.TestCheckResourceAttr("juju_application.this", "trust", "true"), resource.TestCheckResourceAttr("juju_application.this", "expose.#", "1"), - resource.TestCheckResourceAttr("juju_application.this", "principal", "true"), ), }, { @@ -303,8 +296,6 @@ func TestAcc_ResourceApplication_Stable(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_application.this", "model", modelName), resource.TestCheckResourceAttr("juju_application.this", "constraints", "arch=amd64 cores=1 mem=4096M"), - resource.TestCheckResourceAttr("juju_application.this", "principal", "true"), - resource.TestCheckResourceAttr("juju_application.subordinate", "principal", "false"), ), }, {