Skip to content

Commit

Permalink
[bugfix] fix schema attributes and documentation to reflect computed …
Browse files Browse the repository at this point in the history
…(Read-Only) attributes correctly and added directives, action to filter and removed directives from contract for datasource_mso_schema_template_contract
  • Loading branch information
akinross authored and lhercot committed Aug 16, 2023
1 parent 7b1b345 commit fdb2c1e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
41 changes: 17 additions & 24 deletions mso/datasource_mso_schema_template_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,58 @@ func dataSourceMSOTemplateContract() *schema.Resource {
"schema_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"template_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"contract_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"display_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"filter_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"scope": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"filter_relationships": {
Type: schema.TypeMap,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"filter_schema_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"filter_template_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"filter_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"action": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"directives": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
},
Optional: true,
Computed: true,
},
"directives": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Computed: true,
},
}),
}
Expand Down Expand Up @@ -131,23 +123,24 @@ func dataSourceMSOTemplateContractRead(d *schema.ResourceData, m interface{}) er
d.Set("filter_type", models.StripQuotes(contractCont.S("filterType").String()))
d.Set("scope", models.StripQuotes(contractCont.S("scope").String()))

var filterList []interface{}
count, _ := contractCont.ArrayCount("filterRelationships")
filterMap := make(map[string]interface{})
for i := 0; i < count; i++ {
filterMap := make(map[string]interface{})
filterCont, err := contractCont.ArrayElement(i, "filterRelationships")
if err != nil {
return fmt.Errorf("Unable to parse the filter Relationships list")
}

d.Set("directives", filterCont.S("directives").Data().([]interface{}))
filRef := filterCont.S("filterRef").Data()
split := strings.Split(filRef.(string), "/")

filterMap["filter_schema_id"] = fmt.Sprintf("%s", split[2])
filterMap["filter_template_name"] = fmt.Sprintf("%s", split[4])
filterMap["filter_name"] = fmt.Sprintf("%s", split[6])
filterMap["directives"] = filterCont.S("directives").Data().([]interface{})
filterMap["action"] = filterCont.S("action").Data().(string)
filterList = append(filterList, filterMap)
}
d.Set("filter_relationships", filterMap)
d.Set("filter_relationships", filterList)

found = true
break
Expand Down
31 changes: 13 additions & 18 deletions website/docs/d/schema_template_contract.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Data source for MSO Schema Template Contract.

```hcl
data "mso_schema_template_contract" "contract1" {
data "mso_schema_template_contract" "example" {
schema_id = data.mso_schema.schema1.id
template_name = "Template1"
contract_name = "c1"
Expand All @@ -24,23 +24,18 @@ data "mso_schema_template_contract" "contract1" {

## Argument Reference ##

* `schema_id` - (Required) SchemaID under which you want to deploy Contract.
* `template_name` - (Required) Template where Contract to be created.
* `contract_name` - (Required) The name of the contract to manage.
* `schema_id` - (Required) The schema ID of the Contract.
* `template_name` - (Required) The template name of the Contract.
* `contract_name` - (Required) The name of the Contract.

## Attribute Reference ##

* `display_name` - (Optional) Display Name of the contract on the MSO UI.
* `filter_type` - (Optional) The type of filters defined in this contract. Allowed values are `bothWay` and `oneWay`. Default to `bothWay`
* `scope` - (Optional) The scope of the contract.
* `filter_relationships` - **Deprecated** (Required if filter_relationship is not used) Map to provide Filter Relationships. This attribute is deprecated, use `filter_relationship` instead.
* `filter_relationships.filter_schema_id` - (Optional) The schemaId in which the filter is located.
* `filter_relationships.filter_template_name` - (Optional) The template name in which the filter is located.
* `filter_relationships.filter_name` - (Required) The filter to associate with this contract.

* `filter_relationship` - (Required if filter_relationships is not used) Map to provide Filter Relationships.
* `filter_relationship.filter_schema_id` - (Optional) The schemaId in which the filter is located.
* `filter_relationship.filter_template_name` - (Optional) The template name in which the filter is located.
* `filter_relationship.filter_name` - (Required) The filter to associate with this contract.

* `directives` - (Optional) A list of filter directives. Allowed values are `log` and `none`.
* `display_name` - (Read-Only) The name of the Contract as displayed on the MSO UI.
* `filter_type` - (Read-Only) The type of the Filter.
* `scope` - (Read-Only) The scope of the Contract.
* `filter_relationships` - A map for the Filter relationship.
* `filter_schema_id` - (Read-Only) The schema ID of the Filter.
* `filter_template_name` - (Read-Only) The template name of the Filter.
* `filter_name` - (Read-Only) The name of the Filter.
* `action` - (Read-Only) The action of the Filter.
* `directives` - (Read-Only) The directives of the Filter.

0 comments on commit fdb2c1e

Please sign in to comment.