@@ -94,42 +94,50 @@ func resourceNsxtPolicyGroup() *schema.Resource {
94
94
State : nsxtDomainResourceImporter ,
95
95
},
96
96
97
- Schema : map [string ]* schema.Schema {
98
- "nsx_id" : getNsxIDSchema (),
99
- "path" : getPathSchema (),
100
- "display_name" : getDisplayNameSchema (),
101
- "description" : getDescriptionSchema (),
102
- "revision" : getRevisionSchema (),
103
- "tag" : getTagsSchema (),
104
- "context" : getContextSchema (false , false , false ),
105
- "domain" : getDomainNameSchema (),
106
- "group_type" : {
107
- Type : schema .TypeString ,
108
- Description : "Indicates the group type" ,
109
- ValidateFunc : validation .StringInSlice (groupTypeValues , false ),
110
- Optional : true ,
111
- },
112
- "criteria" : {
113
- Type : schema .TypeList ,
114
- Description : "Criteria to determine Group membership" ,
115
- Elem : getCriteriaSetSchema (),
116
- Optional : true ,
117
- },
118
- "conjunction" : {
119
- Type : schema .TypeList ,
120
- Description : "A conjunction applied to 2 sets of criteria." ,
121
- Elem : getConjunctionSchema (),
122
- Optional : true ,
123
- },
124
- "extended_criteria" : {
125
- Type : schema .TypeList ,
126
- Description : "Extended criteria to determine group membership. extended_criteria is implicitly \" AND\" with criteria" ,
127
- Elem : getExtendedCriteriaSetSchema (),
128
- Optional : true ,
129
- MaxItems : 1 ,
130
- },
97
+ Schema : getPolicyGroupSchema (true ),
98
+ }
99
+ }
100
+
101
+ func getPolicyGroupSchema (withDomain bool ) map [string ]* schema.Schema {
102
+ s := map [string ]* schema.Schema {
103
+ "nsx_id" : getNsxIDSchema (),
104
+ "path" : getPathSchema (),
105
+ "display_name" : getDisplayNameSchema (),
106
+ "description" : getDescriptionSchema (),
107
+ "revision" : getRevisionSchema (),
108
+ "tag" : getTagsSchema (),
109
+ "context" : getContextSchema (false , false , ! withDomain ),
110
+ "group_type" : {
111
+ Type : schema .TypeString ,
112
+ Description : "Indicates the group type" ,
113
+ ValidateFunc : validation .StringInSlice (groupTypeValues , false ),
114
+ Optional : true ,
115
+ },
116
+ "criteria" : {
117
+ Type : schema .TypeList ,
118
+ Description : "Criteria to determine Group membership" ,
119
+ Elem : getCriteriaSetSchema (),
120
+ Optional : true ,
121
+ },
122
+ "conjunction" : {
123
+ Type : schema .TypeList ,
124
+ Description : "A conjunction applied to 2 sets of criteria." ,
125
+ Elem : getConjunctionSchema (),
126
+ Optional : true ,
127
+ },
128
+ "extended_criteria" : {
129
+ Type : schema .TypeList ,
130
+ Description : "Extended criteria to determine group membership. extended_criteria is implicitly \" AND\" with criteria" ,
131
+ Elem : getExtendedCriteriaSetSchema (),
132
+ Optional : true ,
133
+ MaxItems : 1 ,
131
134
},
132
135
}
136
+
137
+ if withDomain {
138
+ s ["domain" ] = getDomainNameSchema ()
139
+ }
140
+ return s
133
141
}
134
142
135
143
func getIPAddressExpressionSchema () * schema.Resource {
@@ -833,10 +841,18 @@ func validateGroupCriteriaAndConjunctions(criteriaSets []interface{}, conjunctio
833
841
}
834
842
835
843
func resourceNsxtPolicyGroupCreate (d * schema.ResourceData , m interface {}) error {
844
+ return resourceNsxtPolicyGroupGeneralCreate (d , m , true )
845
+ }
846
+
847
+ func resourceNsxtPolicyGroupGeneralCreate (d * schema.ResourceData , m interface {}, withDomain bool ) error {
836
848
connector := getPolicyConnector (m )
837
849
850
+ domainName := ""
851
+ if withDomain {
852
+ domainName = d .Get ("domain" ).(string )
853
+ }
838
854
// Initialize resource Id and verify this ID is not yet used
839
- id , err := getOrGenerateID2 (d , m , resourceNsxtPolicyGroupExistsInDomainPartial (d . Get ( "domain" ).( string ) ))
855
+ id , err := getOrGenerateID2 (d , m , resourceNsxtPolicyGroupExistsInDomainPartial (domainName ))
840
856
if err != nil {
841
857
return err
842
858
}
@@ -886,7 +902,7 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error
886
902
if client == nil {
887
903
return policyResourceNotSupportedError ()
888
904
}
889
- err = client .Patch (d . Get ( "domain" ).( string ) , id , obj )
905
+ err = client .Patch (domainName , id , obj )
890
906
891
907
// Create the resource using PATCH
892
908
log .Printf ("[INFO] Creating Group with ID %s" , id )
@@ -897,13 +913,20 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error
897
913
d .SetId (id )
898
914
d .Set ("nsx_id" , id )
899
915
900
- return resourceNsxtPolicyGroupRead (d , m )
916
+ return resourceNsxtPolicyGroupGeneralRead (d , m , withDomain )
901
917
}
902
918
903
919
func resourceNsxtPolicyGroupRead (d * schema.ResourceData , m interface {}) error {
920
+ return resourceNsxtPolicyGroupGeneralRead (d , m , true )
921
+ }
922
+
923
+ func resourceNsxtPolicyGroupGeneralRead (d * schema.ResourceData , m interface {}, withDomain bool ) error {
904
924
connector := getPolicyConnector (m )
905
925
id := d .Id ()
906
- domainName := d .Get ("domain" ).(string )
926
+ domainName := ""
927
+ if withDomain {
928
+ domainName = d .Get ("domain" ).(string )
929
+ }
907
930
if id == "" {
908
931
return fmt .Errorf ("Error obtaining Group ID" )
909
932
}
@@ -920,7 +943,9 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error {
920
943
setPolicyTagsInSchema (d , obj .Tags )
921
944
d .Set ("nsx_id" , id )
922
945
d .Set ("path" , obj .Path )
923
- d .Set ("domain" , getDomainFromResourcePath (* obj .Path ))
946
+ if withDomain {
947
+ d .Set ("domain" , getDomainFromResourcePath (* obj .Path ))
948
+ }
924
949
d .Set ("revision" , obj .Revision )
925
950
groupType := ""
926
951
if len (obj .GroupType ) > 0 && util .NsxVersionHigherOrEqual ("3.2.0" ) {
@@ -951,6 +976,10 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error {
951
976
}
952
977
953
978
func resourceNsxtPolicyGroupUpdate (d * schema.ResourceData , m interface {}) error {
979
+ return resourceNsxtPolicyGroupGeneralUpdate (d , m , true )
980
+ }
981
+
982
+ func resourceNsxtPolicyGroupGeneralUpdate (d * schema.ResourceData , m interface {}, withDomain bool ) error {
954
983
connector := getPolicyConnector (m )
955
984
956
985
id := d .Id ()
@@ -1007,15 +1036,23 @@ func resourceNsxtPolicyGroupUpdate(d *schema.ResourceData, m interface{}) error
1007
1036
}
1008
1037
1009
1038
// Update the resource using PATCH
1010
- err = client .Patch (d .Get ("domain" ).(string ), id , obj )
1039
+ domainName := ""
1040
+ if withDomain {
1041
+ domainName = d .Get ("domain" ).(string )
1042
+ }
1043
+ err = client .Patch (domainName , id , obj )
1011
1044
if err != nil {
1012
1045
return handleUpdateError ("Group" , id , err )
1013
1046
}
1014
1047
1015
- return resourceNsxtPolicyGroupRead (d , m )
1048
+ return resourceNsxtPolicyGroupGeneralRead (d , m , withDomain )
1016
1049
}
1017
1050
1018
1051
func resourceNsxtPolicyGroupDelete (d * schema.ResourceData , m interface {}) error {
1052
+ return resourceNsxtPolicyGroupGeneralDelete (d , m , true )
1053
+ }
1054
+
1055
+ func resourceNsxtPolicyGroupGeneralDelete (d * schema.ResourceData , m interface {}, withDomain bool ) error {
1019
1056
id := d .Id ()
1020
1057
if id == "" {
1021
1058
return fmt .Errorf ("Error obtaining Group ID" )
@@ -1030,7 +1067,11 @@ func resourceNsxtPolicyGroupDelete(d *schema.ResourceData, m interface{}) error
1030
1067
if client == nil {
1031
1068
return policyResourceNotSupportedError ()
1032
1069
}
1033
- return client .Delete (d .Get ("domain" ).(string ), id , & failIfSubtreeExists , & forceDelete )
1070
+ domainName := ""
1071
+ if withDomain {
1072
+ domainName = d .Get ("domain" ).(string )
1073
+ }
1074
+ return client .Delete (domainName , id , & failIfSubtreeExists , & forceDelete )
1034
1075
}
1035
1076
1036
1077
err := doDelete ()
0 commit comments