• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Scalr / terraform-provider-scalr / 14217303880

02 Apr 2025 10:22AM UTC coverage: 67.264%. First build
14217303880

Pull #409

github

petroprotsakh
SCALRCORE-32300 Update changelog
Pull Request #409: SCALRCORE-32300 BE > Provider > `scalr_variable` resource doesn't offer any way to expose/use variable value

175 of 520 new or added lines in 5 files covered. (33.65%)

7773 of 11556 relevant lines covered (67.26%)

224.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/provider/variable_migrate.go
1
package provider
2

3
import (
4
        "context"
5

6
        "github.com/hashicorp/terraform-plugin-framework/resource"
7
        "github.com/hashicorp/terraform-plugin-framework/types"
8
        "github.com/scalr/go-scalr"
9
)
10

NEW
11
func upgradeVariableResourceStateV0toV3(c *scalr.Client) func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
12
        return func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
13
                type variableModelV0 struct {
×
NEW
14
                        Id          types.String `tfsdk:"id"`
×
NEW
15
                        Key         types.String `tfsdk:"key"`
×
NEW
16
                        Value       types.String `tfsdk:"value"`
×
NEW
17
                        Category    types.String `tfsdk:"category"`
×
NEW
18
                        HCL         types.Bool   `tfsdk:"hcl"`
×
NEW
19
                        Sensitive   types.Bool   `tfsdk:"sensitive"`
×
NEW
20
                        WorkspaceID types.String `tfsdk:"workspace_id"`
×
NEW
21
                }
×
NEW
22

×
NEW
23
                var dataV0 variableModelV0
×
NEW
24
                resp.Diagnostics.Append(req.State.Get(ctx, &dataV0)...)
×
NEW
25
                if resp.Diagnostics.HasError() {
×
NEW
26
                        return
×
NEW
27
                }
×
28

NEW
29
                variable, err := c.Variables.Read(ctx, dataV0.Id.ValueString())
×
NEW
30
                if err != nil {
×
NEW
31
                        resp.Diagnostics.AddError("Error reading variable", err.Error())
×
NEW
32
                        return
×
NEW
33
                }
×
34

NEW
35
                data, diags := variableResourceModelFromAPI(ctx, variable, nil)
×
NEW
36
                if variable.Sensitive {
×
NEW
37
                        data.Value = dataV0.Value
×
NEW
38
                }
×
NEW
39
                resp.Diagnostics.Append(diags...)
×
NEW
40

×
NEW
41
                diags = resp.State.Set(ctx, data)
×
NEW
42
                resp.Diagnostics.Append(diags...)
×
43
        }
44
}
45

NEW
46
func upgradeVariableResourceStateV1toV3(c *scalr.Client) func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
47
        return func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
48
                type variableModelV1 struct {
×
NEW
49
                        Id            types.String `tfsdk:"id"`
×
NEW
50
                        Key           types.String `tfsdk:"key"`
×
NEW
51
                        Value         types.String `tfsdk:"value"`
×
NEW
52
                        Category      types.String `tfsdk:"category"`
×
NEW
53
                        HCL           types.Bool   `tfsdk:"hcl"`
×
NEW
54
                        Sensitive     types.Bool   `tfsdk:"sensitive"`
×
NEW
55
                        Final         types.Bool   `tfsdk:"final"`
×
NEW
56
                        Force         types.Bool   `tfsdk:"force"`
×
NEW
57
                        WorkspaceID   types.String `tfsdk:"workspace_id"`
×
NEW
58
                        EnvironmentID types.String `tfsdk:"environment_id"`
×
NEW
59
                        AccountID     types.String `tfsdk:"account_id"`
×
NEW
60
                }
×
NEW
61

×
NEW
62
                var dataV1 variableModelV1
×
NEW
63
                resp.Diagnostics.Append(req.State.Get(ctx, &dataV1)...)
×
NEW
64
                if resp.Diagnostics.HasError() {
×
NEW
65
                        return
×
NEW
66
                }
×
67

NEW
68
                variable, err := c.Variables.Read(ctx, dataV1.Id.ValueString())
×
NEW
69
                if err != nil {
×
NEW
70
                        resp.Diagnostics.AddError("Error reading variable", err.Error())
×
NEW
71
                        return
×
NEW
72
                }
×
73

NEW
74
                data, diags := variableResourceModelFromAPI(ctx, variable, nil)
×
NEW
75
                if !dataV1.Force.IsNull() {
×
NEW
76
                        data.Force = dataV1.Force
×
NEW
77
                }
×
NEW
78
                if variable.Sensitive {
×
NEW
79
                        data.Value = dataV1.Value
×
NEW
80
                }
×
NEW
81
                resp.Diagnostics.Append(diags...)
×
NEW
82

×
NEW
83
                diags = resp.State.Set(ctx, data)
×
NEW
84
                resp.Diagnostics.Append(diags...)
×
85
        }
86
}
87

NEW
88
func upgradeVariableResourceStateV2toV3(c *scalr.Client) func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
89
        return func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
×
NEW
90
                type variableModelV2 struct {
×
NEW
91
                        Id            types.String `tfsdk:"id"`
×
NEW
92
                        Key           types.String `tfsdk:"key"`
×
NEW
93
                        Value         types.String `tfsdk:"value"`
×
NEW
94
                        Category      types.String `tfsdk:"category"`
×
NEW
95
                        HCL           types.Bool   `tfsdk:"hcl"`
×
NEW
96
                        Sensitive     types.Bool   `tfsdk:"sensitive"`
×
NEW
97
                        Description   types.String `tfsdk:"description"`
×
NEW
98
                        Final         types.Bool   `tfsdk:"final"`
×
NEW
99
                        Force         types.Bool   `tfsdk:"force"`
×
NEW
100
                        WorkspaceID   types.String `tfsdk:"workspace_id"`
×
NEW
101
                        EnvironmentID types.String `tfsdk:"environment_id"`
×
NEW
102
                        AccountID     types.String `tfsdk:"account_id"`
×
NEW
103
                }
×
NEW
104

×
NEW
105
                var dataV2 variableModelV2
×
NEW
106
                resp.Diagnostics.Append(req.State.Get(ctx, &dataV2)...)
×
NEW
107
                if resp.Diagnostics.HasError() {
×
NEW
108
                        return
×
NEW
109
                }
×
110

NEW
111
                variable, err := c.Variables.Read(ctx, dataV2.Id.ValueString())
×
NEW
112
                if err != nil {
×
NEW
113
                        resp.Diagnostics.AddError("Error reading variable", err.Error())
×
NEW
114
                        return
×
NEW
115
                }
×
116

NEW
117
                data, diags := variableResourceModelFromAPI(ctx, variable, nil)
×
NEW
118
                if !dataV2.Force.IsNull() {
×
NEW
119
                        data.Force = dataV2.Force
×
NEW
120
                }
×
NEW
121
                if variable.Sensitive {
×
NEW
122
                        data.Value = dataV2.Value
×
NEW
123
                }
×
NEW
124
                resp.Diagnostics.Append(diags...)
×
NEW
125

×
NEW
126
                diags = resp.State.Set(ctx, data)
×
NEW
127
                resp.Diagnostics.Append(diags...)
×
128
        }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc