kohrar opened a new issue, #32:
URL: https://github.com/apache/cloudstack-terraform-provider/issues/32

   Greetings everyone.
   
   I ran into an issue where the assigned network_id doesn't get saved in the 
terraform.tfstate file. As a result, subsequent terraform applies will 
destroy/recreate the IP addresses because it thinks the network_id has changed.
   
   Edit: I'm using the latest version of this provider built against 
cloudstack-go v2.12. Terraform version 1.1.7. CloudStack version 4.16.1.
   
   Here is how I create an IP address:
   ```
   resource "cloudstack_ipaddress" "public_ip" { 
       count = "${var.num_vms_to_create}" 
    
       vpc_id = "${cloudstack_vpc.default.id}" 
       network_id = "${cloudstack_network.mynet.id}" 
   } 
   ```
   
   When applying this on multiple runs, Terraform will show the following (note 
that network_id is being added even though the resource is created properly in 
CloudStack):
   ```
   Terraform will perform the following actions:
   
     # cloudstack_ipaddress.public_ip[2] must be replaced
   -/+ resource "cloudstack_ipaddress" "public_ip" {
         ~ id            = "c823415a-32d4-4fe1-ac7d-65e5c38b5a6b" -> (known 
after apply)
         ~ ip_address    = "10.44.121.58" -> (known after apply)
         ~ is_source_nat = false -> (known after apply)
         + network_id    = "0aa28065-2d46-4367-a7c0-0e065218aea5" # forces 
replacement
         + project       = (known after apply)
         ~ tags          = {} -> (known after apply)
           # (2 unchanged attributes hidden)
       }
   ```
   
   The terraform.tfstate file lists the IP address with an empty network_id 
string.
   ```
       {   
         "mode": "managed", 
         "type": "cloudstack_ipaddress", 
         "name": "public_ip", 
         "provider": 
"provider[\"registry.terraform.io/cloudstack/cloudstack\"]", 
         "instances": [ 
           {   
             "index_key": 0,  
             "schema_version": 0,  
             "attributes": { 
               "id": "2bdbc636-f6cd-47cc-b462-ae76351b993e", 
               "ip_address": "10.44.120.53", 
               "is_portable": false, 
               "is_source_nat": false, 
               "network_id": "",            <----- shouldn't be empty
               "project": "", 
               "tags": {}, 
               "vpc_id": "5df887ba-9085-4d4b-a613-e6a7ba2e5ad4", 
               "zone": null 
             },  
             "sensitive_attributes": [], 
             "dependencies": [ 
               "cloudstack_network.mynet", 
               "cloudstack_network_acl.default", 
               "cloudstack_vpc.default" 
             ] 
           },  
   ```
   
   # Workaround
   I was able to 'fix' this issue by removing the conditional 
[`d.GetOk("network_id")`](https://github.com/apache/cloudstack-terraform-provider/blob/main/cloudstack/resource_cloudstack_ipaddress.go#L167)
 and always setting `network_id` based on the `Associatednetworkid` value from 
the CloudStack-go library. I'm not sure why that condition would be failing 
though.
   
   Any advice? Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@cloudstack.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to