Skip to content

Commit 4ea4229

Browse files
author
Your Name
committed
Refactor: Replace stateful resource with terraform_data
1. The `stateful_string` resource appears to be deprecated, so it has been replaced with the native `terraform_data` resource. 2. Using `stateful_string` with a large Terraform plan resulted in the following error: ``` │ Error: Plugin error │ │ with stateful_string.plan_output, │ on resource_plan_config.tf line 10, in resource "stateful_string" "plan_output": │ 10: resource "stateful_string" "plan_output" { │ │ The plugin returned an unexpected error from │ plugin.(*GRPCProvider).PlanResourceChange: rpc error: code = │ ResourceExhausted desc = grpc: received message larger than max (4858459 │ vs. 4194304) ``` This change ensures better compatibility and avoids hitting gRPC message size limits.
1 parent 4045f88 commit 4ea4229

File tree

8 files changed

+9
-81
lines changed

8 files changed

+9
-81
lines changed

docker-prod/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ RUN echo "StrictHostKeyChecking no" >> $HOME/.ssh/config
3030
RUN echo "LogLevel quiet" >> $HOME/.ssh/config
3131
RUN chmod 0600 $HOME/.ssh/config
3232

33-
RUN mkdir -p /usr/local/share/terraform/plugins/github.com/ashald/stateful/1.2.0/linux_${TARGETARCH}/ && \
34-
wget -O /usr/local/share/terraform/plugins/github.com/ashald/stateful/1.2.0/linux_${TARGETARCH}/terraform-provider-stateful_v1.2.0 \
35-
"https://github.com/ashald/terraform-provider-stateful/releases/download/v1.2.0/terraform-provider-stateful_v1.2.0-linux-${TARGETARCH}" && \
36-
chmod +x /usr/local/share/terraform/plugins/github.com/ashald/stateful/1.2.0/linux_${TARGETARCH}/terraform-provider-stateful_v1.2.0
3733
COPY $TARGETARCH/terraform/* /usr/local/bin/
3834
RUN terraform --version
3935
COPY $TARGETARCH/check $TARGETARCH/in $TARGETARCH/out /opt/resource/

src/terraform-resource/in/in_plan_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ var _ = Describe("JSON Plan", func() {
9595
fixturesDir := path.Join(helpers.ProjectRoot(), "fixtures")
9696
err = exec.Command("cp", "-r", fixturesDir, workingDir).Run()
9797
Expect(err).ToNot(HaveOccurred())
98-
99-
err = helpers.DownloadStatefulPlugin(workingDir)
100-
Expect(err).ToNot(HaveOccurred())
10198
})
10299

103100
AfterEach(func() {

src/terraform-resource/out/out_custom_plugins_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ var _ = Describe("Out Lifecycle with Custom Plugins", func() {
5151
Expect(err).ToNot(HaveOccurred())
5252
err = helpers.DownloadPlugins(awsPluginDir, awsProviderURL)
5353
Expect(err).ToNot(HaveOccurred())
54-
// In production image the stateful provider is installed in system-wide location, but manually install
55-
// this plugin in plugin dir to avoid needing to run tests as root.
56-
statefulProviderURL := fmt.Sprintf("https://github.com/ashald/terraform-provider-stateful/releases/download/v1.2.0/terraform-provider-stateful_v1.2.0-%s-%s.zip", runtime.GOOS, runtime.GOARCH)
57-
statefulPluginDir := path.Join(pluginDir, "github.com", "ashald", "stateful", "1.2.0", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH))
58-
err = os.MkdirAll(statefulPluginDir, 0700)
59-
Expect(err).ToNot(HaveOccurred())
60-
err = helpers.DownloadPlugins(statefulPluginDir, statefulProviderURL)
61-
Expect(err).ToNot(HaveOccurred())
6254

6355
// ensure relative paths resolve correctly
6456
err = os.Chdir(workingDir)

src/terraform-resource/out/out_import_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ var _ = Describe("Out Import", func() {
4545
fixturesDir := path.Join(helpers.ProjectRoot(), "fixtures")
4646
err = exec.Command("cp", "-r", fixturesDir, workingDir).Run()
4747
Expect(err).ToNot(HaveOccurred())
48-
49-
err = helpers.DownloadStatefulPlugin(workingDir)
50-
Expect(err).ToNot(HaveOccurred())
5148
})
5249

5350
AfterEach(func() {

src/terraform-resource/out/out_migrated_from_storage_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,6 @@ var _ = Describe("Out - Migrated From Storage", func() {
605605
})
606606

607607
Context("when applying a plan", func() {
608-
BeforeEach(func() {
609-
err := helpers.DownloadStatefulPlugin(workingDir)
610-
Expect(err).ToNot(HaveOccurred())
611-
})
612-
613608
It("plan infrastructure and apply it", func() {
614609
planRequest := models.OutRequest{
615610
Source: models.Source{

src/terraform-resource/out/out_plan_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ var _ = Describe("Out Plan", func() {
6464
fixturesDir := path.Join(helpers.ProjectRoot(), "fixtures")
6565
err = exec.Command("cp", "-r", fixturesDir, workingDir).Run()
6666
Expect(err).ToNot(HaveOccurred())
67-
68-
err = helpers.DownloadStatefulPlugin(workingDir)
69-
Expect(err).ToNot(HaveOccurred())
7067
})
7168

7269
AfterEach(func() {

src/terraform-resource/terraform/client.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,20 @@ func (c *client) writePlanProviderConfig(outputDir string, planContents, planCon
171171
}
172172

173173
configContents := []byte(fmt.Sprintf(`
174-
terraform {
175-
required_providers {
176-
stateful = {
177-
source = "github.com/ashald/stateful"
178-
version = "~> 1.0"
179-
}
180-
}
174+
resource "terraform_data" "plan_output" {
175+
input = %s
181176
}
182-
resource "stateful_string" "plan_output" {
183-
desired = %s
184-
}
185-
resource "stateful_string" "plan_output_json" {
186-
desired = %s
177+
resource "terraform_data" "plan_output_json" {
178+
input = %s
187179
}
180+
188181
output "%s" {
189182
sensitive = true
190-
value = stateful_string.plan_output.desired
183+
value = terraform_data.plan_output.output
191184
}
192185
output "%s" {
193186
sensitive = true
194-
value = stateful_string.plan_output_json.desired
187+
value = terraform_data.plan_output_json.output
195188
}
196189
`, escapedPlan, escapedJSONPlan, models.PlanContent, models.PlanContentJSON))
197190

@@ -784,7 +777,7 @@ func (c *client) SavePlanToBackend(planEnvName string) error {
784777
}
785778
defer os.RemoveAll(tmpDir)
786779

787-
// TODO: this stateful set and reset isn't great
780+
// TODO: this terraform_data set and reset isn't great
788781
origDir, err := os.Getwd()
789782
if err != nil {
790783
return err
@@ -856,7 +849,7 @@ func (c *client) GetPlanFromBackend(planEnvName string) error {
856849
}
857850
defer os.RemoveAll(tmpDir)
858851

859-
// TODO: this stateful set and reset isn't great
852+
// TODO: this terraform_data set and reset isn't great
860853
origDir, err := os.Getwd()
861854
if err != nil {
862855
return err

src/terraform-resource/test/helpers/plugins.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package helpers
22

33
import (
44
"archive/zip"
5-
"fmt"
65
"io"
76
"io/ioutil"
87
"net/http"
98
"os"
109
"path/filepath"
11-
"runtime"
1210
)
1311

1412
func DownloadPlugins(pluginPath string, url string) error {
@@ -60,40 +58,3 @@ func DownloadPlugins(pluginPath string, url string) error {
6058

6159
return nil
6260
}
63-
64-
func DownloadStatefulPlugin(workingDir string) error {
65-
var hostOS string
66-
if runtime.GOOS == "darwin" {
67-
hostOS = "darwin"
68-
} else {
69-
hostOS = "linux"
70-
}
71-
url := fmt.Sprintf("https://github.com/ashald/terraform-provider-stateful/releases/download/v1.2.0/terraform-provider-stateful_v1.2.0-%s-amd64", hostOS)
72-
73-
resp, err := http.Get(url)
74-
if err != nil {
75-
return err
76-
}
77-
defer resp.Body.Close()
78-
79-
pluginDir := filepath.Join(workingDir, ".terraform.d", "plugins", "github.com",
80-
"ashald", "stateful", "1.2.0", fmt.Sprintf("%s_amd64", hostOS))
81-
err = os.MkdirAll(pluginDir, os.ModePerm)
82-
if err != nil {
83-
return err
84-
}
85-
86-
pluginPath := filepath.Join(pluginDir, "terraform-provider-stateful_v1.2.0")
87-
out, err := os.Create(pluginPath)
88-
if err != nil {
89-
return err
90-
}
91-
defer out.Close()
92-
93-
if err = out.Chmod(0755); err != nil {
94-
return err
95-
}
96-
97-
_, err = io.Copy(out, resp.Body)
98-
return err
99-
}

0 commit comments

Comments
 (0)