11package codefresh
22
33import (
4- "github.com/codefresh-io/terraform-provider-codefresh/codefresh/context"
4+ storageContext "github.com/codefresh-io/terraform-provider-codefresh/codefresh/context"
55 "log"
66
77 cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
@@ -15,6 +15,7 @@ const (
1515 contextYaml = "yaml"
1616 contextSecretYaml = "secret-yaml"
1717 contextGoogleStorage = "storage.gc"
18+ contextS3Storage = "storage.s3"
1819)
1920
2021var supportedContextType = []string {
@@ -137,7 +138,8 @@ func resourceContext() *schema.Resource {
137138 },
138139 },
139140 },
140- normalizeFieldName (contextGoogleStorage ): context .GcsSchema (),
141+ normalizeFieldName (contextGoogleStorage ): storageContext .GcsSchema (),
142+ normalizeFieldName (contextS3Storage ): storageContext .S3Schema (),
141143 },
142144 },
143145 },
@@ -148,8 +150,7 @@ func resourceContext() *schema.Resource {
148150func resourceContextCreate (d * schema.ResourceData , meta interface {}) error {
149151
150152 client := meta .(* cfClient.Client )
151- context := * mapResourceToContext (d )
152- resp , err := client .CreateContext (& context )
153+ resp , err := client .CreateContext (mapResourceToContext (d ))
153154 if err != nil {
154155 log .Printf ("[DEBUG] Error while creating context. Error = %v" , err )
155156 return err
@@ -238,8 +239,8 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
238239 m [normalizeFieldName (currentContextType )] = flattenContextConfig (spec )
239240 case contextYaml , contextSecretYaml :
240241 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 )
243244 default :
244245 log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
245246 return nil
@@ -288,7 +289,10 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
288289 _ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
289290 } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
290291 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 {}))
292296 }
293297
294298 return & cfClient.Context {
0 commit comments