You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/06/02 01:16:33 UTC

[GitHub] [cloudstack-terraform-provider] Damans227 opened a new pull request, #34: Add instance data source

Damans227 opened a new pull request, #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34

   Hello @Pearl1594 and @harikrishna-patnala. I'm opening this up as a draft PR to get some feedback. 
   
   I'm implementing a very basic data source to read Virtual Machine (Instance) resource, using the `instance_id` as an input in the terraform configuration file. Once I have this working successfully, I'll write different filters to extend its functionality and also remove all `log.Printf()` calls to make the code cleaner. 
   
   So, at the moment, I am able to associate resource data with `*schema.ResourceData`. This has been confirmed by running the `DEBUG` trace on the Terraform configuration file (main.tf) but when I try to read instance data using Terraform, the output block always returns `null`. I am trying to figure out why is that the case. Could you also pleas etake a look and suggest something? 
   
   I am attaching the main.tf and the logs I have captured. 
   
   From `main.tf`:
   
   ```
   data "cloudstack_instance" "my_instance" {
     instance_id="153aa39d-5f61-4cf8-8e17-687ee25807ff"
   
   
   }
   
   output "instance-output" {
     value = "${data.cloudstack_instance.my_instance}"
   }
   
   ```
   
   `terraform apply` output:
   
   ```
   ╷
   │ Warning: Provider development overrides are in effect
   │ 
   │ The following provider development overrides are set in the CLI configuration:
   │  - cloudstack/cloudstack in /home/darora/.terraform.d/plugins/cloudstack-dev/bin
   │  - edu/hashicups in /home/darora/.terraform.d/plugins/hashicorp.com/edu/hashicups/0.3.1/amd64
   │ 
   │ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible
   │ with published releases.
   ╵
   data.cloudstack_instance.my_instance: Reading...
   cloudstack_instance.instance-test-a: Refreshing state... [id=153aa39d-5f61-4cf8-8e17-687ee25807ff]
   cloudstack_instance.instance-test-c: Refreshing state... [id=9e68b9b1-5434-4cce-bfcf-d7d42b86adc8]
   cloudstack_instance.instance-test-b: Refreshing state... [id=ed55a876-f434-4aa1-840e-2e40249bf199]
   data.cloudstack_instance.my_instance: Read complete after 0s
   
   No changes. Your infrastructure matches the configuration.
   
   Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
   
   Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
   
   Outputs:
   
   instance-output = {
     "account" = tostring(null)
     "created" = tostring(null)
     "display_name" = tostring(null)
     "host_id" = tostring(null)
     "id" = tostring(null)
     "instance_id" = tostring(null)
     "name" = tostring(null)
     "state" = tostring(null)
     "zone_id" = tostring(null)
   }
   
   ```
   
   
   [Terraform_Refresh.log](https://github.com/apache/cloudstack-terraform-provider/files/8819723/Terraform_Refresh.log)
   
   


-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] Damans227 closed pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
Damans227 closed pull request #34: Add instance data source
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34


-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] harikrishna-patnala commented on pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
harikrishna-patnala commented on PR #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34#issuecomment-1144409096

   great start @Damans227, thanks. I will check and let you know


-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] Damans227 commented on pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
Damans227 commented on PR #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34#issuecomment-1145461162

   > great start @Damans227, thanks. I will check and let you know
   
   Yea nw man. I actually fixed it. There was a missing function `d.SetId()`. It is a function built into the `*schema.ResourceData` API which sets the ID of a resource. Non-blank IDs are what inform Terraform that a resource exists and can be read. 
   
   ```
    ~/cloudstack-dev/gh-issue-6016/instance 
    ❯ terraform apply  
   ╷
   │ Warning: Provider development overrides are in effect
   │ 
   │ The following provider development overrides are set in the CLI configuration:
   │  - cloudstack/cloudstack in /home/darora/.terraform.d/plugins/cloudstack-dev/bin
   │  - edu/hashicups in /home/darora/.terraform.d/plugins/hashicorp.com/edu/hashicups/0.3.1/amd64
   │ 
   │ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become
   │ incompatible with published releases.
   ╵
   data.cloudstack_instance.my_instance: Reading...
   cloudstack_instance.instance-test-b: Refreshing state... [id=ed55a876-f434-4aa1-840e-2e40249bf199]
   cloudstack_instance.instance-test-c: Refreshing state... [id=9e68b9b1-5434-4cce-bfcf-d7d42b86adc8]
   cloudstack_instance.instance-test-a: Refreshing state... [id=153aa39d-5f61-4cf8-8e17-687ee25807ff]
   data.cloudstack_instance.my_instance: Read complete after 0s [id=153aa39d-5f61-4cf8-8e17-687ee25807ff]
   
   No changes. Your infrastructure matches the configuration.
   
   Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
   
   Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
   
   Outputs:
   
   instance-output = {
     "account" = "admin"
     "created" = "2022-06-01T18:24:52+0000"
     "display_name" = "server-a"
     "host_id" = "24b1a694-9907-4d93-9f3a-583ed2380c21"
     "id" = "153aa39d-5f61-4cf8-8e17-687ee25807ff"
     "instance_id" = "153aa39d-5f61-4cf8-8e17-687ee25807ff"
     "state" = "Running"
     "zone_id" = "9a7002b2-09a2-44dc-a332-f2e4e7f01539"
   }
   
   ```


