@@ -53,10 +53,10 @@ func resourceCloudcaNetwork() *schema.Resource {
5353 ForceNew : true ,
5454 Description : `The network offering name or id (e.g. "Standard Network" or "Load Balanced Network")` ,
5555 },
56- "network_acl_id " : {
56+ "network_acl " : {
5757 Type : schema .TypeString ,
5858 Required : true ,
59- Description : "Id of the network ACL" ,
59+ Description : "Name or id of the network ACL" ,
6060 },
6161 "cidr" : {
6262 Type : schema .TypeString ,
@@ -77,16 +77,21 @@ func resourceCloudcaNetworkCreate(d *schema.ResourceData, meta interface{}) erro
7777 return nerr
7878 }
7979
80+ aclID , nerr := retrieveNetworkAclID (& ccaResources , d .Get ("network_acl" ).(string ), d .Get ("vpc_id" ).(string ))
81+ if nerr != nil {
82+ return nerr
83+ }
84+
8085 networkToCreate := cloudca.Network {
8186 Name : d .Get ("name" ).(string ),
8287 Description : d .Get ("description" ).(string ),
8388 VpcId : d .Get ("vpc_id" ).(string ),
8489 NetworkOfferingId : networkOfferingId ,
85- NetworkAclId : d . Get ( "network_acl_id" ).( string ) ,
90+ NetworkAclId : aclID ,
8691 }
8792 options := map [string ]string {}
88- if orgId , ok := d .GetOk ("organization_code" ); ok {
89- options ["org_id" ] = orgId .(string )
93+ if orgID , ok := d .GetOk ("organization_code" ); ok {
94+ options ["org_id" ] = orgID .(string )
9095 }
9196 newNetwork , err := ccaResources .Networks .Create (networkToCreate , options )
9297 if err != nil {
@@ -131,7 +136,7 @@ func resourceCloudcaNetworkRead(d *schema.ResourceData, meta interface{}) error
131136 d .Set ("description" , network .Description )
132137 setValueOrID (d , "network_offering" , offering .Name , network .NetworkOfferingId )
133138 d .Set ("vpc_id" , network .VpcId )
134- d . Set ( "network_acl_id" , network .NetworkAclId )
139+ setValueOrID ( d , "network_acl" , network . NetworkAclName , network .NetworkAclId )
135140 d .Set ("cidr" , network .Cidr )
136141 return nil
137142}
@@ -153,8 +158,12 @@ func resourceCloudcaNetworkUpdate(d *schema.ResourceData, meta interface{}) erro
153158 }
154159 }
155160
156- if d .HasChange ("network_acl_id" ) {
157- _ , aclErr := ccaResources .Networks .ChangeAcl (d .Id (), d .Get ("network_acl_id" ).(string ))
161+ if d .HasChange ("network_acl" ) {
162+ aclID , err := retrieveNetworkAclID (& ccaResources , d .Get ("network_acl" ).(string ), d .Get ("vpc_id" ).(string ))
163+ if err != nil {
164+ return err
165+ }
166+ _ , aclErr := ccaResources .Networks .ChangeAcl (d .Id (), aclID )
158167 if aclErr != nil {
159168 return aclErr
160169 }
@@ -201,3 +210,19 @@ func retrieveNetworkOfferingId(ccaRes *cloudca.Resources, name string) (id strin
201210 }
202211 return "" , fmt .Errorf ("Network offering with name %s not found" , name )
203212}
213+
214+ func retrieveNetworkAclID (ccaRes * cloudca.Resources , name , vpcID string ) (id string , err error ) {
215+ if isID (name ) {
216+ return name , nil
217+ }
218+ acls , err := ccaRes .NetworkAcls .ListByVpcId (vpcID )
219+ if err != nil {
220+ return "" , err
221+ }
222+ for _ , acl := range acls {
223+ if strings .EqualFold (acl .Name , name ) {
224+ return acl .Id , nil
225+ }
226+ }
227+ return "" , fmt .Errorf ("Network ACL with name %s not found" , name )
228+ }
0 commit comments