Skip to content

Commit 0aba843

Browse files
add s3 support
1 parent 8688cdc commit 0aba843

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

codefresh/context/storage.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func FlattenStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
4141

4242
}
4343

44-
func GcsSchema() *schema.Schema {
44+
func storageSchema() *schema.Schema {
4545
return &schema.Schema{
4646
Type: schema.TypeList,
4747
Optional: true,
@@ -79,3 +79,11 @@ func GcsSchema() *schema.Schema {
7979
},
8080
}
8181
}
82+
83+
func GcsSchema() *schema.Schema {
84+
return storageSchema()
85+
}
86+
87+
func S3Schema() *schema.Schema {
88+
return storageSchema()
89+
}

codefresh/resource_context.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package codefresh
22

33
import (
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

2021
var 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 {
148150
func 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

Comments
 (0)