@@ -24,7 +24,7 @@ func resourceNsxtPolicySecurityPolicy() *schema.Resource {
2424 Importer : & schema.ResourceImporter {
2525 State : nsxtDomainResourceImporter ,
2626 },
27- Schema : getPolicySecurityPolicySchema (false , true , true ),
27+ Schema : getPolicySecurityPolicySchema (false , true , true , true ),
2828 }
2929}
3030
@@ -61,9 +61,12 @@ func resourceNsxtPolicySecurityPolicyExistsPartial(domainName string) func(sessi
6161 }
6262}
6363
64- func policySecurityPolicyBuildAndPatch (d * schema.ResourceData , m interface {}, id string , createFlow , withRule bool ) error {
64+ func policySecurityPolicyBuildAndPatch (d * schema.ResourceData , m interface {}, id string , createFlow , withRule , withDomain bool ) error {
6565 obj := parentSecurityPolicySchemaToModel (d , id )
66- domain := d .Get ("domain" ).(string )
66+ domain := ""
67+ if withDomain {
68+ domain = d .Get ("domain" ).(string )
69+ }
6770 revision := int64 (d .Get ("revision" ).(int ))
6871 log .Printf ("[INFO] Creating Security Policy with ID %s" , id )
6972
@@ -92,15 +95,15 @@ func policySecurityPolicyBuildAndPatch(d *schema.ResourceData, m interface{}, id
9295}
9396
9497func resourceNsxtPolicySecurityPolicyCreate (d * schema.ResourceData , m interface {}) error {
95- return resourceNsxtPolicySecurityPolicyGeneralCreate (d , m , true )
98+ return resourceNsxtPolicySecurityPolicyGeneralCreate (d , m , true , true )
9699}
97100
98101func resourceNsxtPolicySecurityPolicyRead (d * schema.ResourceData , m interface {}) error {
99- return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , true )
102+ return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , true , true )
100103}
101104
102105func resourceNsxtPolicySecurityPolicyUpdate (d * schema.ResourceData , m interface {}) error {
103- return resourceNsxtPolicySecurityPolicyGeneralUpdate (d , m , true )
106+ return resourceNsxtPolicySecurityPolicyGeneralUpdate (d , m , true , true )
104107}
105108
106109func resourceNsxtPolicySecurityPolicyDelete (d * schema.ResourceData , m interface {}) error {
@@ -124,14 +127,18 @@ func resourceNsxtPolicySecurityPolicyDelete(d *schema.ResourceData, m interface{
124127 return nil
125128}
126129
127- func resourceNsxtPolicySecurityPolicyGeneralCreate (d * schema.ResourceData , m interface {}, withRule bool ) error {
130+ func resourceNsxtPolicySecurityPolicyGeneralCreate (d * schema.ResourceData , m interface {}, withRule , withDomain bool ) error {
128131 // Initialize resource Id and verify this ID is not yet used
129- id , err := getOrGenerateID2 (d , m , resourceNsxtPolicySecurityPolicyExistsPartial (d .Get ("domain" ).(string )))
132+ domain := ""
133+ if withDomain {
134+ domain = d .Get ("domain" ).(string )
135+ }
136+ id , err := getOrGenerateID2 (d , m , resourceNsxtPolicySecurityPolicyExistsPartial (domain ))
130137 if err != nil {
131138 return err
132139 }
133140
134- err = policySecurityPolicyBuildAndPatch (d , m , id , true , withRule )
141+ err = policySecurityPolicyBuildAndPatch (d , m , id , true , withRule , withDomain )
135142
136143 if err != nil {
137144 return handleCreateError ("Security Policy" , id , err )
@@ -140,11 +147,11 @@ func resourceNsxtPolicySecurityPolicyGeneralCreate(d *schema.ResourceData, m int
140147 d .SetId (id )
141148 d .Set ("nsx_id" , id )
142149
143- return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , withRule )
150+ return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , withRule , withDomain )
144151}
145152
146- func resourceNsxtPolicySecurityPolicyGeneralRead (d * schema.ResourceData , m interface {}, withRule bool ) error {
147- obj , err := parentSecurityPolicyModelToSchema (d , m )
153+ func resourceNsxtPolicySecurityPolicyGeneralRead (d * schema.ResourceData , m interface {}, withRule , withDomain bool ) error {
154+ obj , err := parentSecurityPolicyModelToSchema (d , m , withDomain )
148155 if err != nil {
149156 return handleReadError (d , "SecurityPolicy" , d .Id (), err )
150157 }
@@ -154,15 +161,15 @@ func resourceNsxtPolicySecurityPolicyGeneralRead(d *schema.ResourceData, m inter
154161 return nil
155162}
156163
157- func resourceNsxtPolicySecurityPolicyGeneralUpdate (d * schema.ResourceData , m interface {}, withRule bool ) error {
164+ func resourceNsxtPolicySecurityPolicyGeneralUpdate (d * schema.ResourceData , m interface {}, withRule , withDomain bool ) error {
158165 id := d .Id ()
159166 if id == "" {
160167 return fmt .Errorf ("Error obtaining Security Policy id" )
161168 }
162- err := policySecurityPolicyBuildAndPatch (d , m , id , false , withRule )
169+ err := policySecurityPolicyBuildAndPatch (d , m , id , false , withRule , withDomain )
163170 if err != nil {
164171 return handleUpdateError ("Security Policy" , id , err )
165172 }
166173
167- return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , withRule )
174+ return resourceNsxtPolicySecurityPolicyGeneralRead (d , m , withRule , withDomain )
168175}
0 commit comments