oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
757 stars 680 forks source link

Error: can not marshal to path in request for field ConfigId. Due to can not marshal a nil pointer #2166

Open RizwaanShaik opened 3 months ago

RizwaanShaik commented 3 months ago

Community Note

Terraform Version and Provider Version

Terraform v1.9.3 on linux_amd64

Affected Resource(s)

Data Source: oci_apm_config_config

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. 
# Please remove any sensitive information from configuration files before sharing them. 
provider "oci" {
  config_file_profile = "DEFAULT"
}

data "oci_apm_config_config" "test_config" {
  apm_domain_id = "ocid1.apmdomain.oc1.iad.xxxxxxx"
  config_id     = "ocid1.apmconfig.oc1.iad.xxxxxxx"
}

output "final" {
  value = data.oci_apm_config_config.test_config
}

Debug Output

Panic Output

Expected Behavior

Output with current configuration of the apm_config, in this case Apdex Thresholds

Actual Behavior

Erroring out when taking in the paramter of ConfigId

Steps to Reproduce

  1. terraform plan

Important Factoids

References

Similar to the issue: https://github.com/oracle/terraform-provider-oci/issues/1726

tf-oci-pub commented 3 months ago

Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.

iliassox commented 3 months ago

The config_id is using the wring format. It should be something like configs/ocid1.apmconfig.oc1.iad.xxxxxxx/apmDomainId/ocid1.apmdomain.oc1.iad.xxxxxxx. Or you can use the variables, like in the official example after creating the resource: https://registry.terraform.io/providers/oracle/oci/latest/docs/data-sources/apm_config_config

RizwaanShaik commented 2 months ago

Thank you for the response @iliassox

This is the Json Response I fetched using API from the browser where it does a GET call to fetch Apdex Thresholds from where I was able to extract the configId and the display name as you cannot access them directly from the OCI console.

  "items" : [ {
    "configType" : "APDEX",
    "id" : "ocid1.apmconfig.oc1.iad.aaaaaaaamaqh333xd6yjf4uzkerg33ipt4tajonwzgqyvosoohkbyta",
    "timeCreated" : "2023-10-18T13:29:43.159Z",
    "timeUpdated" : "2023-10-18T13:29:43.159Z",
    "createdBy" : null,
    "updatedBy" : null,
    "etag" : "4d7f50e601e21a0b1a4101e6bf15dd003606111717d04c474bba19deabd5a425",
    "freeformTags" : { },
    "definedTags" : { },
    "rules" : [ {
      "filterText" : "Component='BROWSER' AND ApmrumType='Page'",
      "priority" : 0,
      "isEnabled" : true,
      "satisfiedResponseTime" : 2000,
      "toleratingResponseTime" : 6000,
      "isApplyToErrorSpans" : false,
      "displayName" : "Page Loads"
    }, {
      "filterText" : "Component='BROWSER' AND ApmrumPageUpdateType='Full Update'",
      "priority" : 1,
      "isEnabled" : true,
      "satisfiedResponseTime" : 1500,
      "toleratingResponseTime" : 4500,
      "isApplyToErrorSpans" : false,
      "displayName" : "Full Page Updates"
    }, {
      "filterText" : "Component='BROWSER' AND ApmrumPageUpdateType='Partial Update'",
      "priority" : 2,
      "isEnabled" : true,
      "satisfiedResponseTime" : 1000,
      "toleratingResponseTime" : 3000,
      "isApplyToErrorSpans" : false,
      "displayName" : "Partial Page Updates"
    }, {
      "filterText" : "Component='BROWSER' AND ApmrumType='Ajax'",
      "priority" : 3,
      "isEnabled" : true,
      "satisfiedResponseTime" : 500,
      "toleratingResponseTime" : 1500,
      "isApplyToErrorSpans" : false,
      "displayName" : "Ajax Calls"
    }, {
      "filterText" : "kind='SERVER'",
      "priority" : 4,
      "isEnabled" : true,
      "satisfiedResponseTime" : 500,
      "toleratingResponseTime" : 2000,
      "isApplyToErrorSpans" : false,
      "displayName" : "Server Requests"
    } ],
    "displayName" : "Apdex Rules"
  } ]
}

And this issue is specific only to Apdex Thresholds, I am able to use terraform for other apmconfig resources like Span Enrichments, Span Filters, Custom Metrics without any issues.

And I'm also able to fetch the same data using OCI_CLI

Note: I have truncated a few characters in the value of id for security reasons

iliassox commented 2 months ago

Can you try changing your terraform file to have something like this:

...
data "oci_apm_config_config" "test_config" {
  apm_domain_id = "ocid1.apmdomain.oc1.iad.xxxxxxx"
  config_id     = "configs/ocid1.apmconfig.oc1.iad.xxxxxxx/apmDomainId/ocid1.apmdomain.oc1.iad.xxxxxxx"
}
...

Where ocid1.apmdomain.oc1.iad.xxxxxxx is the domain id to which the config belongs.

I was able to reproduce the issue, and this change seems to have worked!

iliassox commented 2 months ago

You can also use a script that creates the config and you use the values from the created resources which also works:

resource "oci_apm_config_config" "test_apdex" {
  #Required
  apm_domain_id = oci_apm_apm_domain.test_apm_domain.id
  config_type   = "APDEX"
  display_name  = "configDisplayName"

  rules {
      display_name = var.rule_display_name
      filter_text = var.rule_filter_text
      is_apply_to_error_spans = var.rule_is_apply_to_error_spans
      is_enabled = var.rule_is_enabled
      priority = var.rule_priority
      satisfied_response_time = var.rule_satisfied_response_time 
      tolerating_response_time = var.rule_tolerating_response_time 
  }
}

data "oci_apm_config_config" "test_config" {
  apm_domain_id = oci_apm_apm_domain.test_apm_domain.id
  config_id = oci_apm_config_config.test_apdex.id
}

This is from this documentation

RizwaanShaik commented 2 months ago

Thanks a lot @iliassox. After trying out the change you suggested, I was able to get the data as output. I actually never came across the format of the configIds in any documentation I'll have to modify my code to match this change. Thank you. Closing this issue.

RizwaanShaik commented 2 months ago

Hi @iliassox, our primary objective was to automate the creation and updating of Apdex Threshold configurations using Terraform. However, we’ve encountered a limitation in OCI where the Apdex ruleset is a singleton and must always be present, causing issues with Terraform as it attempts to create the resource on the first run. Is there a workaround for this? Perhaps by creating a dummy tfstate file to bypass the initial run, or by directly calling the update Apdex API instead of the create API?

iliassox commented 2 weeks ago

Hello @RizwaanShaik , sorry for the delay. I'm not sure what you mean exactly, could you provide a more concrete example of what you mean?

RizwaanShaik commented 1 week ago

@iliassox Our primary goal was to create a new Apdex ruleset in our APM domain. However, when I attempt this with Terraform, I encounter an error indicating that the ruleset already exists. This happens because the Apdex ruleset is treated as a singleton, meaning only one instance can exist at any time. As a result, there isn’t a straightforward way to create a new Apdex ruleset; the only option is to modify the existing one. I wanted to reach out and see if anyone knows of a possible workaround for this.