Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1680.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement:
`helm_release`: add support for the `take_ownership` field
```
1 change: 1 addition & 0 deletions docs/resources/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ A Chart is a Helm package. It contains all of the resource definitions necessary
- `set_list` (Block List) Custom list values to be merged with the values. (see [below for nested schema](#nestedblock--set_list))
- `set_sensitive` (Block Set) Custom sensitive values to be merged with the values. (see [below for nested schema](#nestedblock--set_sensitive))
- `skip_crds` (Boolean) If set, no CRDs will be installed. By default, CRDs are installed if not already present. Defaults to `false`.
- `take_ownership` (Boolean) If set, allows Helm to adopt existing resources not marked as managed by the release. Defaults to `false`.
- `timeout` (Number) Time in seconds to wait for any individual kubernetes operation. Defaults to 300 seconds.
- `upgrade_install` (Boolean) If true, the provider will install the release at the specified version even if a release not controlled by the provider is present: this is equivalent to running 'helm upgrade --install' with the Helm CLI. WARNING: this may not be suitable for production use -- see the 'Upgrade Mode' note in the provider documentation. Defaults to `false`.
- `values` (List of String) List of values in raw yaml format to pass to helm.
Expand Down
12 changes: 12 additions & 0 deletions helm/resource_helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type HelmReleaseModel struct {
SetSensitive types.List `tfsdk:"set_sensitive"`
SkipCrds types.Bool `tfsdk:"skip_crds"`
Status types.String `tfsdk:"status"`
TakeOwnership types.Bool `tfsdk:"take_ownership"`
Timeout types.Int64 `tfsdk:"timeout"`
UpgradeInstall types.Bool `tfsdk:"upgrade_install"`
Values types.List `tfsdk:"values"`
Expand Down Expand Up @@ -133,6 +134,7 @@ var defaultAttributes = map[string]interface{}{
"reset_values": false,
"reuse_values": false,
"skip_crds": false,
"take_ownership": false,
"timeout": int64(300),
"verify": false,
"wait": true,
Expand Down Expand Up @@ -497,6 +499,12 @@ func (r *HelmRelease) Schema(ctx context.Context, req resource.SchemaRequest, re
Computed: true,
Description: "Status of the release",
},
"take_ownership": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(defaultAttributes["take_ownership"].(bool)),
Description: "If set, Helm will take ownership of resources not already annotated by this release. Useful for migrations or recovery.",
},
"timeout": schema.Int64Attribute{
Optional: true,
Computed: true,
Expand Down Expand Up @@ -823,6 +831,7 @@ func (r *HelmRelease) Create(ctx context.Context, req resource.CreateRequest, re
client.WaitForJobs = state.WaitForJobs.ValueBool()
client.Devel = state.Devel.ValueBool()
client.DependencyUpdate = state.DependencyUpdate.ValueBool()
client.TakeOwnership = state.TakeOwnership.ValueBool()
client.Timeout = time.Duration(state.Timeout.ValueInt64()) * time.Second
client.Namespace = state.Namespace.ValueString()
client.ReleaseName = state.Name.ValueString()
Expand Down Expand Up @@ -1091,6 +1100,7 @@ func (r *HelmRelease) Update(ctx context.Context, req resource.UpdateRequest, re

client.Devel = plan.Devel.ValueBool()
client.Namespace = plan.Namespace.ValueString()
client.TakeOwnership = plan.TakeOwnership.ValueBool()
client.Timeout = time.Duration(plan.Timeout.ValueInt64()) * time.Second
client.Wait = plan.Wait.ValueBool()
client.WaitForJobs = plan.WaitForJobs.ValueBool()
Expand Down Expand Up @@ -1979,6 +1989,7 @@ func (r *HelmRelease) ModifyPlan(ctx context.Context, req resource.ModifyPlanReq
install.WaitForJobs = plan.WaitForJobs.ValueBool()
install.Devel = plan.Devel.ValueBool()
install.DependencyUpdate = plan.DependencyUpdate.ValueBool()
install.TakeOwnership = plan.TakeOwnership.ValueBool()
install.Timeout = time.Duration(plan.Timeout.ValueInt64()) * time.Second
install.Namespace = plan.Namespace.ValueString()
install.ReleaseName = plan.Name.ValueString()
Expand Down Expand Up @@ -2053,6 +2064,7 @@ func (r *HelmRelease) ModifyPlan(ctx context.Context, req resource.ModifyPlanReq
upgrade.ChartPathOptions = *cpo
upgrade.Devel = plan.Devel.ValueBool()
upgrade.Namespace = plan.Namespace.ValueString()
upgrade.TakeOwnership = plan.TakeOwnership.ValueBool()
upgrade.Timeout = time.Duration(plan.Timeout.ValueInt64()) * time.Second
upgrade.Wait = plan.Wait.ValueBool()
upgrade.DryRun = true
Expand Down
2 changes: 2 additions & 0 deletions helm/resource_helm_release_stateupgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (r *HelmRelease) buildUpgradeStateMap(_ context.Context) map[int64]resource
"status": tftypes.String,
"timeout": tftypes.Number,
"upgrade_install": tftypes.Bool,
"take_ownership": tftypes.Bool,
"values": tftypes.List{ElementType: tftypes.String},
"verify": tftypes.Bool,
"version": tftypes.String,
Expand All @@ -267,6 +268,7 @@ func (r *HelmRelease) buildUpgradeStateMap(_ context.Context) map[int64]resource
newType.AttributeTypes["set_wo"],
[]tftypes.Value{},
),
"take_ownership": tftypes.NewValue(tftypes.Bool, false),
"set_wo_revision": tftypes.NewValue(tftypes.Number, float64(1)),
"atomic": oldState["atomic"],
"chart": oldState["chart"],
Expand Down
49 changes: 49 additions & 0 deletions helm/resource_helm_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestAccResourceRelease_import(t *testing.T) {

// Default values
resource.TestCheckResourceAttr("helm_release.imported", "verify", "false"),
resource.TestCheckResourceAttr("helm_release.imported", "take_ownership", "false"),
resource.TestCheckResourceAttr("helm_release.imported", "timeout", "300"),
resource.TestCheckResourceAttr("helm_release.imported", "wait", "true"),
resource.TestCheckResourceAttr("helm_release.imported", "wait_for_jobs", "true"),
Expand Down Expand Up @@ -1710,6 +1711,54 @@ func TestAccResourceRelease_LintFailValues(t *testing.T) {
})
}

func TestAccResourceRelease_takeOwnership(t *testing.T) {
name := randName("takeownership")
namespace := createRandomNamespace(t)
defer deleteNamespace(t, namespace)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: protoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testAccHelmReleaseConfigWithTakeOwnership(testResourceName, namespace, name, "1.2.3", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("helm_release.test", "take_ownership", "true"),
resource.TestCheckResourceAttr("helm_release.test", "metadata.name", name),
resource.TestCheckResourceAttr("helm_release.test", "metadata.namespace", namespace),
resource.TestCheckResourceAttr("helm_release.test", "metadata.version", "1.2.3"),
resource.TestCheckResourceAttr("helm_release.test", "status", release.StatusDeployed.String()),
),
},
{
Config: testAccHelmReleaseConfigWithTakeOwnership(testResourceName, namespace, name, "1.2.3", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("helm_release.test", "take_ownership", "true"),
),
},
},
})
}
func testAccHelmReleaseConfigWithTakeOwnership(resource, ns, name, version string, takeOwnership bool) string {
return fmt.Sprintf(`
resource "helm_release" "%s" {
name = %q
namespace = %q
chart = "test-chart"
repository = %q
version = %q
description = "Test"
take_ownership = %t

set = [
{
name = "foo"
value = "bar"
}
]
}
`, resource, name, ns, testRepositoryURL, version, takeOwnership)
}

func TestAccResourceRelease_LintFailChart(t *testing.T) {
namespace := createRandomNamespace(t)
defer deleteNamespace(t, namespace)
Expand Down
Loading