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

Improve Experience of Renaming / Moving Constructs #219

Closed
skorfmann opened this issue Jul 20, 2020 · 7 comments · Fixed by #3152
Closed

Improve Experience of Renaming / Moving Constructs #219

skorfmann opened this issue Jul 20, 2020 · 7 comments · Fixed by #3152
Labels
cdktf enhancement New feature or request feature/refactoring priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month ux/configuration
Milestone

Comments

@skorfmann
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Given the following Construct

  const api = new AppsyncGraphqlApi(this, 'GraphQL', {
      authenticationType: 'AMAZON_COGNITO_USER_POOLS',
      name: 'cdk.dev',
      schema,
      userPoolConfig: [{
        defaultAction: 'DENY',
        userPoolId: userPool.id!
      }]
    })

When renaming its Construct id from GraphQL to GraphQL1 the resource gets recreated by Terraform since the Terraform resource name changes from cdkdev_GraphQL_E4BC4DB4 to cdkdev_GraphQL1_A79E37DD. This applies not only to renaming, but also when refactoring and moving a Construct into another Construct and therefore changing its position in the Construct tree.

Terraform Plan excerpt

    {
      "address": "aws_appsync_graphql_api.cdkdev_GraphQL1_A79E37DD",
      "mode": "managed",
      "type": "aws_appsync_graphql_api",
      "name": "cdkdev_GraphQL1_A79E37DD",
      "provider_name": "aws",
      "change": {
        "actions": [
          "create"
        ],
        "before": null,
        "after": {
          "additional_authentication_provider": [],
          "authentication_type": "AMAZON_COGNITO_USER_POOLS",
          "log_config": [],
          "name": "cdk.dev",
          "openid_connect_config": [],
          "schema": "\n      schema {\n        query: Query\n      }\n\n      type Query {\n        test: Int,\n        snippet: Snippet!\n      }\n\n      type Snippet {\n        id: ID!\n        author: String!\n        title: String!\n        content: String!\n      }\n  ",
          "tags": null,
          "user_pool_config": [
            {
              "app_id_client_regex": null,
              "default_action": "DENY",
              "user_pool_id": "eu-central-1_Uieh1GWj0"
            }
          ],
          "xray_enabled": null
        },
        "after_unknown": {
          "additional_authentication_provider": [],
          "arn": true,
          "id": true,
          "log_config": [],
          "openid_connect_config": [],
          "uris": true,
          "user_pool_config": [
            {
              "aws_region": true
            }
          ]
        }
      }
    },
    {
      "address": "aws_appsync_graphql_api.cdkdev_GraphQL_E4BC4DB4",
      "mode": "managed",
      "type": "aws_appsync_graphql_api",
      "name": "cdkdev_GraphQL_E4BC4DB4",
      "provider_name": "aws",
      "change": {
        "actions": [
          "delete"
        ],
        "before": {
          "additional_authentication_provider": [],
          "arn": "arn:aws:appsync:eu-central-1:412153864843:apis/xxx",
          "authentication_type": "AMAZON_COGNITO_USER_POOLS",
          "id": "xxx",
          "log_config": [],
          "name": "cdk.dev",
          "openid_connect_config": [],
          "schema": "\n      schema {\n        query: Query\n      }\n\n      type Query {\n        test: Int,\n        snippet: Snippet!\n      }\n\n      type Snippet {\n        id: ID!\n        author: String!\n        title: String!\n        content: String!\n      }\n  ",
          "tags": {},
          "uris": {
            "GRAPHQL": "https://xxx.appsync-api.eu-central-1.amazonaws.com/graphql",
            "REALTIME": "wss://xxx.appsync-realtime-api.eu-central-1.amazonaws.com/graphql"
          },
          "user_pool_config": [
            {
              "app_id_client_regex": "",
              "aws_region": "eu-central-1",
              "default_action": "DENY",
              "user_pool_id": "eu-central-1_Uieh1GWj0"
            }
          ],
          "xray_enabled": false
        },
        "after": null,
        "after_unknown": {}
      }
    },

I think it would desirable to make this a smoother experience. There are various approaches to this, here are two which came to my mind:

  • Provide a helper to rename resources easily
  • Autodetect moved resources (similar to what Git does with renamed files)
@skorfmann skorfmann added the enhancement New feature or request label Jul 20, 2020
@sam-goodwin
Copy link

For the git algorithm, what would you be comparing to?

@skorfmann
Copy link
Contributor Author

For the git algorithm, what would you be comparing to?

I think a plan file contains all the information which is required, so there shouldn't be a need to pull the entire state from remote backends.

@DanielMSchmidt DanielMSchmidt added needs-priority Issue has not yet been prioritized; this will prompt team review size/large estimated < 1 month ux/configuration labels Dec 7, 2021
@DanielMSchmidt DanielMSchmidt added priority/important-soon High priority, to be worked on as part of our current release or the following one. and removed needs-priority Issue has not yet been prioritized; this will prompt team review labels Feb 17, 2022
@DJAlPee
Copy link

DJAlPee commented Oct 18, 2022

There is something available directly in Terraform: https://www.terraform.io/language/modules/develop/refactoring
Would be great, if moved could be added to CDKTF as well (which would solve this issue?!).

@ansgarm
Copy link
Member

ansgarm commented Oct 18, 2022

Yep! That one will probably help with implementing this feature.
Here are two other related issues tracking specifically the moved block: #1292, #1102

@xiehan xiehan added priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. and removed priority/important-soon High priority, to be worked on as part of our current release or the following one. labels Jun 1, 2023
@xiehan xiehan added this to the 0.19 (tentative) milestone Jul 20, 2023
@ansgarm
Copy link
Member

ansgarm commented Sep 6, 2023

Idea: To make simple renaming easier we could add a helper that creates a moved block:

const api = new AppsyncGraphqlApi(this, 'GraphQL', {
      authenticationType: 'AMAZON_COGNITO_USER_POOLS',
      name: 'cdk.dev',
      schema,
      userPoolConfig: [{
        defaultAction: 'DENY',
        userPoolId: userPool.id!
      }]
    })

rename(api, "GraphQL1")
// or
api.rename("GraphQL1") // beware name collisions with a potential rename argument/attribute
// or
oldNameWas(api, "GraphQL0")

@dr0l3
Copy link

dr0l3 commented Sep 13, 2023

That would solve all my problems.

oldNameWas either as method or function looks significantly superior because the resources current name doesn't change location. rename(construct, "newname"), and construct.rename("new-name") all have the problem that the name of the resource is effectively moved to after the resources. This means that when you read a resource the only way to know if that is still the resources actual name is by checking current usages of the resource. With the oldNameWas its always clear what the current name is.

Alternatively could just call it by its tf name

const api = new AppsyncGraphqlApi(this, 'GraphQL1', {
      ...
    }).moved("GraphQL")

or

const api = new AppsyncGraphqlApi(this, 'GraphQL1', {
      ...
    }).movedFrom("GraphQL")

Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cdktf enhancement New feature or request feature/refactoring priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month ux/configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants