Skip to content

Commit

Permalink
Merge pull request #328 from hmlanigan/remove-principal-from-schema
Browse files Browse the repository at this point in the history
Remove principal from schema
  • Loading branch information
hmlanigan authored Oct 23, 2023
2 parents b55c592 + b3beaab commit e8979bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a id="nestedblock--charm"></a>
### Nested Schema for `charm`
Expand Down
16 changes: 10 additions & 6 deletions internal/provider/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)...)
}
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 0 additions & 9 deletions internal/provider/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
{
Expand Down

0 comments on commit e8979bd

Please sign in to comment.