6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IntelliJ の Terraform プラグインでカスタムプロバイダの定義を補完できるようにする

Posted at

IntelliJ の Terraform / HCL プラグインではリソース名や属性の補完ができて便利なのですが、カスタムプロバイダは補完が効かず不便です。

どうやらスキーマ定義の JSON ファイルを然るべき場所に置けば認識されるらしいのですが、肝心の JSON ファイルの作り方のドキュメントがありません。

プラグインのソースを眺めていたら、無理やり JSON ファイルを生成できたのでまとめておきます。

以下、terraform-provider-sakuracloud プロバイダのスキーマ定義を生成する例です。

  1. Go をインストールして $GOPATH を設定する

  2. terraform-provider-sakuracloud のソースをダウンロードする

    $ go get github.com/sacloud/terraform-provider-sakuracloud
    
  3. intellij-hcl のソースをダウンロードして schemas-extractor ディレクトリに移動

    $ git clone https://github.com/VladRassokhin/intellij-hcl.git
    $ cd intellij-hcl/schemas-extractor
    
  4. terraform-provider-sakuracloud を対象にするようコードを書き換える

    $ sed -i -e 's/terraform-providers/sacloud/g' build-all.sh template/generate-schema.go
    $ echo terraform-provider-sakuracloud > providers.list.full
    
  5. スキーマ定義ファイルを生成する

    $ make
    Updating terraform-provider-sakuracloud
    
    ========================================
    Waiting for update processes to finish
    All providers updated
    
    Preparing terraform-provider-sakuracloud
    fatal: No annotated tags can describe '36fd67475a6f3b9e53da8e9d45f579a37b1720d5'.
    However, there were unannotated tags: try --tags.
    Generating schema for terraform-provider-sakuracloud
    Finished terraform-provider-sakuracloud
    ========================================
    Everything done!
    
  6. できたスキーマ定義ファイルをインストール

    $ mkdir -p ~/.terraform.d/schemas
    $ cp schemas/sakuracloud.json ~/.terraform.d/schemas
    
  7. IntelliJ を再起動

参考: Document support for custom providers #128

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?