SAP / terraform-provider-btp

Terraform provider for SAP BTP
https://registry.terraform.io/providers/SAP/btp/latest
Apache License 2.0
72 stars 12 forks source link

[Question] How terraform decide the resource match the definition? #789

Closed superwangnan closed 1 month ago

superwangnan commented 1 month ago

Is there an existing issue for this?

What version of the Terraform provider are you using?

1.2.0

What version of the Terraform CLI are you using?

1.8.2

What type of issue are you facing

bug report

Describe the bug

Hi team, In my case, I have existing resource in my trial account and when I read resource info from BTP the out put as following:

    {
      "mode": "data",
      "type": "btp_subaccounts",
      "name": "all",
      "provider": "provider[\"registry.terraform.io/sap/btp\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "6f5168f7trial-ga",
            "labels_filter": null,
            "values": [
              {
                "beta_enabled": false,
                "created_by": "",
                "created_date": "2024-01-30T05:01:44Z",
                "description": "",
                "id": "f842d609-2991-4eec-8efa-e7b5085df21b",
                "labels": null,
                "last_modified": "2024-01-30T05:02:04Z",
                "name": "trial",
                "parent_features": null,
                "parent_id": "1458b4b5-f4a1-4bf6-b252-a4ae365d3146",
                "region": "us10",
                "state": "OK",
                "subdomain": "6f5168f7trial",
                "usage": "UNSET"
              }
            ]

But when I define a new resource as following code

# create a subaccount in us10 region (GCP)
resource "btp_subaccount" "dev" {
  name      = "trial"
  subdomain = "6f5168f7trial"
  region    = "us10"

}

and run command terraform plan the output as following:

Terraform will perform the following actions:

  # btp_subaccount.dev will be created
  + resource "btp_subaccount" "dev" {
      + beta_enabled    = (known after apply)
      + created_by      = (known after apply)
      + created_date    = (known after apply)
      + description     = (known after apply)
      + id              = (known after apply)
      + last_modified   = (known after apply)
      + name            = "trial"
      + parent_features = (known after apply)
      + parent_id       = (known after apply)
      + region          = "us10"
      + state           = (known after apply)
      + subdomain       = "6f5168f7trial"
      + usage           = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

So, I want to know how we test the match of resource and plan definition? I expect my definition should match the exist resource in my case.

Thanks so much.

Expected Behavior

No response

Steps To Reproduce

No response

User's Role Collections

No response

Add screenshots to help explain your problem

No response

Additional context

No response

lechnerc77 commented 1 month ago

I am not sure, if I get what you want to achieve:

If you want to create two subaccounts with the same configuration you can use the data source to get all the data and then map the data to the mandatory and optional parameters of your resource configuration.

Other sceanrios: You can to some extent compare the data when comparing the states of these resources or the result of the data source when reading the data. However, as some computed values are date fields or GUIDs the comparison will not match 100%. In case you want to bring a resource under the management of Terraform, then you must {import](https://developer.hashicorp.com/terraform/language/import) the resource. The data in the state then matches the resource on BTP

A remark on reporting this as a bug: it would be appreciated if you can place questions into the GitHub Discussions and not report them as a bug.