@@ -94,42 +94,50 @@ func resourceNsxtPolicyGroup() *schema.Resource {
9494 State : nsxtDomainResourceImporter ,
9595 },
9696
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 ,
131134 },
132135 }
136+
137+ if withDomain {
138+ s ["domain" ] = getDomainNameSchema ()
139+ }
140+ return s
133141}
134142
135143func getIPAddressExpressionSchema () * schema.Resource {
@@ -833,10 +841,18 @@ func validateGroupCriteriaAndConjunctions(criteriaSets []interface{}, conjunctio
833841}
834842
835843func 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 {
836848 connector := getPolicyConnector (m )
837849
850+ domainName := ""
851+ if withDomain {
852+ domainName = d .Get ("domain" ).(string )
853+ }
838854 // 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 ))
840856 if err != nil {
841857 return err
842858 }
@@ -886,7 +902,7 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error
886902 if client == nil {
887903 return policyResourceNotSupportedError ()
888904 }
889- err = client .Patch (d . Get ( "domain" ).( string ) , id , obj )
905+ err = client .Patch (domainName , id , obj )
890906
891907 // Create the resource using PATCH
892908 log .Printf ("[INFO] Creating Group with ID %s" , id )
@@ -897,13 +913,20 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error
897913 d .SetId (id )
898914 d .Set ("nsx_id" , id )
899915
900- return resourceNsxtPolicyGroupRead (d , m )
916+ return resourceNsxtPolicyGroupGeneralRead (d , m , withDomain )
901917}
902918
903919func 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 {
904924 connector := getPolicyConnector (m )
905925 id := d .Id ()
906- domainName := d .Get ("domain" ).(string )
926+ domainName := ""
927+ if withDomain {
928+ domainName = d .Get ("domain" ).(string )
929+ }
907930 if id == "" {
908931 return fmt .Errorf ("Error obtaining Group ID" )
909932 }
@@ -920,7 +943,9 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error {
920943 setPolicyTagsInSchema (d , obj .Tags )
921944 d .Set ("nsx_id" , id )
922945 d .Set ("path" , obj .Path )
923- d .Set ("domain" , getDomainFromResourcePath (* obj .Path ))
946+ if withDomain {
947+ d .Set ("domain" , getDomainFromResourcePath (* obj .Path ))
948+ }
924949 d .Set ("revision" , obj .Revision )
925950 groupType := ""
926951 if len (obj .GroupType ) > 0 && util .NsxVersionHigherOrEqual ("3.2.0" ) {
@@ -951,6 +976,10 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error {
951976}
952977
953978func 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 {
954983 connector := getPolicyConnector (m )
955984
956985 id := d .Id ()
@@ -1007,15 +1036,23 @@ func resourceNsxtPolicyGroupUpdate(d *schema.ResourceData, m interface{}) error
10071036 }
10081037
10091038 // 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 )
10111044 if err != nil {
10121045 return handleUpdateError ("Group" , id , err )
10131046 }
10141047
1015- return resourceNsxtPolicyGroupRead (d , m )
1048+ return resourceNsxtPolicyGroupGeneralRead (d , m , withDomain )
10161049}
10171050
10181051func 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 {
10191056 id := d .Id ()
10201057 if id == "" {
10211058 return fmt .Errorf ("Error obtaining Group ID" )
@@ -1030,7 +1067,11 @@ func resourceNsxtPolicyGroupDelete(d *schema.ResourceData, m interface{}) error
10301067 if client == nil {
10311068 return policyResourceNotSupportedError ()
10321069 }
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 )
10341075 }
10351076
10361077 err := doDelete ()
0 commit comments