-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from hmlanigan/base-in-application
Base in application
- Loading branch information
Showing
9 changed files
with
121 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,9 +83,10 @@ Required: | |
|
||
Optional: | ||
|
||
- `base` (String) The operating system on which to deploy. E.g. [email protected]. | ||
- `channel` (String) The channel to use when deploying a charm. Specified as \<track>/\<risk>/\<branch>. | ||
- `revision` (Number) The revision of the charm to deploy. | ||
- `series` (String) The series on which to deploy. | ||
- `series` (String, Deprecated) The series on which to deploy. | ||
|
||
|
||
<a id="nestedblock--expose"></a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ resource "juju_machine" "this_machine" { | |
|
||
### Optional | ||
|
||
- `base` (String) The operating system series to install on the new machine(s). | ||
- `base` (String) The operating system to install on the new machine(s). E.g. [email protected]. | ||
- `constraints` (String) Machine constraints that overwrite those available from 'juju get-model-constraints' and provider's defaults. | ||
- `disks` (String) Storage constraints for disks to attach to the machine(s). | ||
- `name` (String) A name for the machine resource in Terraform. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ func TestAcc_DataSourceMachine_Edge(t *testing.T) { | |
ProtoV6ProviderFactories: frameworkProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMachine(modelName), | ||
Config: testAccDataSourceMachine(modelName, "base = \"[email protected]\""), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_machine.machine", "model", modelName), | ||
), | ||
|
@@ -47,7 +47,7 @@ func TestAcc_DataSourceMachine_Stable(t *testing.T) { | |
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMachine(modelName), | ||
Config: testAccDataSourceMachine(modelName, "series = \"jammy\""), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_machine.machine", "model", modelName), | ||
), | ||
|
@@ -56,7 +56,7 @@ func TestAcc_DataSourceMachine_Stable(t *testing.T) { | |
}) | ||
} | ||
|
||
func testAccDataSourceMachine(modelName string) string { | ||
func testAccDataSourceMachine(modelName, os string) string { | ||
return fmt.Sprintf(` | ||
resource "juju_model" "model" { | ||
name = %q | ||
|
@@ -65,11 +65,11 @@ resource "juju_model" "model" { | |
resource "juju_machine" "machine" { | ||
model = juju_model.model.name | ||
name = "machine" | ||
series = "jammy" | ||
%s | ||
} | ||
data "juju_machine" "machine" { | ||
model = juju_model.model.name | ||
machine_id = juju_machine.machine.machine_id | ||
}`, modelName) | ||
}`, modelName, os) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ func TestAcc_DataSourceOffer_Edge(t *testing.T) { | |
ProtoV6ProviderFactories: frameworkProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceOffer(modelName, offerName), | ||
Config: testAccDataSourceOffer(modelName, "base = \"[email protected]\"", offerName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_offer.this", "model", modelName), | ||
resource.TestCheckResourceAttr("data.juju_offer.this", "name", offerName), | ||
|
@@ -46,7 +46,7 @@ func TestAcc_DataSourceOffer_Stable(t *testing.T) { | |
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceOffer(modelName, offerName), | ||
Config: testAccDataSourceOffer(modelName, "series = \"jammy\"", offerName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_offer.this", "model", modelName), | ||
resource.TestCheckResourceAttr("data.juju_offer.this", "name", offerName), | ||
|
@@ -56,7 +56,7 @@ func TestAcc_DataSourceOffer_Stable(t *testing.T) { | |
}) | ||
} | ||
|
||
func testAccDataSourceOffer(modelName string, offerName string) string { | ||
func testAccDataSourceOffer(modelName, os, offerName string) string { | ||
return fmt.Sprintf(` | ||
resource "juju_model" "this" { | ||
name = %q | ||
|
@@ -68,7 +68,7 @@ resource "juju_application" "this" { | |
charm { | ||
name = "postgresql" | ||
series = "jammy" | ||
%s | ||
} | ||
} | ||
|
@@ -82,5 +82,5 @@ resource "juju_offer" "this" { | |
data "juju_offer" "this" { | ||
url = juju_offer.this.url | ||
} | ||
`, modelName, offerName) | ||
`, modelName, os, offerName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
|
@@ -198,13 +199,33 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest | |
int64planmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"series": schema.StringAttribute{ | ||
SeriesKey: schema.StringAttribute{ | ||
Description: "The series on which to deploy.", | ||
Optional: true, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
Validators: []validator.String{ | ||
stringvalidator.ConflictsWith(path.Expressions{ | ||
path.MatchRelative().AtParent().AtName(BaseKey), | ||
}...), | ||
}, | ||
DeprecationMessage: "Configure base instead. This attribute will be removed in the next major version of the provider.", | ||
}, | ||
BaseKey: schema.StringAttribute{ | ||
Description: "The operating system on which to deploy. E.g. [email protected].", | ||
Optional: true, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
Validators: []validator.String{ | ||
stringvalidator.ConflictsWith(path.Expressions{ | ||
path.MatchRelative().AtParent().AtName(SeriesKey), | ||
}...), | ||
stringIsBaseValidator{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -245,6 +266,7 @@ type nestedCharm struct { | |
Name types.String `tfsdk:"name"` | ||
Channel types.String `tfsdk:"channel"` | ||
Revision types.Int64 `tfsdk:"revision"` | ||
Base types.String `tfsdk:"base"` | ||
Series types.String `tfsdk:"series"` | ||
} | ||
|
||
|
@@ -323,7 +345,6 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq | |
if !planCharm.Revision.IsUnknown() { | ||
revision = int(planCharm.Revision.ValueInt64()) | ||
} | ||
series := planCharm.Series.ValueString() | ||
|
||
// TODO: investigate using map[string]string here and let | ||
// terraform do the conversion, will help in CreateApplication. | ||
|
@@ -366,7 +387,8 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq | |
CharmName: charmName, | ||
CharmChannel: channel, | ||
CharmRevision: revision, | ||
CharmSeries: series, | ||
CharmBase: planCharm.Base.ValueString(), | ||
CharmSeries: planCharm.Series.ValueString(), | ||
Units: int(plan.UnitCount.ValueInt64()), | ||
Config: configField, | ||
Constraints: parsedConstraints, | ||
|
@@ -396,6 +418,7 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq | |
plan.Placement = types.StringValue(readResp.Placement) | ||
plan.ApplicationName = types.StringValue(createResp.AppName) | ||
planCharm.Revision = types.Int64Value(int64(readResp.Revision)) | ||
planCharm.Base = types.StringValue(readResp.Base) | ||
planCharm.Series = types.StringValue(readResp.Series) | ||
planCharm.Channel = types.StringValue(readResp.Channel) | ||
charmType := req.Config.Schema.GetBlocks()[CharmKey].(schema.ListNestedBlock).NestedObject.Type() | ||
|
@@ -478,6 +501,7 @@ func (r *applicationResource) Read(ctx context.Context, req resource.ReadRequest | |
Name: types.StringValue(response.Name), | ||
Channel: types.StringValue(response.Channel), | ||
Revision: types.Int64Value(int64(response.Revision)), | ||
Base: types.StringValue(response.Base), | ||
Series: types.StringValue(response.Series), | ||
} | ||
charmType := req.State.Schema.GetBlocks()[CharmKey].(schema.ListNestedBlock).NestedObject.Type() | ||
|
@@ -602,7 +626,7 @@ func (r *applicationResource) Update(ctx context.Context, req resource.UpdateReq | |
if !planCharm.Channel.Equal(stateCharm.Channel) { | ||
updateApplicationInput.Channel = planCharm.Channel.ValueString() | ||
} | ||
if !planCharm.Series.Equal(stateCharm.Series) { | ||
if !planCharm.Series.Equal(stateCharm.Series) || !planCharm.Base.Equal(stateCharm.Base) { | ||
// This violates terraform's declarative model. We could implement | ||
// `juju set-application-base`, usually used after `upgrade-machine`, | ||
// which would change the operating system used for future units of | ||
|
@@ -743,7 +767,7 @@ func (r *applicationResource) Delete(ctx context.Context, req resource.DeleteReq | |
return | ||
} | ||
var state applicationResourceModel | ||
// Read Terraform prior state state into the model | ||
// Read Terraform prior state into the model | ||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
|
Oops, something went wrong.