Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env0_agent_values data source doesn't fetch values #690

Closed
amit-alkobi-env0 opened this issue Aug 13, 2023 · 5 comments · Fixed by #694
Closed

env0_agent_values data source doesn't fetch values #690

amit-alkobi-env0 opened this issue Aug 13, 2023 · 5 comments · Fixed by #694
Assignees
Labels
bug Something isn't working

Comments

@amit-alkobi-env0
Copy link

amit-alkobi-env0 commented Aug 13, 2023

Motivation / Problem / The Why❔:

Getting agent details using the env0_agent_values doesn't work

How to reproduce:

Run the following TF file, provide env0_api_key_id, env0_api_key_value and http_auth as TF_VAR.
http_auth is Basic <the api key and value encoded in base64>, use the widget in our API reference to calculate it:
image


locals {
  api_endpoint    = <fill>
  kushield_env_org_id = <fill>
  agent_key = "my-agent-key"
}

variable "env0_api_key_id" {}
variable "env0_api_key_value" {}
variable "http_auth" {}

terraform {
  required_providers {
    env0 = {
      source = "env0/env0"
    }
    http = {
      source = "hashicorp/http"
      version = "3.4.0"
    }
  }
}

output "api_endpoint" {
  value = local.api_endpoint
}

output "api_key_id" {
  value = var.env0_api_key_id
}

provider "env0" {
  api_key      = var.env0_api_key_id
  api_secret   = var.env0_api_key_value
  api_endpoint = local.api_endpoint
  organization_id = local.kushield_env_org_id
}

data "env0_agent_values" "agent_details" {
  agent_key = local.agent_key
}

output "shag_dev_agent_details" {
  value = data.env0_agent_values.agent_details.values
}

data "http" "agent_details_http" {
  url    = format("https://api-dev.dev.env0.com/agents/%s/values", local.agent_key)
  method = "GET"
  request_headers = {
    accept: "application/json"
    authorization: var.http_auth
    content-type: "application/json"
  }
}

output "http_example_response" {
  value = data.http.agent_details_http.response_body
}

It is expected that output "agent_details" will print all the agent's details, but it doesn't.
Also, data "http" "agent_details_http" which hit the same API EP, does fetch the values, it can be seen by output "http_example_response".


Changes to Outputs:
  + api_endpoint           = <...>
  + api_key_id             = <...>
  + http_example_response  = <<-EOT
        "agentKey": "my-agent-key"
        "agentProxy":
          "install": true
        "apiGatewayUrl": <...>
        "awsAccessKeyIdEncoded": <...>
        "awsSecretAccessKeyEncoded": <...>
        "awsSecretsRegion": "us-east-1"
        "cryptoKmsKeyId": <...>
        "deploymentPodWarmPoolSize": 0
        "deploymentResultSqsUrl": <...>
        "deploymentTriggerSqsUrl": <...>
        "env0ApiGwKeyEncoded": <...>
        "eventsTopicArn":<...>
        "httpProxyRequestSqsUrl": <...>
        "httpProxyResponseBucketName": <...>
        "isSelfHosted": "true"
        "limits":
          "cpu": "460m"
          "memory": "1500Mi"
        "outputLogsLogGroupName": <...>
        "prerequisitesStackName": <...>
        "region": "us-east-1"
        "sharedStackPrefix": <...>
        "stage": <...>
        "stateMountPath": <...>
    EOT
  + agent_details = {
      + agent_key = "my-agent-key"
      + id        = "my-agent-key"
      + values    = ""
    }

Expected Result / DoD ✅:

"env0_agent_values" works as expected.

@TomerHeber
Copy link
Collaborator

TomerHeber commented Aug 13, 2023

Shouldn't the output be:
instead of

output "shag_dev_agent_details" {
  value = data.env0_agent_values.shag_dev_agent
}

should be

output "shag_dev_agent_details" {
  value = data.env0_agent_values.agent_details.values
}

(returned as string).

@amit-alkobi-env0
Copy link
Author

It should, still returns an empty string

@TomerHeber
Copy link
Collaborator

@amit-alkobi-env0 - I reviewed it, and I don't see any issues with the code.
We may need to find some time to troubleshoot it together. Currently, I don't see any issues.

@amit-alkobi-env0
Copy link
Author

Were you able to reproduce it?

@TomerHeber
Copy link
Collaborator

@amit-alkobi-env0 - I don't have an environment with an agent, and therefore cannot test it out.

@TomerHeber TomerHeber self-assigned this Aug 15, 2023
@TomerHeber TomerHeber added the bug Something isn't working label Aug 15, 2023
@TomerHeber TomerHeber added this to To do in Ongoing Issues via automation Aug 15, 2023
Ongoing Issues automation moved this from To do to Done Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants