1
1
package codefresh
2
2
3
3
import (
4
- "github.com/codefresh-io/terraform-provider-codefresh/codefresh/context"
4
+ storageContext "github.com/codefresh-io/terraform-provider-codefresh/codefresh/context"
5
5
"log"
6
6
7
7
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
@@ -15,6 +15,7 @@ const (
15
15
contextYaml = "yaml"
16
16
contextSecretYaml = "secret-yaml"
17
17
contextGoogleStorage = "storage.gc"
18
+ contextS3Storage = "storage.s3"
18
19
)
19
20
20
21
var supportedContextType = []string {
@@ -137,7 +138,8 @@ func resourceContext() *schema.Resource {
137
138
},
138
139
},
139
140
},
140
- normalizeFieldName (contextGoogleStorage ): context .GcsSchema (),
141
+ normalizeFieldName (contextGoogleStorage ): storageContext .GcsSchema (),
142
+ normalizeFieldName (contextS3Storage ): storageContext .S3Schema (),
141
143
},
142
144
},
143
145
},
@@ -148,8 +150,7 @@ func resourceContext() *schema.Resource {
148
150
func resourceContextCreate (d * schema.ResourceData , meta interface {}) error {
149
151
150
152
client := meta .(* cfClient.Client )
151
- context := * mapResourceToContext (d )
152
- resp , err := client .CreateContext (& context )
153
+ resp , err := client .CreateContext (mapResourceToContext (d ))
153
154
if err != nil {
154
155
log .Printf ("[DEBUG] Error while creating context. Error = %v" , err )
155
156
return err
@@ -238,8 +239,8 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
238
239
m [normalizeFieldName (currentContextType )] = flattenContextConfig (spec )
239
240
case contextYaml , contextSecretYaml :
240
241
m [normalizeFieldName (currentContextType )] = flattenContextYaml (spec )
241
- case contextGoogleStorage :
242
- m [normalizeFieldName (currentContextType )] = context .FlattenStorageContextConfig (spec )
242
+ case contextGoogleStorage , contextS3Storage :
243
+ m [normalizeFieldName (currentContextType )] = storageContext .FlattenStorageContextConfig (spec )
243
244
default :
244
245
log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
245
246
return nil
@@ -288,7 +289,10 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
288
289
_ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
289
290
} else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
290
291
normalizedContextType = contextGoogleStorage
291
- normalizedContextData = context .ConvertStorageContext (data .([]interface {}))
292
+ normalizedContextData = storageContext .ConvertStorageContext (data .([]interface {}))
293
+ } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextS3Storage ) + ".0.data" ); ok {
294
+ normalizedContextType = contextS3Storage
295
+ normalizedContextData = storageContext .ConvertStorageContext (data .([]interface {}))
292
296
}
293
297
294
298
return & cfClient.Context {
0 commit comments