Skip to content

feat(generate): generate terraform imports - #908

Open
miton18 wants to merge 1 commit into
masterfrom
feat/tf-import
Open

miton18 wants to merge 1 commit into
masterfrom
feat/tf-import

Conversation

@miton18

@miton18 miton18 commented Apr 17, 2025

Copy link
Copy Markdown
Contributor
  • install clever-tools from this PR
  • install TF
  • write provider.tf
  • run terraform init
  • run clever-tools generate terraform -o orga_xxx > import.tf
  • terraform plan -generate-config-out=generated.tf
  • generated.tf must have all your resources

provider.tf

terraform {  
  required_providers {
    clevercloud = {
      source = "CleverCloud/clevercloud"
      version = "0.7.1"
    }
  }
}
 
provider "clevercloud" {
   # Configuration options
}

Some imports fails see CleverCloud/terraform-provider-clevercloud#134

@miton18
miton18 requested a review from a team as a code owner April 17, 2025 15:01
@miton18
miton18 force-pushed the feat/tf-import branch 2 times, most recently from c95b03a to d79a490 Compare April 17, 2025 15:52
@github-actions

github-actions Bot commented Apr 17, 2025

Copy link
Copy Markdown

🔎 A preview has been automatically published:

  • 🐧 linux 7fdc3af9e12b65cfd8d062951485967ee02523bb3d72c67cdb50002a71e06a76
  • 🍏 macos 159b962f2298602ed9b41157bcf87550f726ed15dc00f674b0dd8ab659c0b5be
  • 🪟 win fb7f073c3087bbe82e893b89627e799fe2bd663a68cd0230da4c510e39055df5

This preview will be deleted once this PR is closed.

@miton18
miton18 force-pushed the feat/tf-import branch 2 times, most recently from ba7d284 to 23482a3 Compare April 23, 2025 16:59
Comment thread src/commands/generate-terraform.js Outdated
if (instanceType === 'node') {
instanceType = 'nodejs';
}
if (instanceType === 'java' && app.variantSlug === 'sbt') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool !

Comment thread src/commands/generate-terraform.js Outdated
}

let id = addon.realId;
if (addon.resourceKind === 'mongodb') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be the same issue with postgresql_UUID ids.

Also, running the binaries from "preview" I did not see any effect of this code.
Should it happen after resourceKind: providerId.replaceAll('-addon', '').replaceAll('addon-', '') ?

@gnoireaux

Copy link
Copy Markdown

Hello @miton18 ,

Rachel asked me to put my feedback here.
Thanks for your work ! It's useful for us not to have to spend hours copy-pasting. (and making mistakes!)

It would be quite useful to get the env. vars. too ! (and dependancies if possible) But maybe it is a job on Terraform's side ?

@gnoireaux

Copy link
Copy Markdown

Cellar

It's not so important (for us since we don't have so many cellars) but for your information, there is an issue with cellar's

terraform outputs an error to the console:

│ Error: Missing Configuration for Required Attribute
│
│   with clevercloud_cellar.cellardevstghds-cellar,
│   on generated.tf line 1:
│   (source code not available)
│
│ Must set a configuration value for the name attribute as the provider has marked it as required.
│
│ Refer to the provider documentation or contact the provider developers for additional information about configurable attributes that are
│ required.

and the file's contents aren't so helpful

# __generated__ by Terraform
resource "clevercloud_cellar" "cellardevstghds-cellar" {
  name   = null
  region = null
}

@gnoireaux

Copy link
Copy Markdown

PG (FYI)

modified by hand:

# ztest-ubilab-playground-for-restore
import {
  to = clevercloud_postgresql.ztest-ubilab-playground-for-restore
  id = "addon_f9a55fce-af2e-418c-bded-58c6b04e38cb"
}

ran terraform, with similar error than for a cellar

│ Error: Missing Configuration for Required Attribute
│
│   with clevercloud_postgresql.ztest-ubilab-playground-for-restore,
│   on generated.tf line 1:
│   (source code not available)
│
│ Must set a configuration value for the name attribute as the provider has marked it as required.
│
│ Refer to the provider documentation or contact the provider developers for additional information about configurable attributes that are
│ required.

there is a bit more content in the file generated.tf

# __generated__ by Terraform
resource "clevercloud_postgresql" "ztest-ubilab-playground-for-restore" {
  name   = null
  plan   = "s_hug"
  region = "par"
}

@miton18
miton18 force-pushed the feat/tf-import branch 2 times, most recently from 1b99114 to 260e0d9 Compare May 26, 2025 08:22
@hsablonniere hsablonniere added this to the 3.14 milestone May 27, 2025
@hsablonniere hsablonniere removed this from the After rework/refacto milestone Jan 23, 2026
Add a new command 'clever terraform generate' that outputs Terraform import blocks for Clever Cloud resources.

Features:
- Generate import blocks for applications and addons
- Filter by organization (--org)
- Filter by application (--app)
- Filter by tag (--tag)
- Allowlist of supported apps and addons
- Automatic name normalization using slugify
- Skip resources with invalid names (starting with numbers)

The output can be used with Terraform to import existing Clever Cloud resources:
  clever terraform generate -o org_xxx > import.tf
  terraform plan -generate-config-out=generated.tf

Related to #908
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown

🔎 A preview has been automatically published!

If you created the alias to the preview script, you can run this command to download and install this preview:

clever-preview update feat-tf-import

You can also run it from your local repository:

./scripts/preview.js update feat-tf-import
OS SHA256 checksum
🐧 linux b088cbf277d9f3449d6fb98d5a66ffe450f28a9f1cce2ee1d41e18afc2bbff4b
🍏 macos acdf70e157f897c832162266282ec1c04b684f497b3879aeaaba5eff358f4c1b

This preview will be deleted once this PR is closed.

@hsablonniere hsablonniere modified the milestone: 5.0.0 Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants