5
5
"fmt"
6
6
"io/ioutil"
7
7
"net/http"
8
+ "os"
8
9
"strings"
9
10
10
11
"github.com/antihax/optional"
@@ -23,6 +24,7 @@ func ResourceFileStoreNodeFile() *schema.Resource {
23
24
UpdateContext : resourceFileStoreNodeFileCreateOrUpdate ,
24
25
CreateContext : resourceFileStoreNodeFileCreateOrUpdate ,
25
26
DeleteContext : resourceFileStoreNodeFileDelete ,
27
+ CustomizeDiff : resourceFileStoreNodeFileCustomizeDiff ,
26
28
Importer : helpers .MultiLevelResourceImporter ,
27
29
28
30
Schema : map [string ]* schema.Schema {
@@ -35,6 +37,7 @@ func ResourceFileStoreNodeFile() *schema.Resource {
35
37
Description : "File content path to be upladed on Harness File Store" ,
36
38
Type : schema .TypeString ,
37
39
Optional : true ,
40
+ Computed : true ,
38
41
},
39
42
"mime_type" : {
40
43
Description : "File mime type" ,
@@ -52,6 +55,7 @@ func ResourceFileStoreNodeFile() *schema.Resource {
52
55
Description : "File content stored on Harness File Store" ,
53
56
Type : schema .TypeString ,
54
57
Optional : true ,
58
+ Computed : true ,
55
59
},
56
60
"path" : {
57
61
Description : "Harness File Store file path" ,
@@ -117,6 +121,28 @@ func ResourceFileStoreNodeFile() *schema.Resource {
117
121
return resource
118
122
}
119
123
124
+ func resourceFileStoreNodeFileCustomizeDiff (_ context.Context , diff * schema.ResourceDiff , _ interface {}) error {
125
+ if contentFilePath , ok := diff .GetOk (fileContentPath ); ok {
126
+ fileContent , err := os .ReadFile (contentFilePath .(string ))
127
+ if err != nil {
128
+ return fmt .Errorf ("error reading content file at path '%s': %w" , contentFilePath , err )
129
+ }
130
+
131
+ if diff .Id () != "" {
132
+ remoteContent := diff .Get ("content" ).(string )
133
+
134
+ if string (fileContent ) != remoteContent {
135
+ err = diff .SetNew ("content" , string (fileContent ))
136
+ if err != nil {
137
+ return fmt .Errorf ("error setting content: %w" , err )
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ return nil
144
+ }
145
+
120
146
func resourceFileStoreNodeFileRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
121
147
c , ctx := meta .(* internal.Session ).GetPlatformClientWithContext (ctx )
122
148
id := d .Get (identifier ).(string )
0 commit comments