scastria / terraform-provider-apigee

Mozilla Public License 2.0
20 stars 17 forks source link

target server resource errors on second tf apply #39

Closed mattboschatliveoak closed 2 years ago

mattboschatliveoak commented 2 years ago

@scastria thanks for providing this apigee provider! I started testing the creation of apigee resources, but have run into an issue with the target server resource.

Following the successful creation of a target server with the following config:

resource "apigee_target_server" "example" {
  environment_name = var.apigee_environment_name
  name = "tftest"
  host = "auth.company.com"
  port = 443
  is_enabled = true
  ssl_enabled = true
  ssl_ignore_validation_errors = false
}

Subsequent executions of terraform apply result with the following error:

apigee_target_server.example: Refreshing state... [id=env1:tftest]
╷
│ Error: json: cannot unmarshal bool into Go struct field SSL.sSLInfo.enabled of type string
│ 
│   with apigee_target_server.example,
│   on main.tf line 40, in resource "apigee_target_server" "example":
│   40: resource "apigee_target_server" "example" {
│ 
╵
scastria commented 2 years ago

What version of Apigee are you using? The difficulty with this provider is that there are 3 versions of Apigee, each with slightly different REST APIs. Therefore, the provider has to tweak its REST API calls to match the version of Apigee it is taking to.

I don’t have access to all three versions so I can’t test very well. And when I say version, I don’t mean a number. I am referring to this page: https://registry.terraform.io/providers/scastria/apigee/latest/docs

mattboschatliveoak commented 2 years ago

I am running Apigee on Google Cloud (ApigeeX). This is the API call and result for getting a specific target server:

curl -s -H "Authorization: Bearer $TOKEN" -X GET "https://apigee.googleapis.com/v1/organizations/<org>/environments/<env>/targetservers/tftest"
{
  "name": "tftest",
  "host": "auth.company.com",
  "port": 443,
  "isEnabled": true,
  "sSLInfo": {
    "enabled": true
  },
  "protocol": "HTTP"
}
swapna0211950 commented 2 years ago

Hi @scastria , Even i'm facing the same issue. Could you please help us in getting this issue resolved.

swapna0211950 commented 2 years ago

@scastria issue looks like when apigee sends a response about targetserver details on ssl enabled is a boolean value. But in the go template that is being used for terraform it is expecting a string. Can you please debug the issue and make possible changes on this side to fix the issue.

swapna0211950 commented 2 years ago

@mattboschatliveoak, Please let me know if you have fixed this issue already. Please do provide the steps regarding what you have done to fix it. This is blocking our CICD pipeline implementation for Apigee. Any help would be really great.

swapna0211950 commented 2 years ago

@scastria for fixing this issue should we consider changing the https://github.com/scastria/terraform-provider-apigee/blob/main/apigee/client/ssl_info.go#L4 field to bool? Please share your thoughts.

scastria commented 2 years ago

Sure, but only for your Apigee version. I still need it to be a string for my version. I have done this type of selective change in other resource types so shouldn’t be a problem.

swapna0211950 commented 2 years ago

@scastria thanks for the response. How to change the field type to bool for a particular version. I'm not very sure on that. Could you please mention the steps for this.

swapna0211950 commented 2 years ago

@scastria please help fixing this issue. As we are not able to deploy SSL enabled targetservers to Apigee X using this terraform provider.

scastria commented 2 years ago

Try version v0.1.47 when it is done building. I don't have access to a Google server for Apigee X so I cannot test. I did test that it doesn't break my old OPDK Apigee server. I also noticed there was a difference between string and boolean for clientAuthEnabled so I fixed that too.

swapna0211950 commented 2 years ago

Above version fixed the issue. Thanks @scastria.