-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] Damans227 commented on a diff in pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
Damans227 commented on code in PR #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34#discussion_r894961017


##########
cloudstack/data_source_cloudstack_instance_test.go:
##########
@@ -22,45 +22,43 @@ package cloudstack
 import (
 	"testing"
 
-	"github.com/apache/cloudstack-go/v2/cloudstack"
 	"github.com/hashicorp/terraform/helper/resource"
-	"github.com/hashicorp/terraform/terraform"
 )
 
-func TestAccDataSourceCloudStackInstance_basic(t *testing.T) {
-	var instance cloudstack.VirtualMachine
+func TestAccInstanceDataSource_basic(t *testing.T) {

Review Comment:
   Test results: 
   
   ```
   
    ❯ TF_ACC=1 go test -v ./...
   
   === RUN   TestAccInstanceDataSource_basic
   --- PASS: TestAccInstanceDataSource_basic (55.73s)
   === RUN   TestProvider
   --- PASS: TestProvider (0.00s)
   
   ```



-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] Damans227 commented on pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
Damans227 commented on PR #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34#issuecomment-1153307248

   Hi @Pearl1594 and @harikrishna-patnala Could you please review this PR when you get a chance? Thanks! 
   
   Result of manually testing the provider binary for instance data source:
   
   
   **main.tf file used:** 
   
   ```
   resource "cloudstack_instance" "instance-test-a" {
     name             = "server-a"
     service_offering = "Small Instance"
     network_id       = "b9c953a0-8686-4240-b8a4-43849f7079ff"
     template         = "CentOS 5.5(64-bit) no GUI (KVM)"
     zone             = "DC"
   }
   
   data "cloudstack_instance" "my_instance" {
       filter {
       name = "name" 
       value = "server-a"
     }
       depends_on = [
       cloudstack_instance.instance-test-a
     ]
   
   }
   
   output "instance-output" {
     value = "${data.cloudstack_instance.my_instance}"
   }
   ```
   
   **Terraform apply output:** 
   
   ```
    ~/cloudstack-dev/gh-issue-6016/instance 
    ❯ terraform apply
   ╷
   │ Warning: Provider development overrides are in effect
   
   Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
   
   Outputs:
   
   instance-output = {
     "account" = "admin"
     "created" = "2022-06-12T22:10:14+0000"
     "display_name" = "server-a"
     "filter" = toset([
       {
         "name" = "name"
         "value" = "server-a"
       },
     ])
     "host_id" = "24b1a694-9907-4d93-9f3a-583ed2380c21"
     "id" = "db3084bc-8411-41fa-bc2b-90f28a1a3df8"
     "instance_id" = "db3084bc-8411-41fa-bc2b-90f28a1a3df8"
     "nic" = tolist([
       {
         "ip_address" = "10.1.1.154"
       },
     ])
     "state" = "Running"
     "tags" = tomap({})
     "zone_id" = "9a7002b2-09a2-44dc-a332-f2e4e7f01539"
   }
   
   ```


-- 
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-unsubscribe@cloudstack.apache.org

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


[GitHub] [cloudstack-terraform-provider] Damans227 commented on pull request #34: Add instance data source

Posted by GitBox <gi...@apache.org>.
Damans227 commented on PR #34:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/34#issuecomment-1155626994

   This PR is now continued on a new branch here: https://github.com/apache/cloudstack-terraform-provider/pull/38


-- 
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-unsubscribe@cloudstack.apache.org

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