Skip to content

Commit

Permalink
fixup access app resource
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiDadireddy committed Sep 26, 2024
1 parent 05eb203 commit 75018be
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions internal/sdkv2provider/schema_cloudflare_access_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,21 @@ func resourceCloudflareAccessApplicationSchema() map[string]*schema.Schema {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hostname": {
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the attribute as provided by the IDP.",
},
"value": {
Type: schema.TypeList,
Required: true,
Description: "The name of the attribute as provided by the IDP.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
"value": {
Type: schema.TypeString,
Required: true,
Description: "The name of the attribute as provided by the IDP.",
Description: "The string value of hostname.",
},
},
},
Expand Down Expand Up @@ -997,15 +1002,18 @@ func convertTargetContextsToStruct(d *schema.ResourceData) (*[]cloudflare.InfraT
}
}

if targetAttributes, ok := itemMap["target_attributes"].(map[string]interface{}); ok {
attributes := make(map[string][]string)
for key, value := range targetAttributes {
valueList := value.([]interface{})
var stringValues []string
for _, val := range valueList {
stringValues = append(stringValues, val.(string))
attributes := make(map[string][]string)
if v, ok := itemMap["target_attributes"].(map[string]interface{}); ok && len(v) > 0 {
for _, attrItem := range v {
attrMap := attrItem.(map[string]interface{})
/// Unpack the nested "hostname" list
attrName := attrMap["name"].(string)
values := attrMap["value"].([]interface{})
for _, value := range values {
valueMap := value.(map[string]interface{})
attributes[attrName] = append(attributes[attrName], valueMap["value"].(string))
}
attributes[key] = stringValues

}

targetContext.TargetAttributes = attributes
Expand Down Expand Up @@ -1326,18 +1334,25 @@ func convertTargetContextsToSchema(targetContexts *[]cloudflare.InfraTargetConte

var targetContextsSchema []interface{}
for _, targetContext := range *targetContexts {
targetContextSchema := make(map[string]interface{})

targetContextSchema["port"] = targetContext.Port
targetContextSchema["protocol"] = targetContext.Protocol
targetAttributesList := []map[string]interface{}{}

attributeMap := make(map[string]interface{})
for key, values := range targetContext.TargetAttributes {
attributeMap[key] = values
keyValue := []map[string]interface{}{}
for _, value := range values {
keyValue = append(keyValue, map[string]interface{}{
"name": value,
})
}
targetAttributesList = append(targetAttributesList, map[string]interface{}{
key: keyValue,
})
}
targetContextSchema["target_attributes"] = attributeMap

targetContextsSchema = append(targetContextsSchema, targetContextSchema)
targetContextsSchema = append(targetContextsSchema, map[string]interface{}{
"port": targetContext.Port,
"protocol": targetContext.Protocol,
"target_attributes": targetAttributesList,
})
}
return targetContextsSchema
}
Expand Down

0 comments on commit 75018be

Please sign in to comment.