@@ -25,6 +25,30 @@ func resourceAciSubjectFilter() *schema.Resource {
2525 },
2626
2727 SchemaVersion : 1 ,
28+
29+ CustomizeDiff : func (ctx context.Context , diff * schema.ResourceDiff , v interface {}) error {
30+ // The "none" value in directives does not get returned by APIC.
31+ // 1. Ignore "none" option when set with other options.
32+ // 2. State is empty when configured only with "none" option.
33+ if diff .HasChange ("directives" ) {
34+ old , new := diff .GetChange ("directives" )
35+ state := old .([]interface {})
36+ config := new .([]interface {})
37+ if len (config ) > 1 {
38+ directives := make ([]string , 0 )
39+ for _ , val := range config {
40+ if val != "none" {
41+ directives = append (directives , val .(string ))
42+ }
43+ }
44+ diff .SetNew ("directives" , directives )
45+ } else if len (state ) == 0 && len (config ) == 1 && config [0 ] == "none" {
46+ diff .SetNew ("directives" , []string {})
47+ }
48+ }
49+ return nil
50+ },
51+
2852 Schema : AppendBaseAttrSchema (map [string ]* schema.Schema {
2953 "contract_subject_dn" : {
3054 Type : schema .TypeString ,
@@ -99,23 +123,11 @@ func setSubjectFilterAttributes(vzRsSubjFiltAtt *models.SubjectFilter, d *schema
99123 d .Set ("contract_subject_dn" , GetParentDn (vzRsSubjFiltAtt .DistinguishedName , fmt .Sprintf ("/" + models .RnvzRsSubjFiltAtt , vzRsSubjFiltAttMap ["name" ])))
100124 d .Set ("annotation" , vzRsSubjFiltAttMap ["annotation" ])
101125 d .Set ("action" , vzRsSubjFiltAttMap ["action" ])
102- directivesGet := make ([]string , 0 , 1 )
103- for _ , val := range strings .Split (vzRsSubjFiltAttMap ["directives" ], "," ) {
104- if val != "" {
105- directivesGet = append (directivesGet , strings .Trim (val , " " ))
106- }
107- }
108- // The "none" value in directives does not get returned by APIC.
109- // Add "none" if the user has defined the value in the directives attributes.
110- if userDirectives , ok := d .GetOk ("directives" ); ok {
111- for _ , val := range userDirectives .([]interface {}) {
112- if val .(string ) == "none" {
113- directivesGet = append (directivesGet , "none" )
114- break
115- }
116- }
126+ directives := []string {}
127+ if vzRsSubjFiltAttMap ["directives" ] != "" {
128+ directives = strings .Split (vzRsSubjFiltAttMap ["directives" ], "," )
117129 }
118- d .Set ("directives" , directivesGet )
130+ d .Set ("directives" , directives )
119131 d .Set ("priority_override" , vzRsSubjFiltAttMap ["priorityOverride" ])
120132 d .Set ("filter_dn" , vzRsSubjFiltAttMap ["tDn" ])
121133 return d , nil
0 commit comments