-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from codefresh-io/CR-5752
Cr 5752
- Loading branch information
Showing
6 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package context | ||
|
||
import ( | ||
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func convertStorageContext(context []interface{}, auth map[string]interface{}) map[string]interface{} { | ||
data := make(map[string]interface{}) | ||
data["auth"] = auth | ||
return data | ||
} | ||
|
||
func ConvertJsonConfigStorageContext(context []interface{}) map[string]interface{} { | ||
contextData := context[0].(map[string]interface{}) | ||
contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{}) | ||
auth := make(map[string]interface{}) | ||
auth["type"] = contextAuth["type"] | ||
auth["jsonConfig"] = contextAuth["json_config"] | ||
return convertStorageContext(context, auth) | ||
} | ||
|
||
func ConvertAzureStorageContext(context []interface{}) map[string]interface{} { | ||
contextData := context[0].(map[string]interface{}) | ||
contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{}) | ||
auth := make(map[string]interface{}) | ||
auth["type"] = contextAuth["type"] | ||
auth["accountName"] = contextAuth["account_name"] | ||
auth["accountKey"] = contextAuth["account_key"] | ||
return convertStorageContext(context, auth) | ||
} | ||
|
||
func flattenStorageContextConfig(spec cfClient.ContextSpec, auth map[string]interface{}) []interface{} { | ||
|
||
var res = make([]interface{}, 0) | ||
m := make(map[string]interface{}) | ||
|
||
dataList := make([]interface{}, 0) | ||
data := make(map[string]interface{}) | ||
|
||
authList := make([]interface{}, 0) | ||
authList = append(authList, auth) | ||
|
||
data["auth"] = authList | ||
|
||
dataList = append(dataList, data) | ||
|
||
m["data"] = dataList | ||
res = append(res, m) | ||
return res | ||
|
||
} | ||
|
||
func FlattenJsonConfigStorageContextConfig(spec cfClient.ContextSpec) []interface{} { | ||
auth := make(map[string]interface{}) | ||
auth["json_config"] = spec.Data["auth"].(map[string]interface{})["jsonConfig"] | ||
auth["type"] = spec.Data["type"] | ||
return flattenStorageContextConfig(spec, auth) | ||
} | ||
|
||
func FlattenAzureStorageContextConfig(spec cfClient.ContextSpec) []interface{} { | ||
auth := make(map[string]interface{}) | ||
authParams := spec.Data["auth"].(map[string]interface{}) | ||
auth["account_name"] = authParams["accountName"] | ||
auth["account_key"] = authParams["accountKey"] | ||
auth["type"] = spec.Data["type"] | ||
return flattenStorageContextConfig(spec, auth) | ||
} | ||
|
||
func storageSchema(authSchema *schema.Schema) *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"data": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"auth": authSchema, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func GcsSchema() *schema.Schema { | ||
sch := &schema.Schema{ | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"json_config": { | ||
Type: schema.TypeMap, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
return storageSchema(sch) | ||
} | ||
|
||
func S3Schema() *schema.Schema { | ||
sch := &schema.Schema{ | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"json_config": { | ||
Type: schema.TypeMap, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
return storageSchema(sch) | ||
} | ||
|
||
func AzureStorage() *schema.Schema { | ||
sch := &schema.Schema{ | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"account_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"account_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
return storageSchema(sch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
resource "codefresh_context" "gcs" { | ||
for_each = toset(["create"]) | ||
name = "gcs" | ||
spec { | ||
storagegc { | ||
data { | ||
auth { | ||
type = "basic" | ||
json_config = tomap({ | ||
"config": "cf" | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "codefresh_context" "s3" { | ||
for_each = toset(["create"]) | ||
name = "s3" | ||
spec { | ||
storages3 { | ||
data { | ||
auth { | ||
type = "basic" | ||
json_config = tomap({ | ||
"config": "cf" | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "codefresh_context" "azure" { | ||
for_each = toset(["create"]) | ||
name = "azure" | ||
spec { | ||
storageazuref { | ||
data { | ||
auth { | ||
type = "basic" | ||
account_name = "accName" | ||
account_key = "accKey" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_providers { | ||
codefresh = { | ||
source = "codefresh.io/app/codefresh" | ||
version = "0.1.0" | ||
} | ||
} | ||
} | ||
|
||
provider "codefresh" { | ||
api_url = var.api_url | ||
token = var.token # If token isn't set the provider expects the $CODEFRESH_API_KEY env variable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
variable api_url { | ||
type = string | ||
} | ||
|
||
variable token { | ||
type = string | ||
default = "" | ||
} |