diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1bedc5e591..7fde1e2fcb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,14 +27,27 @@ jobs: run: git config --global --add safe.directory /__w/terraform-cdk/terraform-cdk - name: ensure correct user run: chown -R root /__w/terraform-cdk - - name: Get yarn cache directory path + # Setup caches for yarn, and go + - name: Get cache directory paths id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-build + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + path: ${{ steps.global-cache-dir-path.outputs.go }} + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-build + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - name: install dependencies run: yarn install - name: build and package @@ -43,5 +56,4 @@ jobs: yarn package env: SENTRY_DSN: ${{ secrets.SENTRY_DSN }} - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 9733580cb5..d4268b0b4b 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -50,16 +50,35 @@ jobs: run: git config --global --add safe.directory /__w/terraform-cdk/terraform-cdk - name: ensure correct user run: chown -R root /__w/terraform-cdk - - name: Get yarn cache directory path + # Setup caches for yarn, terraform, and go + - name: Get cache directory paths id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/terraform + echo "terraform=/usr/local/share/.cache/terraform" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-examples + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.terraform }} + key: terraform-${{ runner.os }}-${{ matrix.terraform }}-examples + restore-keys: | + terraform-${{ runner.os }}-${{ matrix.terraform }} - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-examples-yarn-${{ hashFiles('**/yarn.lock') }} + path: ${{ steps.global-cache-dir-path.outputs.go }} + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-examples restore-keys: | - ${{ runner.os }}-examples-yarn- + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - name: installing dependencies run: | yarn install --frozen-lockfile --prefer-offline @@ -72,8 +91,8 @@ jobs: run: yarn build env: TERRAFORM_BINARY_NAME: "terraform${{ matrix.terraform }}" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} - name: create bundle run: yarn package - name: examples integration tests @@ -83,5 +102,5 @@ jobs: TEST_TARGET: "${{ matrix.target }}" TERRAFORM_BINARY_NAME: "terraform${{ matrix.terraform }}" MAVEN_OPTS: "-Xmx3G" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index c6a0085094..304ea1dd94 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -33,18 +33,29 @@ jobs: run: git config --global --add safe.directory /__w/terraform-cdk/terraform-cdk - name: ensure correct user run: chown -R root /__w/terraform-cdk - - name: Get yarn cache directory path + # Setup caches for yarn, and go + - name: Get cache directory paths id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-integration + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-integration-yarn-${{ hashFiles('**/yarn.lock') }} + path: ${{ steps.global-cache-dir-path.outputs.go }} + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-integration + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - name: install dependencies run: yarn install --frozen-lockfile --prefer-offline - env: - YARN_CACHE_FOLDER: ${{ steps.global-cache-dir-path.outputs.dir }} - name: set version if: ${{ !inputs.skip_setup }} run: tools/align-version.sh "-dev.$GITHUB_RUN_ID" @@ -55,8 +66,7 @@ jobs: yarn package env: SENTRY_DSN: ${{ secrets.SENTRY_DSN }} - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} - name: Upload dist uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce if: ${{ !inputs.skip_setup }} @@ -72,8 +82,6 @@ jobs: - name: installing test dependencies run: | cd test && yarn install --frozen-lockfile --prefer-offline - env: - YARN_CACHE_FOLDER: ${{ steps.global-cache-dir-path.outputs.dir }} - id: build-test-matrix run: | ./tools/build-test-matrix.sh @@ -95,16 +103,42 @@ jobs: steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - name: Get yarn cache directory path - id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - name: ensure correct user run: chown -R root /__w/terraform-cdk + # Setup caches for yarn, terraform, and go + - name: Get cache directory paths + id: global-cache-dir-path + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/terraform + echo "terraform=/usr/local/share/.cache/terraform" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-integration-yarn-${{ hashFiles('**/yarn.lock') }} + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-matrix-integration-${{ matrix.target }} + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-integration + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.terraform }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: terraform-${{ runner.os }}-${{ matrix.terraform }}-matrix-integration-${{ matrix.target }} + restore-keys: | + terraform-${{ runner.os }}-${{ matrix.terraform }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.go }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-matrix-integration-${{ matrix.target }} + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-integration + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }} + go-${{ runner.os }}- - name: Download dist uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: @@ -124,8 +158,8 @@ jobs: TERRAFORM_CLOUD_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }} TERRAFORM_BINARY_NAME: "terraform${{ matrix.terraform }}" NODE_OPTIONS: "--max-old-space-size=7168" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} windows_integration: needs: prepare-integration-tests @@ -143,15 +177,41 @@ jobs: steps: - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab - - name: Get yarn cache directory path + # Setup caches for yarn, terraform, and go + - name: Get cache directory paths id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT shell: bash + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/terraform + echo "terraform=/usr/local/share/.cache/terraform" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-matrix-integration-${{ matrix.target }} + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-integration + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.terraform }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: terraform-${{ runner.os }}-${{ matrix.terraform }}-matrix-integration-${{ matrix.target }} + restore-keys: | + terraform-${{ runner.os }}-${{ matrix.terraform }}- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-integration-yarn-${{ hashFiles('**/yarn.lock') }} + path: ${{ steps.global-cache-dir-path.outputs.go }} + # put matrix before integration to not restore caches from other sibling matrix jobs + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-matrix-integration-${{ matrix.target }} + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-integration + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - name: HashiCorp - Setup Terraform uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 with: @@ -185,5 +245,5 @@ jobs: TEST_TARGET: ${{ matrix.target }} TERRAFORM_CLOUD_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }} NODE_OPTIONS: "--max-old-space-size=7168" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} diff --git a/.github/workflows/provider-integration.yml b/.github/workflows/provider-integration.yml index e6d89bde31..8000a53e64 100644 --- a/.github/workflows/provider-integration.yml +++ b/.github/workflows/provider-integration.yml @@ -11,6 +11,11 @@ on: default: pr required: false type: string + terraform_version: + description: Version of Terraform to use + default: 1.2.8 + type: string + required: false concurrency: group: ${{ inputs.concurrency_group_prefix }}-provider-integration-${{ github.head_ref }} @@ -33,18 +38,27 @@ jobs: run: git config --global --add safe.directory /__w/terraform-cdk/terraform-cdk - name: ensure correct user run: chown -R root /__w/terraform-cdk - - name: Get yarn cache directory path + # Setup caches for yarn, and go + - name: Get cache directory paths id: global-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: - path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - - name: ensure all plugin directories exist - run: | - mkdir -p ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - mkdir -p ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-provider-integration + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.go }} + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-provider-integration + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - name: installing dependencies and build if: ${{ !inputs.skip_setup }} run: | @@ -53,9 +67,10 @@ jobs: yarn build yarn package env: - TERRAFORM_BINARY_NAME: "terraform${{ inputs.terraform_version }}" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} + - name: install test dependencies to warm up cache for matrix jobs to use + run: | + cd test && yarn - name: Upload dist if: ${{ !inputs.skip_setup }} uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce @@ -76,7 +91,8 @@ jobs: image: docker.mirror.hashicorp.services/hashicorp/jsii-terraform env: CHECKPOINT_DISABLE: "1" - TERRAFORM_VERSION: ${{ matrix.terraform }} + TERRAFORM_VERSION: ${{ inputs.terraform_version }} + TERRAFORM_BINARY_NAME: "terraform${{ inputs.terraform_version }}" timeout-minutes: 60 steps: @@ -88,6 +104,27 @@ jobs: path: dist - name: ensure correct user run: chown -R root /__w/terraform-cdk + - name: Get cache directory paths + id: global-cache-dir-path + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/terraform + echo "terraform=/usr/local/share/.cache/terraform" >> $GITHUB_OUTPUT + # Only restoring yarn caches as the dependencies are not indiviual to each matrix job + - uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-provider-integration + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.terraform }} + # put matrix before provider-integration to not restore caches from other sibling matrix jobs + key: terraform-${{ runner.os }}-${{ inputs.terraform_version }}-matrix-provider-integration-${{ matrix.target }} + restore-keys: | + terraform-${{ runner.os }}-${{ inputs.terraform_version }}- - name: install test dependencies run: cd test && yarn - name: integration tests @@ -95,8 +132,7 @@ jobs: env: TEST_TARGET: ${{ matrix.target }} NODE_OPTIONS: "--max-old-space-size=7168" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} windows_provider: needs: prepare-provider-tests @@ -106,7 +142,7 @@ jobs: matrix: ${{fromJSON(needs.prepare-provider-tests.outputs.tests)}} env: CHECKPOINT_DISABLE: "1" - TERRAFORM_VERSION: ${{ matrix.terraform }} + TERRAFORM_VERSION: ${{ inputs.terraform_version }} timeout-minutes: 60 steps: @@ -115,7 +151,7 @@ jobs: uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 with: terraform_wrapper: false - terraform_version: ${{ matrix.terraform }} + terraform_version: ${{ inputs.terraform_version }} - name: Install pipenv run: pip install pipenv - name: Install Go @@ -127,6 +163,28 @@ jobs: with: name: dist path: dist + - name: Get cache directory paths + id: global-cache-dir-path + shell: bash + run: | + echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/terraform + echo "terraform=/usr/local/share/.cache/terraform" >> $GITHUB_OUTPUT + # Only restoring yarn caches to save available cache storage size + - uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.yarn }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-provider-integration + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- + - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 + with: + path: ${{ steps.global-cache-dir-path.outputs.terraform }} + # put matrix before provider-integration to not restore caches from other sibling matrix jobs + key: terraform-${{ runner.os }}-${{ matrix.terraform }}-matrix-provider-integration-${{ matrix.target }} + restore-keys: | + terraform-${{ runner.os }}-${{ matrix.terraform }}- # tmp fix for https://github.com/npm/cli/issues/4980 - name: update npm run: npm install -g npm@8.12.1 @@ -137,5 +195,4 @@ jobs: env: TEST_TARGET: ${{ matrix.target }} NODE_OPTIONS: "--max-old-space-size=7168" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.dir }}/terraform-plugins - GOCACHE: ${{ steps.global-cache-dir-path.outputs.dir }}/go-cache + TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index ae34639d30..5b5970c0e4 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -41,25 +41,29 @@ jobs: id: global-cache-dir-path run: | echo "yarn=$(yarn cache dir)" >> $GITHUB_OUTPUT - echo "terraform=$(mktemp -d)" >> $GITHUB_OUTPUT - echo "go=$(mktemp -d)" >> $GITHUB_OUTPUT - echo "providerSchema=$(mktemp -d)" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/go + echo "go=/usr/local/share/.cache/go" >> $GITHUB_OUTPUT + mkdir -p /usr/local/share/.cache/providerSchema + echo "providerSchema=/usr/local/share/.cache/providerSchema" >> $GITHUB_OUTPUT - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: ${{ steps.global-cache-dir-path.outputs.yarn }} - key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} - - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - with: - path: ${{ steps.global-cache-dir-path.outputs.terraform }} - key: terraform-${{ runner.os }}-${{ inputs.terraform_version }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-unit-${{ inputs.package }} + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-unit- + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: ${{ steps.global-cache-dir-path.outputs.go }} - key: go-${{ runner.os }} + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-unit + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}- + go-${{ runner.os }}- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: ${{ steps.global-cache-dir-path.outputs.providerSchema }} - key: providerSchema-${{ runner.os }}-${{ inputs.terraform_version }} + key: providerSchema-${{ runner.os }}-${{ inputs.terraform_version }}-unit-${{ inputs.package }} - name: installing dependencies run: | @@ -71,13 +75,12 @@ jobs: yarn package env: TERRAFORM_BINARY_NAME: "terraform${{ inputs.terraform_version }}" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} - name: test run: | + unset TF_PLUGIN_CACHE_DIR npx lerna run --scope '${{ inputs.package }}' test:ci env: TERRAFORM_BINARY_NAME: "terraform${{ inputs.terraform_version }}" - TF_PLUGIN_CACHE_DIR: ${{ steps.global-cache-dir-path.outputs.terraform }} GOCACHE: ${{ steps.global-cache-dir-path.outputs.go }} CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH: ${{ steps.global-cache-dir-path.outputs.providerSchema }} diff --git a/.github/workflows/yarn-upgrade.yml b/.github/workflows/yarn-upgrade.yml index 5db9f7800c..195d82a253 100644 --- a/.github/workflows/yarn-upgrade.yml +++ b/.github/workflows/yarn-upgrade.yml @@ -21,10 +21,12 @@ jobs: id: global-cache-dir-path run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 - id: global-cache # use this to check for `cache-hit` (`steps.global-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.global-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-upgrade + restore-keys: | + yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}- + yarn-${{ runner.os }}- - name: ensure correct user run: chown -R root /__w/terraform-cdk - name: Install Tools diff --git a/.gitignore b/.gitignore index c5c218ffbb..d8675980b2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ node_modules .cdk.staging cdktf.out -tsconfig.json **/.DS_Store **/.gen diff --git a/CHANGELOG.md b/CHANGELOG.md index c530efa882..837c94d866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,45 @@ +## 0.18.2 + +Fixes a bug in 0.18.1 that broke crash reporting due to a partial dependency upgrade. + +### fix + +- fix: Fix partial dependency update for Sentry [\#3172](https://github.com/hashicorp/terraform-cdk/pull/3172) + +## 0.18.1 + +### fix + +- fix(docs): Fix typo in example of using TF*VAR* to set TerraformVariable [\#3116](https://github.com/hashicorp/terraform-cdk/pull/3116) +- fix(provider-generator): make sanitize comments function robust against diverse inputs [\#3131](https://github.com/hashicorp/terraform-cdk/pull/3131) +- fix(cli): fix help template spelling [\#3146](https://github.com/hashicorp/terraform-cdk/pull/3146) +- fix(cli): ensure terraform output fails with a proper error [\#3135](https://github.com/hashicorp/terraform-cdk/pull/3135) +- fix: make sure noColor option is honored [\#3138](https://github.com/hashicorp/terraform-cdk/pull/3138) +- fix(hcl2cdk): Try to fix TF checksum errors in tests by running them in band [\#3163](https://github.com/hashicorp/terraform-cdk/pull/3163) +- fix: use whl to install local python [\#3119](https://github.com/hashicorp/terraform-cdk/pull/3119) +- fix: fix Github workflow caches to restore successfully more often [\#3154](https://github.com/hashicorp/terraform-cdk/pull/3154) +- fix: set specific copywrite tool version to fix CI [\#3150](https://github.com/hashicorp/terraform-cdk/pull/3150) +- fix: unpin version of copywrite [\#3151](https://github.com/hashicorp/terraform-cdk/pull/3151) + +### chore + +- chore: Upgrade docker image to use Node 18 [\#3107](https://github.com/hashicorp/terraform-cdk/pull/3107) +- chore: fix passing additional providers [\#3092](https://github.com/hashicorp/terraform-cdk/pull/3092) +- chore(docs): fix grammar and spelling on Performance page [\#3098](https://github.com/hashicorp/terraform-cdk/pull/3098) +- chore: fix typo [\#3091](https://github.com/hashicorp/terraform-cdk/pull/3091) +- chore(cli): fixes typo (#3120) [\#3121](https://github.com/hashicorp/terraform-cdk/pull/3121) +- chore: fix typo in registry workflow [\#3100](https://github.com/hashicorp/terraform-cdk/pull/3100) +- chore: fix remove-waiting-on-answer workflow [\#3097](https://github.com/hashicorp/terraform-cdk/pull/3097) +- chore: ensure GitHub treats us as a TypeScript project [\#3099](https://github.com/hashicorp/terraform-cdk/pull/3099) +- chore: update registry tool [\#3101](https://github.com/hashicorp/terraform-cdk/pull/3101) +- chore: update dependencies for @cdktf/commons [\#3096](https://github.com/hashicorp/terraform-cdk/pull/3096) +- chore: update cdktf version [\#3090](https://github.com/hashicorp/terraform-cdk/pull/3090) +- chore: remove obsolete comment [\#3137](https://github.com/hashicorp/terraform-cdk/pull/3137) + +### refactor + +- refactor: move schema reading logic into package [\#3124](https://github.com/hashicorp/terraform-cdk/pull/3124) + ## 0.18.0 ### chore diff --git a/examples/java/aws-gradle/build.gradle b/examples/java/aws-gradle/build.gradle index f05695a5d9..191a6f4e16 100644 --- a/examples/java/aws-gradle/build.gradle +++ b/examples/java/aws-gradle/build.gradle @@ -24,10 +24,10 @@ repositories { } dependencies { - implementation 'com.hashicorp:cdktf:0.0.0' - implementation 'software.constructs:constructs:10.0.25' - implementation 'junit:junit:4.13.2' - implementation 'org.junit.jupiter:junit-jupiter:5.8.0' + implementation "com.hashicorp:cdktf:0.0.0" + implementation "software.constructs:constructs:10.0.25" + implementation "junit:junit:4.13.2" + implementation "org.junit.jupiter:junit-jupiter:5.8.0" } group = 'com.mycompany.app' diff --git a/examples/java/aws-gradle/reinstall.sh b/examples/java/aws-gradle/reinstall.sh index 0fc20788ef..bd05d19484 100755 --- a/examples/java/aws-gradle/reinstall.sh +++ b/examples/java/aws-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle \ No newline at end of file diff --git a/examples/java/azure-gradle/build.gradle b/examples/java/azure-gradle/build.gradle index 1e1b11e593..ee535feead 100644 --- a/examples/java/azure-gradle/build.gradle +++ b/examples/java/azure-gradle/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.hashicorp:cdktf:0.17.3" + implementation "com.hashicorp:cdktf:0.0.0" implementation "software.constructs:constructs:10.0.25" implementation "junit:junit:4.13.2" implementation "org.junit.jupiter:junit-jupiter:5.8.0" diff --git a/examples/java/azure-gradle/reinstall.sh b/examples/java/azure-gradle/reinstall.sh index 0fc20788ef..bd05d19484 100755 --- a/examples/java/azure-gradle/reinstall.sh +++ b/examples/java/azure-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle \ No newline at end of file diff --git a/examples/java/documentation-gradle/build.gradle b/examples/java/documentation-gradle/build.gradle index 2e19ab1587..bd40f7f181 100644 --- a/examples/java/documentation-gradle/build.gradle +++ b/examples/java/documentation-gradle/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.hashicorp:cdktf:0.17.3" + implementation "com.hashicorp:cdktf:0.0.0" implementation "software.constructs:constructs:10.0.25" implementation "junit:junit:4.13.2" implementation "org.junit.jupiter:junit-jupiter:5.8.0" diff --git a/examples/java/documentation-gradle/reinstall.sh b/examples/java/documentation-gradle/reinstall.sh index 0fc20788ef..bd05d19484 100755 --- a/examples/java/documentation-gradle/reinstall.sh +++ b/examples/java/documentation-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle \ No newline at end of file diff --git a/examples/java/google-gradle/build.gradle b/examples/java/google-gradle/build.gradle index 419047198c..82bfc6428d 100644 --- a/examples/java/google-gradle/build.gradle +++ b/examples/java/google-gradle/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.hashicorp:cdktf:0.17.3" + implementation "com.hashicorp:cdktf:0.0.0" implementation "software.constructs:constructs:10.0.25" implementation "junit:junit:4.13.2" implementation "org.junit.jupiter:junit-jupiter:5.8.0" diff --git a/examples/java/google-gradle/reinstall.sh b/examples/java/google-gradle/reinstall.sh index 0fc20788ef..bd05d19484 100755 --- a/examples/java/google-gradle/reinstall.sh +++ b/examples/java/google-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle \ No newline at end of file diff --git a/examples/java/kubernetes-gradle/build.gradle b/examples/java/kubernetes-gradle/build.gradle index f24c719ca3..791e8fbd9b 100644 --- a/examples/java/kubernetes-gradle/build.gradle +++ b/examples/java/kubernetes-gradle/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.hashicorp:cdktf:0.17.3" + implementation "com.hashicorp:cdktf:0.0.0" implementation "software.constructs:constructs:10.0.25" implementation "junit:junit:4.13.2" implementation "org.junit.jupiter:junit-jupiter:5.8.0" diff --git a/examples/java/kubernetes-gradle/reinstall.sh b/examples/java/kubernetes-gradle/reinstall.sh index 0fc20788ef..bd05d19484 100755 --- a/examples/java/kubernetes-gradle/reinstall.sh +++ b/examples/java/kubernetes-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle \ No newline at end of file diff --git a/examples/java/ucloud-gradle/build.gradle b/examples/java/ucloud-gradle/build.gradle index 07e9703ebf..cd152716b8 100644 --- a/examples/java/ucloud-gradle/build.gradle +++ b/examples/java/ucloud-gradle/build.gradle @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.hashicorp:cdktf:0.17.3" + implementation "com.hashicorp:cdktf:0.0.0" implementation "software.constructs:constructs:10.0.25" implementation "junit:junit:4.13.2" implementation "org.junit.jupiter:junit-jupiter:5.8.0" diff --git a/examples/java/ucloud-gradle/reinstall.sh b/examples/java/ucloud-gradle/reinstall.sh index 0fc20788ef..5555a2cd0d 100755 --- a/examples/java/ucloud-gradle/reinstall.sh +++ b/examples/java/ucloud-gradle/reinstall.sh @@ -5,4 +5,4 @@ set -ex -sed -i "s/implementation 'com.hashicorp:cdktf:0.0.0'/implementation files(\"..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar\")/" build.gradle \ No newline at end of file +sed -i 's/"com\.hashicorp:cdktf:0\.0\.0"/files("..\/..\/..\/dist\/java\/com\/hashicorp\/cdktf\/0.0.0\/cdktf-0.0.0.jar")/g' build.gradle diff --git a/examples/typescript/aws-import/.gitignore b/examples/typescript/aws-import/.gitignore new file mode 100644 index 0000000000..1dfae30c78 --- /dev/null +++ b/examples/typescript/aws-import/.gitignore @@ -0,0 +1,11 @@ +*.d.ts +*.js +node_modules +cdktf.out +cdktf.log +*terraform.*.tfstate* +.gen +.terraform +tsconfig.tsbuildinfo +!jest.config.js +!setup.js \ No newline at end of file diff --git a/examples/typescript/aws-import/__tests__/main-test.ts b/examples/typescript/aws-import/__tests__/main-test.ts new file mode 100644 index 0000000000..4f4cd20106 --- /dev/null +++ b/examples/typescript/aws-import/__tests__/main-test.ts @@ -0,0 +1,87 @@ +// Copyright (c) HashiCorp, Inc +// SPDX-License-Identifier: MPL-2.0 +// import { Testing } from "cdktf"; +// import "cdktf/lib/testing/adapters/jest"; + +describe("My CDKTF Application", () => { + it.todo("should be tested"); + + // // All Unit testst test the synthesised terraform code, it does not create real-world resources + // describe("Unit testing using assertions", () => { + // it("should contain a resource", () => { + // // import { Image,Container } from "./.gen/providers/docker" + // expect( + // Testing.synthScope((scope) => { + // new MyApplicationsAbstraction(scope, "my-app", {}); + // }) + // ).toHaveResource(Container); + + // expect( + // Testing.synthScope((scope) => { + // new MyApplicationsAbstraction(scope, "my-app", {}); + // }) + // ).toHaveResourceWithProperties(Image, { name: "ubuntu:latest" }); + // }); + // }); + + // describe("Unit testing using snapshots", () => { + // it("Tests the snapshot", () => { + // const app = Testing.app(); + // const stack = new TerraformStack(app, "test"); + + // new TestProvider(stack, "provider", { + // accessKey: "1", + // }); + + // new TestResource(stack, "test", { + // name: "my-resource", + // }); + + // expect(Testing.synth(stack)).toMatchSnapshot(); + // }); + + // it("Tests a combination of resources", () => { + // expect( + // Testing.synthScope((stack) => { + // new TestDataSource(stack, "test-data-source", { + // name: "foo", + // }); + + // new TestResource(stack, "test-resource", { + // name: "bar", + // }); + // }) + // ).toMatchInlineSnapshot(); + // }); + // }); + + // describe("Checking validity", () => { + // it("check if the produced terraform configuration is valid", () => { + // const app = Testing.app(); + // const stack = new TerraformStack(app, "test"); + + // new TestDataSource(stack, "test-data-source", { + // name: "foo", + // }); + + // new TestResource(stack, "test-resource", { + // name: "bar", + // }); + // expect(Testing.fullSynth(app)).toBeValidTerraform(); + // }); + + // it("check if this can be planned", () => { + // const app = Testing.app(); + // const stack = new TerraformStack(app, "test"); + + // new TestDataSource(stack, "test-data-source", { + // name: "foo", + // }); + + // new TestResource(stack, "test-resource", { + // name: "bar", + // }); + // expect(Testing.fullSynth(app)).toPlanSuccessfully(); + // }); + // }); +}); diff --git a/examples/typescript/aws-import/cdktf.json b/examples/typescript/aws-import/cdktf.json new file mode 100644 index 0000000000..3ec54a79c2 --- /dev/null +++ b/examples/typescript/aws-import/cdktf.json @@ -0,0 +1,7 @@ +{ + "language": "typescript", + "app": "npx ts-node main.ts", + "terraformProviders": [ + "aws@~> 5.0" + ] +} \ No newline at end of file diff --git a/examples/typescript/aws-import/help b/examples/typescript/aws-import/help new file mode 100644 index 0000000000..83a74dd683 --- /dev/null +++ b/examples/typescript/aws-import/help @@ -0,0 +1,34 @@ +======================================================================================================== + + Your cdktf typescript project is ready! + + cat help Print this message + + Compile: + npm run compile Compile typescript code to javascript (or "yarn watch") + npm run watch Watch for changes and compile typescript in the background + npm run build cdktf get and compile typescript + + Synthesize: + cdktf synth Synthesize Terraform resources from stacks to cdktf.out/ (ready for 'terraform apply') + + Diff: + cdktf diff Perform a diff (terraform plan) for the given stack + + Deploy: + cdktf deploy Deploy the given stack + + Destroy: + cdktf destroy Destroy the stack + + Test: + npm run test Runs unit tests (edit __tests__/main-test.ts to add your own tests) + npm run test:watch Watches the tests and reruns them on change + + + Upgrades: + npm run get Import/update Terraform providers and modules (you should check-in this directory) + npm run upgrade Upgrade cdktf modules to latest version + npm run upgrade:next Upgrade cdktf modules to latest "@next" version (last commit) + +======================================================================================================== diff --git a/examples/typescript/aws-import/jest.config.js b/examples/typescript/aws-import/jest.config.js new file mode 100644 index 0000000000..e53ea43b7d --- /dev/null +++ b/examples/typescript/aws-import/jest.config.js @@ -0,0 +1,16 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +/* + * For a detailed explanation regarding each configuration property, visit: + * https://jestjs.io/docs/configuration + */ + +module.exports = { + clearMocks: true, + coverageProvider: "v8", + setupFilesAfterEnv: ["./setup.js"], + }; + diff --git a/examples/typescript/aws-import/main.ts b/examples/typescript/aws-import/main.ts new file mode 100644 index 0000000000..6c48a3e357 --- /dev/null +++ b/examples/typescript/aws-import/main.ts @@ -0,0 +1,56 @@ +// Copyright (c) HashiCorp, Inc +// SPDX-License-Identifier: MPL-2.0 +import { Construct } from "constructs"; +import { App, TerraformStack } from "cdktf"; +import { AwsProvider } from "./.gen/providers/aws/provider"; +import { S3Bucket } from "./.gen/providers/aws/s3-bucket"; + +class StackWithImport extends TerraformStack { + constructor(scope: Construct, ns: string) { + super(scope, ns); + + const bucketId = "best-bucket-in-the-world"; + // Step 1: Create a S3Bucket in the AWS web ui + // https://s3.console.aws.amazon.com/s3/buckets?region=us-east-1®ion=us-east-1 + + new AwsProvider(this, "aws", { + region: "us-east-1", + }); + + // Step 2: Create importable resource + new S3Bucket(this, "bucket", {}).importFrom(bucketId); + + // Step 3: Run `cdktf apply` + // Step 4: Remove the `importFrom` call, the resource is now imported + } +} + +class StackWithImportAndConfigurationGeneration extends TerraformStack { + constructor(scope: Construct, ns: string) { + super(scope, ns); + + const bucketId = "best-bucket-in-the-world"; + // Step 1: Create a S3Bucket in the AWS web ui + // https://s3.console.aws.amazon.com/s3/buckets?region=us-east-1®ion=us-east-1 + + new AwsProvider(this, "aws", { + region: "us-east-1", + }); + + // Step 2: Create import block + S3Bucket.generateConfigForImport(this, "bucket", bucketId); + + // Step 3: Run cdktf plan + // Step 4: Replace the `generateConfigForImport()` call with the generated configuration + // Step 5: Add the `importFrom` call to the generated configuration, + // Step 6: On apply, the resource is now imported + } +} + +const app = new App(); +new StackWithImport(app, "ts-import"); +new StackWithImportAndConfigurationGeneration( + app, + "ts-import-with-configuration" +); +app.synth(); diff --git a/examples/typescript/aws-import/package.json b/examples/typescript/aws-import/package.json new file mode 100644 index 0000000000..f8b49ef474 --- /dev/null +++ b/examples/typescript/aws-import/package.json @@ -0,0 +1,32 @@ +{ + "//": "This example test is disabled via the 'private' attribute since Terraform 1.5 is required for proper synth, and as of writing CI has a lesser version", + "name": "@examples/typescript-aws-import", + "private": true, + "version": "0.0.0", + "main": "main.js", + "types": "main.ts", + "license": "MPL-2.0", + "scripts": { + "get": "cdktf get", + "build": "yarn get && tsc", + "synth": "cdktf synth", + "compile": "tsc --pretty", + "watch": "tsc -w", + "test": "jest", + "test:watch": "jest --watch", + "upgrade": "npm i cdktf@latest cdktf-cli@latest", + "upgrade:next": "npm i cdktf@next cdktf-cli@next" + }, + "dependencies": { + "cdktf": "0.0.0", + "constructs": "^10.0.25" + }, + "devDependencies": { + "@types/jest": "27.5.2", + "@types/node": "16.18.23", + "cdktf-cli": "0.0.0", + "jest": "^27.5.1", + "ts-node": "^10.9.1", + "typescript": "^5.0.2" + } +} \ No newline at end of file diff --git a/examples/typescript/aws-import/setup.js b/examples/typescript/aws-import/setup.js new file mode 100644 index 0000000000..cabf53825f --- /dev/null +++ b/examples/typescript/aws-import/setup.js @@ -0,0 +1,7 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +const cdktf = require("cdktf"); +cdktf.Testing.setupJest(); diff --git a/examples/typescript/aws-import/tsconfig.json b/examples/typescript/aws-import/tsconfig.json new file mode 100644 index 0000000000..778b2e42e3 --- /dev/null +++ b/examples/typescript/aws-import/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "alwaysStrict": true, + "declaration": true, + "experimentalDecorators": true, + "inlineSourceMap": true, + "inlineSources": true, + "lib": [ + "es2018" + ], + "module": "CommonJS", + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "stripInternal": true, + "target": "ES2018", + "incremental": true + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 57222f6dce..5884141a08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "root", - "version": "0.18.0", + "version": "0.18.2", "private": true, "scripts": { "build-and-package": "lerna run --scope 'cdktf*' --scope @cdktf/* build,package && tools/collect-dist.sh", diff --git a/packages/@cdktf/cli-core/package.json b/packages/@cdktf/cli-core/package.json index 6e186872d1..ffbb32d428 100644 --- a/packages/@cdktf/cli-core/package.json +++ b/packages/@cdktf/cli-core/package.json @@ -42,7 +42,7 @@ "@cdktf/hcl2json": "0.0.0", "@cdktf/provider-schema": "0.0.0", "@cdktf/node-pty-prebuilt-multiarch": "0.10.1-pre.10", - "@sentry/node": "^6.19.7", + "@sentry/node": "^7.64.0", "archiver": "^5.3.1", "cdktf": "0.0.0", "chalk": "^4.1.2", diff --git a/packages/@cdktf/cli-core/src/lib/cdktf-project.ts b/packages/@cdktf/cli-core/src/lib/cdktf-project.ts index 853aab95a1..fd8a72e4f6 100644 --- a/packages/@cdktf/cli-core/src/lib/cdktf-project.ts +++ b/packages/@cdktf/cli-core/src/lib/cdktf-project.ts @@ -348,7 +348,7 @@ export class CdktfProject { ); } - public async synth() { + public async synth(noColor?: boolean) { this.onUpdate({ type: "synthesizing", }); @@ -358,6 +358,7 @@ export class CdktfProject { this.outDir, this.workingDirectory, false, + noColor, this.synthOrigin ); @@ -386,7 +387,7 @@ export class CdktfProject { public async diff(opts: DiffOptions = {}) { const stacks = opts.skipSynth ? await this.readSynthesizedStacks() - : await this.synth(); + : await this.synth(opts.noColor); const stack = this.getStackExecutor( getSingleStack(stacks, opts?.stackName, "diff") ); @@ -484,7 +485,7 @@ export class CdktfProject { public async deploy(opts: MutationOptions = {}) { const stacks = opts.skipSynth ? await this.readSynthesizedStacks() - : await this.synth(); + : await this.synth(opts.noColor); const stacksToRun = getMultipleStacks(stacks, opts.stackNames, "deploy"); if (!opts.ignoreMissingStackDependencies) { checkIfAllDependenciesAreIncluded(stacksToRun); @@ -542,7 +543,7 @@ export class CdktfProject { public async destroy(opts: MutationOptions = {}) { const stacks = opts.skipSynth ? await this.readSynthesizedStacks() - : await this.synth(); + : await this.synth(opts.noColor); const stacksToRun = getMultipleStacks(stacks, opts.stackNames, "destroy"); if (!opts.ignoreMissingStackDependencies) { diff --git a/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts b/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts index 18eb9b8422..0f9fc7bf1c 100644 --- a/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts +++ b/packages/@cdktf/cli-core/src/lib/cdktf-stack.ts @@ -5,10 +5,16 @@ import { Terraform } from "./models/terraform"; import { getConstructIdsForOutputs, NestedTerraformOutputs } from "./output"; import { logger } from "@cdktf/commons"; import { extractJsonLogIfPresent } from "./server/terraform-logs"; -import { TerraformCli, OutputFilter } from "./models/terraform-cli"; +import { + TerraformCli, + OutputFilter, + tryReadGeneratedConfigurationFile, + tryRemoveGeneratedConfigurationFile, +} from "./models/terraform-cli"; import { ProviderConstraint } from "./dependencies/dependency-manager"; import { terraformJsonSchema, TerraformStack } from "./terraform-json"; import { TerraformProviderLock } from "./terraform-provider-lock"; +import { convertConfigurationFile } from "./convert"; export type StackUpdate = | { @@ -61,6 +67,16 @@ export type StackUpdate = | { type: "dismissed"; stackName: string; + } + | { + type: "import with configuration detected"; + stackName: string; + configuration: string; + } + | { + type: "import with configuration converted"; + stackName: string; + configuration: string; }; export type StackUserInputUpdate = @@ -362,6 +378,50 @@ export class CdktfStack { noColor, }); this.updateState({ type: "planned", stackName: this.stack.name }); + + // Find generated file + const configFile = await tryReadGeneratedConfigurationFile( + this.stack.workingDirectory + ); + if (configFile) { + this.updateState({ + type: "import with configuration detected", + stackName: this.stack.name, + configuration: configFile, + }); + + const convertedCode = await convertConfigurationFile( + configFile, + this.stack.workingDirectory + ); + this.updateState({ + type: "import with configuration converted", + stackName: this.stack.name, + configuration: convertedCode, + }); + const onLog = this.options.onLog; + if (onLog) { + onLog({ + message: `Import without configuration detected. Terraform has created configuration for it: +${configFile} + +CDKTF has translated the code to the following: + +${convertedCode} + +Please review the code and make any necessary changes before adding it to your codebase. +Make sure to only copy the code within the construct's constructor. + +NOTE: Your resource has not yet become managed by CDKTF. +To finish the import remove the call "generateConfigForImport", add the above code within the construct's constructor, and then append the call importFrom() to the generated code: + +new SomeResource(...).importFrom("some_id") +`, + isError: false, + }); + } + await tryRemoveGeneratedConfigurationFile(this.stack.workingDirectory); + } }); } diff --git a/packages/@cdktf/cli-core/src/lib/convert.ts b/packages/@cdktf/cli-core/src/lib/convert.ts new file mode 100644 index 0000000000..14e43954b7 --- /dev/null +++ b/packages/@cdktf/cli-core/src/lib/convert.ts @@ -0,0 +1,39 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import * as hcl2cdk from "@cdktf/hcl2cdk"; +import { CdktfConfig } from "./cdktf-config"; +import { TerraformProviderConstraint } from "@cdktf/provider-generator"; +import { readSchema } from "@cdktf/provider-schema"; +import { + Errors, + LANGUAGES, + ConstructsMakerProviderTarget, +} from "@cdktf/commons"; + +export async function convertConfigurationFile( + configuration: string, + stackWorkingDirectory: string +) { + const cfg = CdktfConfig.read(stackWorkingDirectory); + const targets = cfg.terraformProviders.map((constraint) => + ConstructsMakerProviderTarget.from( + new TerraformProviderConstraint(constraint), + LANGUAGES[0] + ) + ); + const { providerSchema } = await readSchema(targets); + if (!providerSchema) { + throw Errors.Internal("Could not fetch provider schema"); + } + + const { all } = await hcl2cdk.convert(configuration, { + providerSchema, + language: cfg.language, + codeContainer: "constructs.Construct", + }); + + return all; +} diff --git a/packages/@cdktf/cli-core/src/lib/error-reporting.ts b/packages/@cdktf/cli-core/src/lib/error-reporting.ts index f51cd54e0e..f8f84c6a3a 100644 --- a/packages/@cdktf/cli-core/src/lib/error-reporting.ts +++ b/packages/@cdktf/cli-core/src/lib/error-reporting.ts @@ -96,8 +96,9 @@ export async function initializErrorReporting( | Error | string | null - | undefined = hint.originalException; - let error: Error | string | null | undefined; + | undefined + | unknown = hint.originalException; + let error: Error | string | null | undefined | unknown; if (isPromise(originalException)) { (originalException as unknown as Promise).catch( (e) => (error = e) diff --git a/packages/@cdktf/cli-core/src/lib/models/terraform-cli.ts b/packages/@cdktf/cli-core/src/lib/models/terraform-cli.ts index 4fe7e48df0..8438e6c9a6 100644 --- a/packages/@cdktf/cli-core/src/lib/models/terraform-cli.ts +++ b/packages/@cdktf/cli-core/src/lib/models/terraform-cli.ts @@ -26,6 +26,10 @@ import { waitFor } from "xstate/lib/waitFor"; import { missingVariable } from "../errors"; import { terraformJsonSchema } from "../terraform-json"; import { spawnPty } from "./pty-process"; +import path from "path"; +import * as fs from "fs-extra"; + +const GENERATE_CONFIG_OUT_FILE = "generated_resources.tf"; export class TerraformCliPlan extends AbstractTerraformPlan @@ -180,6 +184,7 @@ export class TerraformCli implements Terraform { cwd: this.workdir, env: process.env, signal: this.abortSignal, + noColor: opts.noColor, }, this.onStdout("init"), this.onStderr("init") @@ -197,6 +202,14 @@ export class TerraformCli implements Terraform { ); } + private get hasImports(): boolean { + const parsedStack = terraformJsonSchema.parse( + JSON.parse(this.stack.content) + ); + + return Boolean(parsedStack.import); + } + public async plan(opts: { destroy: boolean; refreshOnly?: boolean; @@ -215,6 +228,16 @@ export class TerraformCli implements Terraform { } = opts; const options = ["plan", "-input=false"]; + const generatedConfigFile = path.join( + this.workdir, + GENERATE_CONFIG_OUT_FILE + ); + if (fs.existsSync(generatedConfigFile)) { + fs.remove(generatedConfigFile); + } + if (this.hasImports) { + options.push(`-generate-config-out=${GENERATE_CONFIG_OUT_FILE}`); + } if (!this.isCloudStack) { const planFile = "plan"; options.push("-out", planFile); @@ -249,6 +272,7 @@ export class TerraformCli implements Terraform { cwd: this.workdir, env: process.env, signal: this.abortSignal, + noColor, }, this.onStdout("plan", [VariableRequiredFilter]), this.onStderr("plan", [VariableRequiredFilter]) @@ -411,6 +435,7 @@ export class TerraformCli implements Terraform { cwd: this.workdir, env: process.env, signal: this.abortSignal, + noColor: true, }, this.onStdout("version"), this.onStderr("version") @@ -430,6 +455,7 @@ export class TerraformCli implements Terraform { cwd: this.workdir, env: process.env, signal: this.abortSignal, + noColor: true, }, // We don't need to log the output here since we use it later on () => {}, // eslint-disable-line @typescript-eslint/no-empty-function @@ -460,3 +486,20 @@ export class TerraformCli implements Terraform { return; } } + +export async function tryReadGeneratedConfigurationFile( + workingDir: string +): Promise { + const generatedConfigPath = path.join(workingDir, GENERATE_CONFIG_OUT_FILE); + if (!fs.existsSync(generatedConfigPath)) { + return null; + } + return fs.readFileSync(generatedConfigPath, "utf-8"); +} + +export async function tryRemoveGeneratedConfigurationFile(workingDir: string) { + const generatedConfigPath = path.join(workingDir, GENERATE_CONFIG_OUT_FILE); + if (fs.existsSync(generatedConfigPath)) { + fs.unlinkSync(generatedConfigPath); + } +} diff --git a/packages/@cdktf/cli-core/src/lib/synth-stack.ts b/packages/@cdktf/cli-core/src/lib/synth-stack.ts index 8b940a0e64..f52bf10686 100644 --- a/packages/@cdktf/cli-core/src/lib/synth-stack.ts +++ b/packages/@cdktf/cli-core/src/lib/synth-stack.ts @@ -70,6 +70,7 @@ export class SynthStack { outdir: string, workingDirectory = process.cwd(), graceful = false, // will not exit the process but rethrow the error instead + noColor = false, synthOrigin?: SynthOrigin ): Promise { // start performance timer @@ -120,6 +121,7 @@ might fail while synthesizing with an out of memory error.`); }, cwd: workingDirectory, signal: abortSignal, + noColor: noColor, }); } catch (e: any) { const errorOutput = chalkColour`{redBright cdktf encountered an error while synthesizing} diff --git a/packages/@cdktf/cli-core/src/test/lib/terraform-parallelism.test.ts b/packages/@cdktf/cli-core/src/test/lib/terraform-parallelism.test.ts index 8c49859943..5675e62b5b 100644 --- a/packages/@cdktf/cli-core/src/test/lib/terraform-parallelism.test.ts +++ b/packages/@cdktf/cli-core/src/test/lib/terraform-parallelism.test.ts @@ -10,16 +10,20 @@ import { CdktfProject, init, get } from "../../lib/index"; import { spawn } from "@cdktf/node-pty-prebuilt-multiarch"; import { exec, Language } from "@cdktf/commons"; +// this is required for the get() call in beforeAll() to work +let execMockActive = false; + jest.mock("@cdktf/commons", () => { const originalModule = jest.requireActual("@cdktf/commons"); return { __esmodule: true, ...originalModule, - // exec: jest.fn().mockImplementation(originalModule.exec), - exec: jest.fn().mockImplementation(async (_binary, _args) => { + exec: jest.fn().mockImplementation(async (...args: any[]) => { // Fake all commands that we invoke - return Promise.resolve(JSON.stringify({})); + + if (execMockActive) return Promise.resolve(JSON.stringify({})); + return originalModule.exec(...args); }), }; }); @@ -127,6 +131,8 @@ describe("terraform parallelism", () => { process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH, }); + execMockActive = true; + inNewWorkingDirectory = function inNewWorkingDirectory() { const wd = fs.mkdtempSync(path.join(os.tmpdir(), "cdktf.")); const outDir = path.resolve(wd, "out"); diff --git a/packages/@cdktf/commons/package.json b/packages/@cdktf/commons/package.json index 0869698e69..fe6721af74 100644 --- a/packages/@cdktf/commons/package.json +++ b/packages/@cdktf/commons/package.json @@ -43,7 +43,7 @@ "fs-extra": "^11.1.1", "is-valid-domain": "^0.1.6", "log4js": "^6.9.1", - "uuid": "^9.0.0" + "uuid": "^9.0.1" }, "devDependencies": { "@types/follow-redirects": "^1.14.1", diff --git a/packages/@cdktf/commons/src/logging.ts b/packages/@cdktf/commons/src/logging.ts index 4e25045583..64a9a986dc 100644 --- a/packages/@cdktf/commons/src/logging.ts +++ b/packages/@cdktf/commons/src/logging.ts @@ -4,6 +4,7 @@ import { configure, getLogger } from "log4js"; import * as fs from "fs-extra"; import * as path from "path"; import * as Sentry from "@sentry/node"; +import { hasNoColorFlagOrEnv } from "./util"; const cliLogger = getLogger(); const logger = { @@ -81,6 +82,13 @@ if ( }, categories: { default: { appenders: ["cdktf"], level: "debug" } }, }); +} else { + const layoutType = hasNoColorFlagOrEnv() ? "basic" : "colored"; + + configure({ + appenders: { out: { type: "stdout", layout: { type: layoutType } } }, + categories: { default: { appenders: ["out"], level: "info" } }, + }); } const processLoggerDebug = (chunk: Buffer | string | Uint8Array) => { diff --git a/packages/@cdktf/commons/src/util.ts b/packages/@cdktf/commons/src/util.ts index d96d5f3865..95b13bf26d 100644 --- a/packages/@cdktf/commons/src/util.ts +++ b/packages/@cdktf/commons/src/util.ts @@ -9,11 +9,12 @@ import * as path from "path"; import { processLoggerError, processLoggerDebug } from "./logging"; import { IManifest, Manifest } from "cdktf"; import * as config from "./config"; +import stripAnsi from "strip-ansi"; export async function shell( program: string, args: string[] = [], - options: SpawnOptions = {} + options: SpawnOptions & { noColor?: boolean } = {} ) { const stderr = new Array(); const stdout = new Array(); @@ -22,18 +23,32 @@ export async function shell( program, args, options, - (chunk: Buffer) => { - stdout.push(chunk.toString()); - console.log(chunk.toString()); + (chunk: string) => { + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + stdout.push(sanitizedChunk); + console.log(sanitizedChunk); }, - (chunk: string | Uint8Array) => stderr.push(chunk) + (chunk: string | Uint8Array) => { + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + stderr.push(sanitizedChunk); + } ); } catch (e: any) { if (stderr.length > 0) { e.stderr = stderr.map((chunk) => chunk.toString()).join(""); + if (options.noColor) { + e.stderr = stripAnsi(e.stderr); + } } if (stdout.length > 0) { e.stdout = stdout.join(""); + if (options.noColor) { + e.stdout = stripAnsi(e.stdout); + } } throw e; } @@ -68,42 +83,60 @@ export async function mkdtemp(closure: (dir: string) => Promise) { export const exec = async ( command: string, args: string[], - options: SpawnOptions, - stdout?: (chunk: Buffer) => any, + options: SpawnOptions & { noColor?: boolean }, + stdout?: (chunk: string) => any, stderr?: (chunk: string | Uint8Array) => any, sendToStderr = true ): Promise => { + // if options.noColor is not set, checking the flags & environment if it should be set + // This is required for collectDebugInformation() which does not have knowledge about flags + if (typeof options.noColor !== "boolean" && hasNoColorFlagOrEnv()) { + options.noColor = true; + } + return new Promise((ok, ko) => { const child = spawn(command, args, options); - const out = new Array(); - const err = new Array(); + const out = new Array(); + const err = new Array(); if (stdout !== undefined) { child.stdout?.on("data", (chunk: Buffer) => { - processLoggerDebug(chunk); - out.push(chunk); - stdout(chunk); + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + processLoggerDebug(sanitizedChunk); + out.push(sanitizedChunk); + stdout(sanitizedChunk); }); } else { child.stdout?.on("data", (chunk: Buffer) => { - processLoggerDebug(chunk); - out.push(chunk); + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + processLoggerDebug(sanitizedChunk); + out.push(sanitizedChunk); }); } if (stderr !== undefined) { child.stderr?.on("data", (chunk: string | Uint8Array) => { - processLoggerError(chunk); + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + processLoggerError(sanitizedChunk); if (sendToStderr) { - stderr(chunk); + stderr(sanitizedChunk); } - err.push(chunk); + err.push(sanitizedChunk); }); } else { child.stderr?.on("data", (chunk: string | Uint8Array) => { - processLoggerError(chunk); + const sanitizedChunk = options.noColor + ? stripAnsi(chunk.toLocaleString()) + : chunk.toLocaleString(); + processLoggerError(sanitizedChunk); if (sendToStderr) { - process.stderr.write(chunk); + process.stderr.write(sanitizedChunk); } - err.push(chunk); + err.push(sanitizedChunk); }); } child.once("error", (err: any) => ko(err)); @@ -113,7 +146,7 @@ export const exec = async ( (error as any).stderr = err.map((chunk) => chunk.toString()).join(""); return ko(error); } - return ok(Buffer.concat(out).toString("utf-8")); + return ok(out.join("")); }); }); }; @@ -211,3 +244,24 @@ export async function ensureAllSettledBeforeThrowing( throw e; } } + +/** + * returns true if --no-color is passed as CLI flag or the env var FORCE_COLOR is set to "0" + * Used for cases where we can't pass down the noColor flag (e.g. when collecting debug information from the environment) + * This is the same behavior as the `chalk` lib we use for coloring output + */ +export function hasNoColorFlagOrEnv(): boolean { + return hasFlag("no-color") || process.env.FORCE_COLOR === "0"; +} + +// From: https://github.com/sindresorhus/has-flag/blob/main/index.js +// as used in https://github.com/chalk/chalk +function hasFlag(flag: string) { + const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; + const position = process.argv.indexOf(prefix + flag); + const terminatorPosition = process.argv.indexOf("--"); + return ( + position !== -1 && + (terminatorPosition === -1 || position < terminatorPosition) + ); +} diff --git a/packages/@cdktf/hcl2cdk/package.json b/packages/@cdktf/hcl2cdk/package.json index 24db08c335..a79b3b53b7 100644 --- a/packages/@cdktf/hcl2cdk/package.json +++ b/packages/@cdktf/hcl2cdk/package.json @@ -12,7 +12,7 @@ "watch": "tsc -w", "watch-preserve-output": "tsc -w --preserveWatchOutput", "test": "jest", - "test:ci": "jest --ci", + "test:ci": "jest --ci --runInBand", "jest-watch": "jest --watch", "package": "./package.sh", "dist-clean": "rm -rf dist" diff --git a/packages/@cdktf/provider-generator/lib/__tests__/__snapshots__/provider.test.ts.snap b/packages/@cdktf/provider-generator/lib/__tests__/__snapshots__/provider.test.ts.snap index 37f352f773..badb5182b1 100644 --- a/packages/@cdktf/provider-generator/lib/__tests__/__snapshots__/provider.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/__tests__/__snapshots__/provider.test.ts.snap @@ -45,6 +45,20 @@ export class ApiKey extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_api_key"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ApiKey resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ApiKey to import + * @param importFromId The id of the existing ApiKey that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/api_key#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ApiKey to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_api_key", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -164,6 +178,20 @@ export class ApplicationKey extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_application_key"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ApplicationKey resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ApplicationKey to import + * @param importFromId The id of the existing ApplicationKey that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/application_key#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ApplicationKey to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_application_key", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -295,6 +323,20 @@ export class AuthnMapping extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_authn_mapping"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a AuthnMapping resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the AuthnMapping to import + * @param importFromId The id of the existing AuthnMapping that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/authn_mapping#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the AuthnMapping to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_authn_mapping", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1030,6 +1072,20 @@ export class ChildOrganization extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_child_organization"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ChildOrganization resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ChildOrganization to import + * @param importFromId The id of the existing ChildOrganization that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/child_organization#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ChildOrganization to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_child_organization", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1196,6 +1252,20 @@ export class CloudWorkloadSecurityAgentRule extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_cloud_workload_security_agent_rule"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a CloudWorkloadSecurityAgentRule resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the CloudWorkloadSecurityAgentRule to import + * @param importFromId The id of the existing CloudWorkloadSecurityAgentRule that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/cloud_workload_security_agent_rule#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the CloudWorkloadSecurityAgentRule to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_cloud_workload_security_agent_rule", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1373,6 +1443,20 @@ export class DashboardJson extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_dashboard_json"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DashboardJson resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DashboardJson to import + * @param importFromId The id of the existing DashboardJson that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/dashboard_json#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DashboardJson to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard_json", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1656,6 +1740,20 @@ export class DashboardList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_dashboard_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DashboardList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DashboardList to import + * @param importFromId The id of the existing DashboardList that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/dashboard_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DashboardList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -172993,6 +173091,20 @@ export class Dashboard extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_dashboard"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Dashboard resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Dashboard to import + * @param importFromId The id of the existing Dashboard that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/dashboard#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Dashboard to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173309,6 +173421,20 @@ export class DataDatadogApiKey extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_api_key"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogApiKey resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogApiKey to import + * @param importFromId The id of the existing DataDatadogApiKey that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/api_key#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogApiKey to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_api_key", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173433,6 +173559,20 @@ export class DataDatadogApplicationKey extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_application_key"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogApplicationKey resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogApplicationKey to import + * @param importFromId The id of the existing DataDatadogApplicationKey that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/application_key#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogApplicationKey to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_application_key", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173633,6 +173773,20 @@ export class DataDatadogCloudWorkloadSecurityAgentRules extends cdktf.TerraformD // ================= public static readonly tfResourceType = "datadog_cloud_workload_security_agent_rules"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogCloudWorkloadSecurityAgentRules resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogCloudWorkloadSecurityAgentRules to import + * @param importFromId The id of the existing DataDatadogCloudWorkloadSecurityAgentRules that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/cloud_workload_security_agent_rules#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogCloudWorkloadSecurityAgentRules to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_cloud_workload_security_agent_rules", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173738,6 +173892,20 @@ export class DataDatadogDashboardList extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_dashboard_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogDashboardList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogDashboardList to import + * @param importFromId The id of the existing DataDatadogDashboardList that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/dashboard_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogDashboardList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173852,6 +174020,20 @@ export class DataDatadogDashboard extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_dashboard"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogDashboard resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogDashboard to import + * @param importFromId The id of the existing DataDatadogDashboard that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/dashboard#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogDashboard to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -173970,6 +174152,20 @@ export class DataDatadogIpRanges extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_ip_ranges"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogIpRanges resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogIpRanges to import + * @param importFromId The id of the existing DataDatadogIpRanges that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/ip_ranges#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogIpRanges to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_ip_ranges", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -174145,6 +174341,20 @@ export class DataDatadogLogsIndexesOrder extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_logs_indexes_order"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogLogsIndexesOrder resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogLogsIndexesOrder to import + * @param importFromId The id of the existing DataDatadogLogsIndexesOrder that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/logs_indexes_order#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogLogsIndexesOrder to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_indexes_order", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -174537,6 +174747,20 @@ export class DataDatadogLogsIndexes extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_logs_indexes"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogLogsIndexes resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogLogsIndexes to import + * @param importFromId The id of the existing DataDatadogLogsIndexes that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/logs_indexes#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogLogsIndexes to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_indexes", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -174812,6 +175036,20 @@ export class DataDatadogMonitor extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_monitor"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogMonitor resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogMonitor to import + * @param importFromId The id of the existing DataDatadogMonitor that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/monitor#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogMonitor to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_monitor", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -175173,6 +175411,20 @@ export class DataDatadogMonitors extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_monitors"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogMonitors resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogMonitors to import + * @param importFromId The id of the existing DataDatadogMonitors that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/monitors#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogMonitors to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_monitors", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -175326,6 +175578,20 @@ export class DataDatadogPermissions extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_permissions"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogPermissions resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogPermissions to import + * @param importFromId The id of the existing DataDatadogPermissions that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/permissions#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogPermissions to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_permissions", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -175431,6 +175697,20 @@ export class DataDatadogRole extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_role"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogRole resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogRole to import + * @param importFromId The id of the existing DataDatadogRole that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/role#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogRole to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_role", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -175629,6 +175909,20 @@ export class DataDatadogRoles extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_roles"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogRoles resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogRoles to import + * @param importFromId The id of the existing DataDatadogRoles that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/roles#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogRoles to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_roles", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -175905,6 +176199,20 @@ export class DataDatadogSecurityMonitoringFilters extends cdktf.TerraformDataSou // ================= public static readonly tfResourceType = "datadog_security_monitoring_filters"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogSecurityMonitoringFilters resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogSecurityMonitoringFilters to import + * @param importFromId The id of the existing DataDatadogSecurityMonitoringFilters that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/security_monitoring_filters#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogSecurityMonitoringFilters to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_security_monitoring_filters", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -176682,6 +176990,20 @@ export class DataDatadogSecurityMonitoringRules extends cdktf.TerraformDataSourc // ================= public static readonly tfResourceType = "datadog_security_monitoring_rules"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogSecurityMonitoringRules resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogSecurityMonitoringRules to import + * @param importFromId The id of the existing DataDatadogSecurityMonitoringRules that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/security_monitoring_rules#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogSecurityMonitoringRules to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_security_monitoring_rules", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -176878,6 +177200,20 @@ export class DataDatadogServiceLevelObjective extends cdktf.TerraformDataSource // ================= public static readonly tfResourceType = "datadog_service_level_objective"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogServiceLevelObjective resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogServiceLevelObjective to import + * @param importFromId The id of the existing DataDatadogServiceLevelObjective that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/service_level_objective#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogServiceLevelObjective to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_service_level_objective", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -177133,6 +177469,20 @@ export class DataDatadogServiceLevelObjectives extends cdktf.TerraformDataSource // ================= public static readonly tfResourceType = "datadog_service_level_objectives"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogServiceLevelObjectives resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogServiceLevelObjectives to import + * @param importFromId The id of the existing DataDatadogServiceLevelObjectives that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/service_level_objectives#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogServiceLevelObjectives to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_service_level_objectives", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -177310,6 +177660,20 @@ export class DataDatadogSyntheticsGlobalVariable extends cdktf.TerraformDataSour // ================= public static readonly tfResourceType = "datadog_synthetics_global_variable"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogSyntheticsGlobalVariable resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogSyntheticsGlobalVariable to import + * @param importFromId The id of the existing DataDatadogSyntheticsGlobalVariable that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/synthetics_global_variable#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogSyntheticsGlobalVariable to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_global_variable", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -177423,6 +177787,20 @@ export class DataDatadogSyntheticsLocations extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_synthetics_locations"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogSyntheticsLocations resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogSyntheticsLocations to import + * @param importFromId The id of the existing DataDatadogSyntheticsLocations that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/synthetics_locations#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogSyntheticsLocations to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_locations", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -177528,6 +177906,20 @@ export class DataDatadogSyntheticsTest extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_synthetics_test"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogSyntheticsTest resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogSyntheticsTest to import + * @param importFromId The id of the existing DataDatadogSyntheticsTest that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/synthetics_test#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogSyntheticsTest to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_test", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -177657,6 +178049,20 @@ export class DataDatadogUser extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "datadog_user"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataDatadogUser resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataDatadogUser to import + * @param importFromId The id of the existing DataDatadogUser that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/data-sources/user#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataDatadogUser to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_user", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -178050,6 +178456,20 @@ export class Downtime extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_downtime"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Downtime resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Downtime to import + * @param importFromId The id of the existing Downtime that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/downtime#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Downtime to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_downtime", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -178433,6 +178853,20 @@ export class IntegrationAwsLambdaArn extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_aws_lambda_arn"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationAwsLambdaArn resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationAwsLambdaArn to import + * @param importFromId The id of the existing IntegrationAwsLambdaArn that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_aws_lambda_arn#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationAwsLambdaArn to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_aws_lambda_arn", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -178568,6 +179002,20 @@ export class IntegrationAwsLogCollection extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_aws_log_collection"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationAwsLogCollection resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationAwsLogCollection to import + * @param importFromId The id of the existing IntegrationAwsLogCollection that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_aws_log_collection#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationAwsLogCollection to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_aws_log_collection", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -178709,6 +179157,20 @@ export class IntegrationAwsTagFilter extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_aws_tag_filter"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationAwsTagFilter resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationAwsTagFilter to import + * @param importFromId The id of the existing IntegrationAwsTagFilter that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_aws_tag_filter#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationAwsTagFilter to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_aws_tag_filter", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -178913,6 +179375,20 @@ export class IntegrationAws extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_aws"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationAws resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationAws to import + * @param importFromId The id of the existing IntegrationAws that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_aws#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationAws to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_aws", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -179239,6 +179715,20 @@ export class IntegrationAzure extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_azure"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationAzure resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationAzure to import + * @param importFromId The id of the existing IntegrationAzure that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_azure#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationAzure to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_azure", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -179455,6 +179945,20 @@ export class IntegrationGcp extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_gcp"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationGcp resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationGcp to import + * @param importFromId The id of the existing IntegrationGcp that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_gcp#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationGcp to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_gcp", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -179671,6 +180175,20 @@ export class IntegrationPagerdutyServiceObject extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_pagerduty_service_object"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationPagerdutyServiceObject resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationPagerdutyServiceObject to import + * @param importFromId The id of the existing IntegrationPagerdutyServiceObject that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_pagerduty_service_object#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationPagerdutyServiceObject to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_pagerduty_service_object", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -179812,6 +180330,20 @@ export class IntegrationPagerduty extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_pagerduty"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationPagerduty resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationPagerduty to import + * @param importFromId The id of the existing IntegrationPagerduty that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_pagerduty#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationPagerduty to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_pagerduty", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -180128,6 +180660,20 @@ export class IntegrationSlackChannel extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_integration_slack_channel"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IntegrationSlackChannel resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IntegrationSlackChannel to import + * @param importFromId The id of the existing IntegrationSlackChannel that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/integration_slack_channel#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IntegrationSlackChannel to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_integration_slack_channel", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -180340,6 +180886,20 @@ export class LogsArchiveOrder extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_archive_order"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsArchiveOrder resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsArchiveOrder to import + * @param importFromId The id of the existing LogsArchiveOrder that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_archive_order#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsArchiveOrder to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_archive_order", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -180954,6 +181514,20 @@ export class LogsArchive extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_archive"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsArchive resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsArchive to import + * @param importFromId The id of the existing LogsArchive that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_archive#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsArchive to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_archive", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -187632,6 +188206,20 @@ export class LogsCustomPipeline extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_custom_pipeline"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsCustomPipeline resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsCustomPipeline to import + * @param importFromId The id of the existing LogsCustomPipeline that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_custom_pipeline#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsCustomPipeline to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_custom_pipeline", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -187803,6 +188391,20 @@ export class LogsIndexOrder extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_index_order"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsIndexOrder resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsIndexOrder to import + * @param importFromId The id of the existing LogsIndexOrder that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_index_order#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsIndexOrder to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_index_order", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -188311,6 +188913,20 @@ export class LogsIndex extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_index"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsIndex resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsIndex to import + * @param importFromId The id of the existing LogsIndex that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_index#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsIndex to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_index", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -188512,6 +189128,20 @@ export class LogsIntegrationPipeline extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_integration_pipeline"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsIntegrationPipeline resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsIntegrationPipeline to import + * @param importFromId The id of the existing LogsIntegrationPipeline that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_integration_pipeline#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsIntegrationPipeline to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_integration_pipeline", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -188926,6 +189556,20 @@ export class LogsMetric extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_metric"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsMetric resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsMetric to import + * @param importFromId The id of the existing LogsMetric that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_metric#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsMetric to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_metric", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -189094,6 +189738,20 @@ export class LogsPipelineOrder extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_logs_pipeline_order"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LogsPipelineOrder resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LogsPipelineOrder to import + * @param importFromId The id of the existing LogsPipelineOrder that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/logs_pipeline_order#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LogsPipelineOrder to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_logs_pipeline_order", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -189259,6 +189917,20 @@ export class MetricMetadata extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_metric_metadata"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a MetricMetadata resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the MetricMetadata to import + * @param importFromId The id of the existing MetricMetadata that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/metric_metadata#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the MetricMetadata to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_metric_metadata", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -189627,6 +190299,20 @@ export class MetricTagConfiguration extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_metric_tag_configuration"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a MetricTagConfiguration resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the MetricTagConfiguration to import + * @param importFromId The id of the existing MetricTagConfiguration that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/metric_tag_configuration#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the MetricTagConfiguration to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_metric_tag_configuration", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -189813,6 +190499,20 @@ export class MonitorJson extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_monitor_json"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a MonitorJson resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the MonitorJson to import + * @param importFromId The id of the existing MonitorJson that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/monitor_json#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the MonitorJson to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_monitor_json", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -190421,6 +191121,20 @@ export class Monitor extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_monitor"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Monitor resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Monitor to import + * @param importFromId The id of the existing Monitor that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/monitor#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Monitor to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_monitor", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -191517,6 +192231,20 @@ export class OrganizationSettings extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_organization_settings"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a OrganizationSettings resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the OrganizationSettings to import + * @param importFromId The id of the existing OrganizationSettings that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/organization_settings#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the OrganizationSettings to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_organization_settings", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -191691,6 +192419,20 @@ export class DatadogProvider extends cdktf.TerraformProvider { // ================= public static readonly tfResourceType = "datadog"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DatadogProvider resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DatadogProvider to import + * @param importFromId The id of the existing DatadogProvider that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DatadogProvider to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -192002,6 +192744,20 @@ export class Role extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_role"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Role resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Role to import + * @param importFromId The id of the existing Role that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/role#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Role to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_role", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -192395,6 +193151,20 @@ export class SecurityMonitoringDefaultRule extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_security_monitoring_default_rule"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SecurityMonitoringDefaultRule resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SecurityMonitoringDefaultRule to import + * @param importFromId The id of the existing SecurityMonitoringDefaultRule that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/security_monitoring_default_rule#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SecurityMonitoringDefaultRule to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_security_monitoring_default_rule", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -192694,6 +193464,20 @@ export class SecurityMonitoringFilter extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_security_monitoring_filter"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SecurityMonitoringFilter resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SecurityMonitoringFilter to import + * @param importFromId The id of the existing SecurityMonitoringFilter that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/security_monitoring_filter#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SecurityMonitoringFilter to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_security_monitoring_filter", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -193993,6 +194777,20 @@ export class SecurityMonitoringRule extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_security_monitoring_rule"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SecurityMonitoringRule resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SecurityMonitoringRule to import + * @param importFromId The id of the existing SecurityMonitoringRule that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/security_monitoring_rule#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SecurityMonitoringRule to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_security_monitoring_rule", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -194565,6 +195363,20 @@ export class ServiceLevelObjective extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_service_level_objective"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ServiceLevelObjective resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ServiceLevelObjective to import + * @param importFromId The id of the existing ServiceLevelObjective that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/service_level_objective#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ServiceLevelObjective to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_service_level_objective", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -194877,6 +195689,20 @@ export class SloCorrection extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_slo_correction"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SloCorrection resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SloCorrection to import + * @param importFromId The id of the existing SloCorrection that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/slo_correction#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SloCorrection to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_slo_correction", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -195365,6 +196191,20 @@ export class SyntheticsGlobalVariable extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_synthetics_global_variable"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SyntheticsGlobalVariable resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SyntheticsGlobalVariable to import + * @param importFromId The id of the existing SyntheticsGlobalVariable that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/synthetics_global_variable#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SyntheticsGlobalVariable to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_global_variable", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -195687,6 +196527,20 @@ export class SyntheticsPrivateLocation extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_synthetics_private_location"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SyntheticsPrivateLocation resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SyntheticsPrivateLocation to import + * @param importFromId The id of the existing SyntheticsPrivateLocation that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/synthetics_private_location#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SyntheticsPrivateLocation to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_private_location", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -201846,6 +202700,20 @@ export class SyntheticsTest extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_synthetics_test"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SyntheticsTest resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SyntheticsTest to import + * @param importFromId The id of the existing SyntheticsTest that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/synthetics_test#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SyntheticsTest to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_synthetics_test", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -202340,6 +203208,20 @@ export class User extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_user"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a User resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the User to import + * @param importFromId The id of the existing User that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/user#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the User to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_user", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -202548,6 +203430,20 @@ export class WebhookCustomVariable extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_webhook_custom_variable"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a WebhookCustomVariable resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the WebhookCustomVariable to import + * @param importFromId The id of the existing WebhookCustomVariable that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/webhook_custom_variable#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the WebhookCustomVariable to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_webhook_custom_variable", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -202716,6 +203612,20 @@ export class Webhook extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_webhook"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Webhook resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Webhook to import + * @param importFromId The id of the existing Webhook that should be imported. Refer to the {@link https://registry.terraform.io/providers/datadog/datadog/3.12.0/docs/resources/webhook#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Webhook to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_webhook", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/__tests__/edge-provider-schema.test.ts b/packages/@cdktf/provider-generator/lib/__tests__/edge-provider-schema.test.ts index e16cec8347..3bbc57c456 100644 --- a/packages/@cdktf/provider-generator/lib/__tests__/edge-provider-schema.test.ts +++ b/packages/@cdktf/provider-generator/lib/__tests__/edge-provider-schema.test.ts @@ -3,7 +3,7 @@ import * as fs from "fs-extra"; import * as path from "path"; import { generateProviderBindingsFromSchema } from ".."; -import { mkdtemp } from "../util"; +import { mkdtemp } from "@cdktf/commons"; import { edgeSchema } from "./edge-provider-schema"; describe("Edge Provider Schema", () => { diff --git a/packages/@cdktf/provider-generator/lib/__tests__/provider.test.ts b/packages/@cdktf/provider-generator/lib/__tests__/provider.test.ts index a09ecf4d92..060039533c 100644 --- a/packages/@cdktf/provider-generator/lib/__tests__/provider.test.ts +++ b/packages/@cdktf/provider-generator/lib/__tests__/provider.test.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as fs from "fs-extra"; import { glob } from "glob"; -import { mkdtemp } from "../util"; +import { mkdtemp } from "@cdktf/commons"; import { ConstructsMaker } from "../get/constructs-maker"; import { Language, TerraformProviderConstraint } from "@cdktf/commons"; @@ -61,5 +61,47 @@ describe("Provider", () => { const snapshot = directorySnapshot(workdir); expect(snapshot).toMatchSnapshot(); }); - }, 600_000); + }, 600_000), + it("has generated provider that includes static import functions", async () => { + const constraint = new TerraformProviderConstraint( + "DataDog/datadog@= 3.12.0" + ); + return await mkdtemp(async (workdir) => { + const jsiiPath = path.join(workdir, ".jsii"); + const maker = new ConstructsMaker({ + codeMakerOutput: workdir, + outputJsii: jsiiPath, + targetLanguage: Language.TYPESCRIPT, + }); + await maker.generate([constraint]); + const snapshot = directorySnapshot(workdir); + + const terraformResourceTypesPresent: string[] = []; + const files = Object.keys(snapshot); + for (const file of files) { + const match = file.match(/providers\/datadog\/(.*?)\/index\.ts/); + // avoids any not resources from being pushed + if ( + match && + !match[1].includes("/") && + !match[1].includes("data-") && + !match[1].includes("provider") + ) { + terraformResourceTypesPresent.push(match[1]); + } + } + terraformResourceTypesPresent.forEach((resource) => { + let terraformResourceType = resource.replace(/-/g, "_"); + if (!terraformResourceType.includes("datadog")) { + terraformResourceType = `datadog_${terraformResourceType}`; + } + expect(snapshot[`providers/datadog/${resource}/index.ts`]).toContain( + `public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) {` + ); + expect(snapshot[`providers/datadog/${resource}/index.ts`]).toContain( + `return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "${terraformResourceType}", importId: importFromId, provider });` + ); + }); + }); + }, 600_000); }); diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap index 6abefde4e0..7d05d49a44 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap @@ -211,6 +211,20 @@ export class AcmCertificate extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_acm_certificate"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a AcmCertificate resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the AcmCertificate to import + * @param importFromId The id of the existing AcmCertificate that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the AcmCertificate to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_acm_certificate", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/description-escaping.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/description-escaping.test.ts.snap index 38e63ec64d..3f7e29228a 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/description-escaping.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/description-escaping.test.ts.snap @@ -34,6 +34,20 @@ export class DescriptionEscaping extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "description_escaping"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DescriptionEscaping resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DescriptionEscaping to import + * @param importFromId The id of the existing DescriptionEscaping that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/description_escaping#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DescriptionEscaping to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "description_escaping", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -122,6 +136,20 @@ export class CodeBlocks extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "code_blocks"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a CodeBlocks resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the CodeBlocks to import + * @param importFromId The id of the existing CodeBlocks that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/code_blocks#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the CodeBlocks to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "code_blocks", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -208,6 +236,20 @@ export class CodeBlocks extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "code_blocks"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a CodeBlocks resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the CodeBlocks to import + * @param importFromId The id of the existing CodeBlocks that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/code_blocks#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the CodeBlocks to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "code_blocks", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap index d24f876950..19f13dc617 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap @@ -107,6 +107,20 @@ export class Dashboard extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "datadog_dashboard"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Dashboard resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Dashboard to import + * @param importFromId The id of the existing Dashboard that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/datadog/latest/docs/resources/dashboard#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Dashboard to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "datadog_dashboard", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -146861,6 +146875,20 @@ export class Wafv2WebAcl extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_wafv2_web_acl"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Wafv2WebAcl resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Wafv2WebAcl to import + * @param importFromId The id of the existing Wafv2WebAcl that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Wafv2WebAcl to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_wafv2_web_acl", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap index 15b882c4bf..bb9ee16711 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap @@ -300,6 +300,20 @@ export class NestedTypesResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "nested_types_resource"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a NestedTypesResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the NestedTypesResource to import + * @param importFromId The id of the existing NestedTypesResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/nested_types_resource#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the NestedTypesResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "nested_types_resource", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/provider.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/provider.test.ts.snap index a52eae810c..ad52b71cb2 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/provider.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/provider.test.ts.snap @@ -1170,6 +1170,20 @@ export class AwsProvider extends cdktf.TerraformProvider { // ================= public static readonly tfResourceType = "aws"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a AwsProvider resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the AwsProvider to import + * @param importFromId The id of the existing AwsProvider that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the AwsProvider to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1687,6 +1701,20 @@ export class ElasticstackProvider extends cdktf.TerraformProvider { // ================= public static readonly tfResourceType = "elasticstack"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ElasticstackProvider resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ElasticstackProvider to import + * @param importFromId The id of the existing ElasticstackProvider that should be imported. Refer to the {@link https://registry.terraform.io/providers/elastic/elasticstack/latest/docs#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ElasticstackProvider to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "elasticstack", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap index e61b4f0aac..73296c0090 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap @@ -4020,6 +4020,20 @@ export class CloudfrontDistribution extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_cloudfront_distribution"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a CloudfrontDistribution resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the CloudfrontDistribution to import + * @param importFromId The id of the existing CloudfrontDistribution that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the CloudfrontDistribution to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_cloudfront_distribution", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -4505,6 +4519,20 @@ export class FmsAdminAccount extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_fms_admin_account"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a FmsAdminAccount resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the FmsAdminAccount to import + * @param importFromId The id of the existing FmsAdminAccount that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/fms_admin_account#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the FmsAdminAccount to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_fms_admin_account", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -7519,6 +7547,20 @@ export class S3Bucket extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_s3_bucket"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a S3Bucket resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the S3Bucket to import + * @param importFromId The id of the existing S3Bucket that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the S3Bucket to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_s3_bucket", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -8781,6 +8823,20 @@ export class SecurityGroup extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_security_group"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SecurityGroup resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SecurityGroup to import + * @param importFromId The id of the existing SecurityGroup that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SecurityGroup to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_security_group", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap index 1ba36d8779..a7ec1b65fc 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap @@ -688,6 +688,20 @@ export class QuicksightTemplate extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_quicksight_template"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a QuicksightTemplate resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the QuicksightTemplate to import + * @param importFromId The id of the existing QuicksightTemplate that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_template#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the QuicksightTemplate to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_quicksight_template", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/types.test.ts.snap b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/types.test.ts.snap index 569a70c078..51aa77d77f 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/types.test.ts.snap +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/generator/__snapshots__/types.test.ts.snap @@ -30,6 +30,20 @@ export class BooleanList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_boolean_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a BooleanList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the BooleanList to import + * @param importFromId The id of the existing BooleanList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/boolean_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the BooleanList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_boolean_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -142,6 +156,20 @@ export class BooleanMap extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_boolean_map"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a BooleanMap resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the BooleanMap to import + * @param importFromId The id of the existing BooleanMap that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/boolean_map#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the BooleanMap to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_boolean_map", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -353,6 +381,20 @@ export class ComputedComplex extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_computed_complex"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ComputedComplex resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ComputedComplex to import + * @param importFromId The id of the existing ComputedComplex that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/computed_complex#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ComputedComplex to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_computed_complex", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -558,6 +600,20 @@ export class ComputedComplexNested extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_computed_complex_nested"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ComputedComplexNested resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ComputedComplexNested to import + * @param importFromId The id of the existing ComputedComplexNested that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/computed_complex_nested#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ComputedComplexNested to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_computed_complex_nested", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -809,6 +865,20 @@ export class BlockTypeNestedComputedList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_block_type_nested_computed_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a BlockTypeNestedComputedList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the BlockTypeNestedComputedList to import + * @param importFromId The id of the existing BlockTypeNestedComputedList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/block_type_nested_computed_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the BlockTypeNestedComputedList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_block_type_nested_computed_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1209,6 +1279,20 @@ export class ComputedOptionalComplex extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_computed_optional_complex"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ComputedOptionalComplex resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ComputedOptionalComplex to import + * @param importFromId The id of the existing ComputedOptionalComplex that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/computed_optional_complex#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ComputedOptionalComplex to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_computed_optional_complex", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1489,6 +1573,20 @@ export class DeeplyNestedBlockTypes extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_deeply_nested_block_types"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DeeplyNestedBlockTypes resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DeeplyNestedBlockTypes to import + * @param importFromId The id of the existing DeeplyNestedBlockTypes that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/deeply_nested_block_types#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DeeplyNestedBlockTypes to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_deeply_nested_block_types", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1579,6 +1677,20 @@ export class IgnoredAttributes extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_ignored_attributes"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IgnoredAttributes resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IgnoredAttributes to import + * @param importFromId The id of the existing IgnoredAttributes that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ignored_attributes#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IgnoredAttributes to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_ignored_attributes", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1687,6 +1799,20 @@ export class IncompatibleAttributeNames extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_incompatible_attribute_names"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a IncompatibleAttributeNames resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the IncompatibleAttributeNames to import + * @param importFromId The id of the existing IncompatibleAttributeNames that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/incompatible_attribute_names#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the IncompatibleAttributeNames to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_incompatible_attribute_names", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1834,6 +1960,20 @@ export class FunctionResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_function"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a FunctionResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the FunctionResource to import + * @param importFromId The id of the existing FunctionResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/function#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the FunctionResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_function", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -1945,6 +2085,20 @@ export class LicenseResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_license"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a LicenseResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the LicenseResource to import + * @param importFromId The id of the existing LicenseResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/license#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the LicenseResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_license", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2032,6 +2186,20 @@ export class ObjectResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_object"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ObjectResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ObjectResource to import + * @param importFromId The id of the existing ObjectResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/object#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ObjectResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_object", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2119,6 +2287,20 @@ export class ProviderResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_provider"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ProviderResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ProviderResource to import + * @param importFromId The id of the existing ProviderResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/provider#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ProviderResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_provider", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2206,6 +2388,20 @@ export class StaticResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_static"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a StaticResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the StaticResource to import + * @param importFromId The id of the existing StaticResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/static#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the StaticResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_static", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2293,6 +2489,20 @@ export class StringResource extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_string"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a StringResource resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the StringResource to import + * @param importFromId The id of the existing StringResource that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/string#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the StringResource to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_string", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2728,6 +2938,20 @@ export class Complex extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "test_complex"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a Complex resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the Complex to import + * @param importFromId The id of the existing Complex that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/complex#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the Complex to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "test_complex", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -2932,6 +3156,20 @@ export class DataAirbyteSourceSchemaCatalog extends cdktf.TerraformDataSource { // ================= public static readonly tfResourceType = "airbyte_source_schema_catalog"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a DataAirbyteSourceSchemaCatalog resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the DataAirbyteSourceSchemaCatalog to import + * @param importFromId The id of the existing DataAirbyteSourceSchemaCatalog that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/data-sources/airbyte_source_schema_catalog#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the DataAirbyteSourceSchemaCatalog to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "airbyte_source_schema_catalog", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3027,6 +3265,20 @@ export class ListOfStringMap extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_list_of_string_map"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a ListOfStringMap resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the ListOfStringMap to import + * @param importFromId The id of the existing ListOfStringMap that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/list_of_string_map#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the ListOfStringMap to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_list_of_string_map", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3122,6 +3374,20 @@ export class MapOfStringList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_map_of_string_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a MapOfStringList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the MapOfStringList to import + * @param importFromId The id of the existing MapOfStringList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_string_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the MapOfStringList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_map_of_string_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3219,6 +3485,20 @@ export class NumberList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_number_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a NumberList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the NumberList to import + * @param importFromId The id of the existing NumberList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/number_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the NumberList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_number_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3325,6 +3605,20 @@ export class NumberMap extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_number_map"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a NumberMap resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the NumberMap to import + * @param importFromId The id of the existing NumberMap that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/number_map#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the NumberMap to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_number_map", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3444,6 +3738,20 @@ export class PrimitiveBoolean extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_primitive_boolean"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a PrimitiveBoolean resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the PrimitiveBoolean to import + * @param importFromId The id of the existing PrimitiveBoolean that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/primitive_boolean#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the PrimitiveBoolean to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_primitive_boolean", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3577,6 +3885,20 @@ export class PrimitiveDynamic extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_primitive_dynamic"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a PrimitiveDynamic resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the PrimitiveDynamic to import + * @param importFromId The id of the existing PrimitiveDynamic that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/primitive_dynamic#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the PrimitiveDynamic to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_primitive_dynamic", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3711,6 +4033,20 @@ export class PrimitiveNumber extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_primitive_number"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a PrimitiveNumber resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the PrimitiveNumber to import + * @param importFromId The id of the existing PrimitiveNumber that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/primitive_number#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the PrimitiveNumber to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_primitive_number", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3844,6 +4180,20 @@ export class PrimitiveString extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_primitive_string"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a PrimitiveString resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the PrimitiveString to import + * @param importFromId The id of the existing PrimitiveString that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/primitive_string#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the PrimitiveString to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_primitive_string", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -3981,6 +4331,20 @@ export class NameConflict extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_name_conflict"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a NameConflict resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the NameConflict to import + * @param importFromId The id of the existing NameConflict that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/name_conflict#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the NameConflict to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_name_conflict", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -4324,6 +4688,20 @@ export class BlockTypeSetList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_block_type_set_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a BlockTypeSetList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the BlockTypeSetList to import + * @param importFromId The id of the existing BlockTypeSetList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/block_type_set_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the BlockTypeSetList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_block_type_set_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -4506,6 +4884,20 @@ export class SingleBlockType extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_single_block_type"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a SingleBlockType resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the SingleBlockType to import + * @param importFromId The id of the existing SingleBlockType that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/single_block_type#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the SingleBlockType to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_single_block_type", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -4601,6 +4993,20 @@ export class StringList extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_string_list"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a StringList resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the StringList to import + * @param importFromId The id of the existing StringList that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/string_list#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the StringList to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_string_list", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== @@ -4734,6 +5140,20 @@ export class StringMap extends cdktf.TerraformResource { // ================= public static readonly tfResourceType = "aws_string_map"; + // ============== + // STATIC Methods + // ============== + /** + * Generates CDKTF code for importing a StringMap resource upon running "cdktf plan " + * @param scope The scope in which to define this construct + * @param importToId The construct id used in the generated config for the StringMap to import + * @param importFromId The id of the existing StringMap that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/string_map#import import section} in the documentation of this resource for the id to use + * @param provider? Optional instance of the provider where the StringMap to import is found + */ + public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "aws_string_map", importId: importFromId, provider }); + } + // =========== // INITIALIZER // =========== diff --git a/packages/@cdktf/provider-generator/lib/get/__tests__/util.ts b/packages/@cdktf/provider-generator/lib/get/__tests__/util.ts index a15dc10d21..b0c6354bdc 100644 --- a/packages/@cdktf/provider-generator/lib/get/__tests__/util.ts +++ b/packages/@cdktf/provider-generator/lib/get/__tests__/util.ts @@ -1,8 +1,11 @@ // Copyright (c) HashiCorp, Inc // SPDX-License-Identifier: MPL-2.0 import * as fs from "fs"; -import { withTempDir } from "../../util"; -import { Language, TerraformModuleConstraint } from "@cdktf/commons"; +import { + Language, + TerraformModuleConstraint, + withTempDir, +} from "@cdktf/commons"; import { ConstructsMaker } from "../constructs-maker"; import * as path from "path"; diff --git a/packages/@cdktf/provider-generator/lib/get/constructs-maker.ts b/packages/@cdktf/provider-generator/lib/get/constructs-maker.ts index 45e395491e..60b34b0381 100644 --- a/packages/@cdktf/provider-generator/lib/get/constructs-maker.ts +++ b/packages/@cdktf/provider-generator/lib/get/constructs-maker.ts @@ -3,7 +3,7 @@ import * as fs from "fs-extra"; import * as path from "path"; import { CodeMaker } from "codemaker"; -import { mkdtemp } from "../util"; +import { mkdtemp } from "@cdktf/commons"; import * as srcmak from "jsii-srcmak"; import { TerraformDependencyConstraint, diff --git a/packages/@cdktf/provider-generator/lib/get/generator/emitter/resource-emitter.ts b/packages/@cdktf/provider-generator/lib/get/generator/emitter/resource-emitter.ts index dc2be94a66..506eb69f4b 100644 --- a/packages/@cdktf/provider-generator/lib/get/generator/emitter/resource-emitter.ts +++ b/packages/@cdktf/provider-generator/lib/get/generator/emitter/resource-emitter.ts @@ -26,6 +26,9 @@ export class ResourceEmitter { this.emitHeader("STATIC PROPERTIES"); this.emitStaticProperties(resource); + this.emitHeader("STATIC Methods"); + this.emitStaticMethods(resource); + this.emitHeader("INITIALIZER"); this.emitInitializer(resource); @@ -52,6 +55,29 @@ export class ResourceEmitter { ); } + private emitStaticMethods(resource: ResourceModel) { + const comment = sanitizedComment(this.code); + comment.line( + `Generates CDKTF code for importing a ${resource.className} resource upon running "cdktf plan "` + ); + comment.line(`@param scope The scope in which to define this construct`); + comment.line( + `@param importToId The construct id used in the generated config for the ${resource.className} to import` + ); + comment.line( + `@param importFromId The id of the existing ${resource.className} that should be imported. Refer to the {@link ${resource.linkToDocs}#import import section} in the documentation of this resource for the id to use` + ); + comment.line( + `@param provider? Optional instance of the provider where the ${resource.className} to import is found` + ); + comment.end(); + this.code.line( + `public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktf.TerraformProvider) { + return new cdktf.ImportableResource(scope, importToId, { terraformResourceType: "${resource.terraformResourceType}", importId: importFromId, provider }); + }` + ); + } + private emitResourceSynthesis(resource: ResourceModel) { this.code.line(); this.code.openBlock( diff --git a/packages/@cdktf/provider-generator/lib/get/generator/models/attribute-model.ts b/packages/@cdktf/provider-generator/lib/get/generator/models/attribute-model.ts index 2df640ecd4..67b103e2f8 100644 --- a/packages/@cdktf/provider-generator/lib/get/generator/models/attribute-model.ts +++ b/packages/@cdktf/provider-generator/lib/get/generator/models/attribute-model.ts @@ -47,8 +47,10 @@ export function escapeAttributeName(name: string) { if (name === "system") return "systemAttribute"; // `tfResourceType` is already used by resources to distinguish between different resource types if (name === "tfResourceType") return `${name}Attribute`; + // `importFrom` has potential for common name collision with providers + if (name === "importFrom") return `${name}Attribute`; // `move` could have common name collision with providers - if (name === "move") return `${name}Attribute`; + if (name === "moveTo") return `${name}Attribute`; return name; } diff --git a/packages/@cdktf/provider-generator/lib/get/generator/provider-generator.ts b/packages/@cdktf/provider-generator/lib/get/generator/provider-generator.ts index 57777b5fe2..7863ff0d83 100644 --- a/packages/@cdktf/provider-generator/lib/get/generator/provider-generator.ts +++ b/packages/@cdktf/provider-generator/lib/get/generator/provider-generator.ts @@ -79,7 +79,9 @@ export class TerraformProviderGenerator { )}` ); throw new Error( - `Could not find provider with constraint ${providerConstraint}` + `Could not find provider with constraint ${JSON.stringify( + providerConstraint + )}` ); } diff --git a/packages/@cdktf/provider-generator/lib/util.ts b/packages/@cdktf/provider-generator/lib/util.ts index 722c85aa94..37b06d57e3 100644 --- a/packages/@cdktf/provider-generator/lib/util.ts +++ b/packages/@cdktf/provider-generator/lib/util.ts @@ -1,36 +1,6 @@ // Copyright (c) HashiCorp, Inc // SPDX-License-Identifier: MPL-2.0 -import * as fs from "fs-extra"; -import * as os from "os"; -import * as path from "path"; - -export async function withTempDir( - dirname: string, - closure: () => Promise -) { - const prevdir = process.cwd(); - const parent = await fs.mkdtemp(path.join(os.tmpdir(), "cdktf.")); - const workdir = path.join(parent, dirname); - await fs.mkdirp(workdir); - try { - process.chdir(workdir); - await closure(); - } finally { - process.chdir(prevdir); - await fs.remove(parent); - } -} - -export async function mkdtemp(closure: (dir: string) => Promise) { - const workdir = await fs.mkdtemp(path.join(os.tmpdir(), "cdktf.")); - try { - await closure(workdir); - } finally { - await fs.remove(workdir); - } -} - /** * Downcase the first character in a string. * diff --git a/packages/@cdktf/provider-schema/src/provider-schema.ts b/packages/@cdktf/provider-schema/src/provider-schema.ts index a1c2d53288..0ab3e2b402 100644 --- a/packages/@cdktf/provider-schema/src/provider-schema.ts +++ b/packages/@cdktf/provider-schema/src/provider-schema.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MPL-2.0 import * as fs from "fs-extra"; import * as path from "path"; -import { exec, withTempDir } from "./util"; + import { convertFiles } from "@cdktf/hcl2json"; import { ConstructsMakerModuleTarget, @@ -12,6 +12,8 @@ import { ModuleSchema, ProviderSchema, VersionSchema, + exec, + withTempDir, } from "@cdktf/commons"; const terraformBinaryName = process.env.TERRAFORM_BINARY_NAME || "terraform"; diff --git a/packages/cdktf-cli/package.json b/packages/cdktf-cli/package.json index cb4cbeb722..97fbe7b4ab 100644 --- a/packages/cdktf-cli/package.json +++ b/packages/cdktf-cli/package.json @@ -43,7 +43,7 @@ "@cdktf/hcl2cdk": "0.0.0", "@cdktf/hcl2json": "0.0.0", "@inquirer/prompts": "^2.3.0", - "@sentry/node": "^6.19.7", + "@sentry/node": "^7.64.0", "cdktf": "0.0.0", "ci-info": "^3.8.0", "codemaker": "^1.87.0", diff --git a/packages/cdktf/lib/backends/cloud-backend.ts b/packages/cdktf/lib/backends/cloud-backend.ts index e2de9a479d..2214a358ba 100644 --- a/packages/cdktf/lib/backends/cloud-backend.ts +++ b/packages/cdktf/lib/backends/cloud-backend.ts @@ -1,11 +1,11 @@ // Copyright (c) HashiCorp, Inc // SPDX-License-Identifier: MPL-2.0 import { Construct } from "constructs"; -import { keysToSnakeCase, deepMerge, terraformBinaryName } from "../util"; +import { keysToSnakeCase, deepMerge } from "../util"; import { DataTerraformRemoteState } from "./remote-backend"; import { TerraformRemoteState } from "../terraform-remote-state"; import { TerraformBackend } from "../terraform-backend"; -import { ValidateBinaryVersion } from "../validations"; +import { ValidateTerraformVersion } from "../validations/validate-terraform-version"; /** * checks whether the given hostname belongs to tfc or (else) to tfe @@ -30,10 +30,8 @@ export class CloudBackend extends TerraformBackend { super(scope, "backend", "cloud"); this.node.addValidation( - new ValidateBinaryVersion( - "terraform", + new ValidateTerraformVersion( ">=1.1", - `${terraformBinaryName} version`, `The cloud block is only supported for Terraform >=1.1. Please upgrade your Terraform version.` ) ); diff --git a/packages/cdktf/lib/importable-resource.ts b/packages/cdktf/lib/importable-resource.ts new file mode 100644 index 0000000000..e350b63b7d --- /dev/null +++ b/packages/cdktf/lib/importable-resource.ts @@ -0,0 +1,53 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { Construct } from "constructs"; +import { TerraformElement } from "./terraform-element"; +import { TerraformProvider } from "./terraform-provider"; +import { ValidateTerraformVersion } from "./validations/validate-terraform-version"; + +export interface IImportableConfig { + terraformResourceType: string; + importId: string; + provider?: TerraformProvider; +} + +/** + * Class used to represent an importable resource. + */ +export class ImportableResource extends TerraformElement { + constructor( + scope: Construct, + name: string, + private readonly config: IImportableConfig + ) { + super(scope, name, config.terraformResourceType); + this.node.addValidation( + new ValidateTerraformVersion( + ">=1.5", + `Import blocks are only supported for Terraform >=1.5. Please upgrade your Terraform version.` + ) + ); + } + + public toTerraform(): any { + const expectedResourceAddress = `${this.config.terraformResourceType}.${this.friendlyUniqueId}`; + return { + import: [ + { + to: expectedResourceAddress, + id: this.config.importId, + provider: this.config.provider ? this.config.provider.fqn : undefined, + }, + ], + }; + } + + public toMetadata(): any { + return { + importsGeneratingConfiguration: [this.friendlyUniqueId], + }; + } +} diff --git a/packages/cdktf/lib/index.ts b/packages/cdktf/lib/index.ts index 93e4b6b221..f038b48dc6 100644 --- a/packages/cdktf/lib/index.ts +++ b/packages/cdktf/lib/index.ts @@ -37,6 +37,7 @@ export * from "./terraform-iterator"; export * from "./terraform-provisioner"; export * from "./terraform-conditions"; export * from "./terraform-count"; +export * from "./importable-resource"; export * from "./terraform-resource-targets"; // required for JSII because Fn extends from it diff --git a/packages/cdktf/lib/terraform-resource.ts b/packages/cdktf/lib/terraform-resource.ts index 7807e70f2c..1e1bb742f0 100644 --- a/packages/cdktf/lib/terraform-resource.ts +++ b/packages/cdktf/lib/terraform-resource.ts @@ -23,6 +23,7 @@ import { RemoteExecProvisioner, } from "./terraform-provisioner"; import { TerraformStack } from "./terraform-stack"; +import { ValidateTerraformVersion } from "./validations/validate-terraform-version"; const TERRAFORM_RESOURCE_SYMBOL = Symbol.for("cdktf/TerraformResource"); @@ -78,6 +79,11 @@ export interface TerraformResourceMove { readonly renamed: boolean; } +export interface TerraformResourceImport { + readonly id: string; + readonly provider?: TerraformProvider; +} + // eslint-disable-next-line jsdoc/require-jsdoc export class TerraformResource extends TerraformElement @@ -97,6 +103,7 @@ export class TerraformResource public provisioners?: Array< FileProvisioner | LocalExecProvisioner | RemoteExecProvisioner >; + private _imported?: TerraformResourceImport; private _moved?: TerraformResourceMove; constructor(scope: Construct, id: string, config: TerraformResourceConfig) { @@ -224,18 +231,30 @@ export class TerraformResource from: this._moved.from, } : undefined, + import: this._imported + ? [ + { + provider: this._imported.provider?.fqn, + id: this._imported.id, + to: `${this.terraformResourceType}.${this.friendlyUniqueId}`, + }, + ] + : undefined, }; } public toMetadata(): any { - if (!Object.keys(this.rawOverrides).length) { - return {}; - } - return { - overrides: { - [this.terraformResourceType]: Object.keys(this.rawOverrides), - }, + overrides: Object.keys(this.rawOverrides).length + ? { + [this.terraformResourceType]: Object.keys(this.rawOverrides), + } + : undefined, + imports: this._imported + ? { + [this.terraformResourceType]: [this.friendlyUniqueId], + } + : undefined, moved: this._moved ? { [this.terraformResourceType]: [this.friendlyUniqueId], // TODO: anything more we need here? @@ -257,6 +276,16 @@ export class TerraformResource return TerraformStack.of(this).moveTargets; } + public importFrom(id: string, provider?: TerraformProvider) { + this._imported = { id, provider }; + this.node.addValidation( + new ValidateTerraformVersion( + ">=1.5", + `Import blocks are only supported for Terraform >=1.5. Please upgrade your Terraform version.` + ) + ); + } + /** * Moves this resource to the location denoted by moveTarget. * @param moveTarget The previously set string moveTarget denoting the location of the move diff --git a/packages/cdktf/lib/validations/validate-terraform-version.ts b/packages/cdktf/lib/validations/validate-terraform-version.ts new file mode 100644 index 0000000000..261d84bf44 --- /dev/null +++ b/packages/cdktf/lib/validations/validate-terraform-version.ts @@ -0,0 +1,21 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { terraformBinaryName } from "../util"; +import { ValidateBinaryVersion } from "./validate-binary-version"; + +/** + * Validates the existence of a Terraform binary and with a certain version or higher. + */ +export class ValidateTerraformVersion extends ValidateBinaryVersion { + constructor(protected versionConstraint: string, protected hint?: string) { + super( + terraformBinaryName, + versionConstraint, + `${terraformBinaryName} version`, + hint + ); + } +} diff --git a/packages/cdktf/test/__snapshots__/resource.test.ts.snap b/packages/cdktf/test/__snapshots__/resource.test.ts.snap index 96442c70ae..7a43ab856b 100644 --- a/packages/cdktf/test/__snapshots__/resource.test.ts.snap +++ b/packages/cdktf/test/__snapshots__/resource.test.ts.snap @@ -91,6 +91,70 @@ exports[`do not change capitalization of tags 1`] = ` }" `; +exports[`includes import block when import is present 1`] = ` +"{ + "import": [ + { + "id": "testId", + "to": "test_resource.test" + } + ], + "provider": { + "test": [ + { + } + ] + }, + "resource": { + "test_resource": { + "test": { + "name": "foo" + } + } + }, + "terraform": { + "required_providers": { + "test": { + "version": "~> 2.0" + } + } + } +}" +`; + +exports[`includes import block when import is present, provider given 1`] = ` +"{ + "import": [ + { + "id": "testId", + "provider": "test.foo", + "to": "test_resource.test" + } + ], + "provider": { + "test": [ + { + "alias": "foo" + } + ] + }, + "resource": { + "test_resource": { + "test": { + "name": "foo" + } + } + }, + "terraform": { + "required_providers": { + "test": { + "version": "~> 2.0" + } + } + } +}" +`; + exports[`maintains the same order of provisioner 1`] = ` "{ "provider": { diff --git a/packages/cdktf/test/resource.test.ts b/packages/cdktf/test/resource.test.ts index 6c0d87c8c5..2514aae4cd 100644 --- a/packages/cdktf/test/resource.test.ts +++ b/packages/cdktf/test/resource.test.ts @@ -328,6 +328,29 @@ it("maintains the same order of provisioner", () => { expect(Testing.synth(stack)).toMatchSnapshot(); }); +test("includes import block when import is present", () => { + const app = Testing.app(); + const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); + + new TestResource(stack, "test", { + name: "foo", + }).importFrom("testId"); + expect(Testing.synth(stack)).toMatchSnapshot(); +}); + +test("includes import block when import is present, provider given", () => { + const app = Testing.app(); + const stack = new TerraformStack(app, "test"); + const provider = new TestProvider(stack, "provider", { + alias: "foo", + }); + new TestResource(stack, "test", { + name: "foo", + }).importFrom("testId", provider); + expect(Testing.synth(stack)).toMatchSnapshot(); +}); + it("moves resource to greater nesting in contained construct", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); diff --git a/test/csharp/no-color-command-option-test/test.ts b/test/csharp/no-color-command-option-test/test.ts index 206d36e512..dea3d897b5 100644 --- a/test/csharp/no-color-command-option-test/test.ts +++ b/test/csharp/no-color-command-option-test/test.ts @@ -22,6 +22,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf diff", async () => { @@ -29,6 +31,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { env: driver.env, cwd: driver.workingDirectory, }); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf destroy", async () => { @@ -40,6 +44,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); }); diff --git a/test/go/no-color-command-option-test/test.ts b/test/go/no-color-command-option-test/test.ts index a3122ef4ed..8c5ca74c38 100644 --- a/test/go/no-color-command-option-test/test.ts +++ b/test/go/no-color-command-option-test/test.ts @@ -22,6 +22,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf diff", async () => { @@ -29,6 +31,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { env: driver.env, cwd: driver.workingDirectory, }); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf destroy", async () => { @@ -40,6 +44,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); }); diff --git a/test/java/no-color-command-option-test/test.ts b/test/java/no-color-command-option-test/test.ts index d8cd3eb670..22c12422a4 100644 --- a/test/java/no-color-command-option-test/test.ts +++ b/test/java/no-color-command-option-test/test.ts @@ -25,6 +25,8 @@ describe.skip("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf diff", async () => { @@ -32,6 +34,8 @@ describe.skip("no-color option for cdktf deploy, diff, destroy", () => { env: driver.env, cwd: driver.workingDirectory, }); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf destroy", async () => { @@ -43,6 +47,8 @@ describe.skip("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); }); diff --git a/test/python/no-color-command-option-test/test.ts b/test/python/no-color-command-option-test/test.ts index a7cf33f7a2..72e684314e 100644 --- a/test/python/no-color-command-option-test/test.ts +++ b/test/python/no-color-command-option-test/test.ts @@ -22,6 +22,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf diff", async () => { @@ -29,6 +31,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { env: driver.env, cwd: driver.workingDirectory, }); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf destroy", async () => { @@ -40,6 +44,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); }); diff --git a/test/typescript/no-color-command-option-test/test.ts b/test/typescript/no-color-command-option-test/test.ts index 1007076f1a..c1d29c55e8 100644 --- a/test/typescript/no-color-command-option-test/test.ts +++ b/test/typescript/no-color-command-option-test/test.ts @@ -20,6 +20,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf diff", async () => { @@ -27,6 +29,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { env: driver.env, cwd: driver.workingDirectory, }); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); onPosix("contains no color formatting in cdktf destroy", async () => { @@ -38,6 +42,8 @@ describe("no-color option for cdktf deploy, diff, destroy", () => { cwd: driver.workingDirectory, } ); + // These tests are sometimes flaky, therefore we log the result here to ensure we can debug it properly + console.log(result.stdout); expect(hasAnsi(result.stdout)).toBe(false); }); }); diff --git a/website/docs/cdktf/concepts/resources.mdx b/website/docs/cdktf/concepts/resources.mdx index bccba03598..e00e41cb4e 100644 --- a/website/docs/cdktf/concepts/resources.mdx +++ b/website/docs/cdktf/concepts/resources.mdx @@ -459,6 +459,235 @@ If you need to use the special [`self` object](/terraform/language/resources/pro If you need to ensure a condition is met either before or after a resource was created you can specify [conditions](/terraform/language/expressions/custom-conditions#preconditions-and-postconditions). To add one configure the `lifecycle` key on your resource with an object containing a `precondition` and / or a `postcondition`. These keys take a list of conditions with a `condition` key containing a Terraform Expression to be evaluated and an `errorMessage` key containing a string to be displayed if the condition is not met. +## Importing Resources + +If you have existing resources that you want to manage with CDKTF, you can import them into your CDKTF application. The best way to do this is using the [`import` block feature](/terraform/language/import) of Terraform >= 1.5. You can do this in CDKTF either with a specified configuration or without. + +### How To Import + +To import a resource, first instantiate an instance of the resource type you wish to import – in our case we'll be using an S3Bucket. No configuration is explicitly needed. You then call the `importFrom` method on the resource object. This method takes the ID of the resource to be imported as the first argument and the provider as an optional second. The provider is only required if you have multiple providers of the same type in your configuration. + +```typescript +new S3Bucket(this, "bucket", {}).importFrom(bucketId); +``` + +When running plan / apply you will get the information that your resource is going to be imported. Once you have ran apply, you can remove the `importFrom` call and the resource will become managed by CDKTF. + +Please note that Terraform is going to update existing fields on the imported resource to match your configuration as it puts it under management. In our case we did not define any specific properties on the `S3Bucket` which causes Terraform e.g. to remove the tags currently defined on the resource (as can be seen on the plan below). If you want to keep existing settings, you can run a plan first, add everything that Terraform would change to your resource config, and only then apply the changes. + +Your output might look as follows: + +``` +ts-import Initializing the backend... +ts-import Initializing provider plugins... +ts-import - Reusing previous version of hashicorp/aws from the dependency lock file +ts-import - Using previously-installed hashicorp/aws v5.5.0 +ts-import Terraform has been successfully initialized! + + You may now begin working with Terraform. Try running "terraform plan" to see + any changes that are required for your infrastructure. All Terraform commands + should now work. + + If you ever set or change modules or backend configuration for Terraform, + rerun this command to reinitialize your working directory. If you forget, other + commands will detect it and remind you to do so if necessary. +ts-import aws_s3_bucket.bucket (bucket): Preparing import... [id=best-bucket-in-the-world] +ts-import aws_s3_bucket.bucket (bucket): Refreshing state... [id=best-bucket-in-the-world] +ts-import Terraform used the selected providers to generate the following execution + plan. Resource actions are indicated with the following symbols: + ~ update in-place + + Terraform will perform the following actions: +ts-import # aws_s3_bucket.bucket (bucket) will be updated in-place + # (imported from "best-bucket-in-the-world") + ~ resource "aws_s3_bucket" "bucket" { + arn = "arn:aws:s3:::best-bucket-in-the-world" + bucket = "best-bucket-in-the-world" + bucket_domain_name = "best-bucket-in-the-world.s3.amazonaws.com" + bucket_regional_domain_name = "best-bucket-in-the-world.s3.us-east-1.amazonaws.com" + + force_destroy = false + hosted_zone_id = "XXXXXXXXXXXXX" + id = "best-bucket-in-the-world" + object_lock_enabled = false + region = "us-east-1" + request_payer = "BucketOwner" + ~ tags = { + - "foo" = "bar" -> null + } + ~ tags_all = { + - "foo" = "bar" + } -> (known after apply) + + grant { + id = "XXXXXXXXXXXXX" + permissions = [ + "FULL_CONTROL", + ] + type = "CanonicalUser" + } + + server_side_encryption_configuration { + rule { + bucket_key_enabled = true + + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } + } + + versioning { + enabled = true + mfa_delete = false + } + } + + Plan: 1 to import, 0 to add, 1 to change, 0 to destroy. + + ───────────────────────────────────────────────────────────────────────────── + + Saved the plan to: plan + + To perform exactly these actions, run the following command to apply: + terraform apply "plan" +``` + +### Generate Configuration For Import + +If you don't want to specify the configuration of your imported resource yourself you can use the static method `generateConfigForImport` on the class of the resource you want to import. This method takes the scope as the first argument, the construct id of the resource to import to (as will be given in the generated config returned), the resource id of the resource to be imported, and the provider as an optional fourth. The provider is only required if you have multiple providers of the same type in your configuration. + +```typescript +S3Bucket.generateConfigForImport(this, "bucket", bucketId); +``` + +When running `cdktf plan ` Terraform will generate code for the resource you are importing and CDKTF will convert it to the language you are using. + +Your output might look as follows: + +``` +ts-import-with-configuration Initializing the backend... +ts-import-with-configuration Initializing provider plugins... + - Reusing previous version of hashicorp/aws from the dependency lock file +ts-import-with-configuration - Using previously-installed hashicorp/aws v5.18.1 + + Terraform has been successfully initialized! +ts-import-with-configuration + You may now begin working with Terraform. Try running "terraform plan" to see + any changes that are required for your infrastructure. All Terraform commands + should now work. + + If you ever set or change modules or backend configuration for Terraform, + rerun this command to reinitialize your working directory. If you forget, other + commands will detect it and remind you to do so if necessary. +ts-import-with-configuration aws_s3_bucket.bucket: Preparing import... [id=best-bucket-in-the-world] +ts-import-with-configuration aws_s3_bucket.bucket: Refreshing state... [id=best-bucket-in-the-world] +ts-import-with-configuration Terraform will perform the following actions: +ts-import-with-configuration # aws_s3_bucket.bucket will be imported + # (config will be generated) + resource "aws_s3_bucket" "bucket" { + arn = "arn:aws:s3:::best-bucket-in-the-world" + bucket = "best-bucket-in-the-world" + bucket_domain_name = "best-bucket-in-the-world.s3.amazonaws.com" + bucket_regional_domain_name = "best-bucket-in-the-world.s3.us-east-1.amazonaws.com" + hosted_zone_id = "Z3AQBSTGFYJSTF" + id = "best-bucket-in-the-world" + object_lock_enabled = false + region = "us-east-1" + request_payer = "BucketOwner" + tags = {} + tags_all = {} + + grant { + id = "554912fda2704333d162d216be50aefb05562e0bf1709997f1d9417cf46087d5" + permissions = [ + "FULL_CONTROL", + ] + type = "CanonicalUser" + } + + server_side_encryption_configuration { + rule { + bucket_key_enabled = true + + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } + } + + versioning { + enabled = false + mfa_delete = false + } + } + + Plan: 1 to import, 0 to add, 0 to change, 0 to destroy. + ╷ + │ Warning: Config generation is experimental + │ + │ Generating configuration during import is currently experimental, and the + │ generated configuration format may change in future versions. + ╵ + + ───────────────────────────────────────────────────────────────────────────── + + Terraform has generated configuration and written it to + generated_resources.tf. Please review the configuration and edit it as + necessary before adding it to version control. + + Saved the plan to: plan + + To perform exactly these actions, run the following command to apply: + terraform apply "plan" +ts-import-with-configuration Import without configuration detected. Terraform has created configuration for it: + # __generated__ by Terraform + # Please review these resources and move them into your main configuration files. + + # __generated__ by Terraform from "best-bucket-in-the-world" + resource "aws_s3_bucket" "bucket" { + bucket = "best-bucket-in-the-world" + bucket_prefix = null + force_destroy = null + object_lock_enabled = false + tags = {} + tags_all = {} + } + + + CDKTF has translated the code to the following: + + import { Construct } from "constructs"; + /* + * Provider bindings are generated by running `cdktf get`. + * See https://cdk.tf/provider-generation for more details. + */ + import { S3Bucket } from "./.gen/providers/aws/s3-bucket"; + class MyConvertedCode extends Construct { + constructor(scope: Construct, name: string) { + super(scope, name); + new S3Bucket(this, "bucket", { + bucket: "best-bucket-in-the-world", + bucketPrefix: [null], + forceDestroy: [null], + objectLockEnabled: false, + tags: {}, + tagsAll: {}, + }); + } + } + + + Please review the code and make any necessary changes before adding it to your codebase. + Make sure to only copy the code within the construct's constructor. + + NOTE: Your resource has not yet become managed by CDKTF. + To finish the import remove the call "generateConfigForImport", add the above code within the construct's constructor, and then append the call importFrom() to the generated code: + + new SomeResource(...).importFrom("some_id") +``` + +Though at this point, your resource has not been imported. To import, first add the new generated configuration to your project, then remove the initial call of `generateConfigForImport`. Finally, follow the steps outlined in the section "How To Import" above. On apply, your resource will be imported, then becoming managed by CDKTF. + ## Escape Hatch Terraform provides [meta-arguments](/terraform/language/resources/syntax#meta-arguments) to change resource behavior. For example, the `for_each` meta-argument creates multiple resource instances according to a map, or set of strings. The escape hatch allows you to use these meta-arguments to your CDKTF application and to override attributes that CDKTF cannot yet fully express. diff --git a/yarn.lock b/yarn.lock index 6261b5bf9e..e77ba75f61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1945,17 +1945,6 @@ "@sentry/utils" "7.64.0" tslib "^2.4.1 || ^1.9.3" -"@sentry/core@6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.19.7.tgz#156aaa56dd7fad8c89c145be6ad7a4f7209f9785" - integrity sha512-tOfZ/umqB2AcHPGbIrsFLcvApdTm9ggpi/kQZFkej7kMphjT+SGBiQfYtjyg9jcRW+ilAR4JXC9BGKsdEQ+8Vw== - dependencies: - "@sentry/hub" "6.19.7" - "@sentry/minimal" "6.19.7" - "@sentry/types" "6.19.7" - "@sentry/utils" "6.19.7" - tslib "^1.9.3" - "@sentry/core@7.64.0": version "7.64.0" resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.64.0.tgz#9d61cdc29ba299dedbdcbe01cfadf94bd0b7df48" @@ -1965,38 +1954,6 @@ "@sentry/utils" "7.64.0" tslib "^2.4.1 || ^1.9.3" -"@sentry/hub@6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.19.7.tgz#58ad7776bbd31e9596a8ec46365b45cd8b9cfd11" - integrity sha512-y3OtbYFAqKHCWezF0EGGr5lcyI2KbaXW2Ik7Xp8Mu9TxbSTuwTe4rTntwg8ngPjUQU3SUHzgjqVB8qjiGqFXCA== - dependencies: - "@sentry/types" "6.19.7" - "@sentry/utils" "6.19.7" - tslib "^1.9.3" - -"@sentry/minimal@6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.19.7.tgz#b3ee46d6abef9ef3dd4837ebcb6bdfd01b9aa7b4" - integrity sha512-wcYmSJOdvk6VAPx8IcmZgN08XTXRwRtB1aOLZm+MVHjIZIhHoBGZJYTVQS/BWjldsamj2cX3YGbGXNunaCfYJQ== - dependencies: - "@sentry/hub" "6.19.7" - "@sentry/types" "6.19.7" - tslib "^1.9.3" - -"@sentry/node@^6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.19.7.tgz#32963b36b48daebbd559e6f13b1deb2415448592" - integrity sha512-gtmRC4dAXKODMpHXKfrkfvyBL3cI8y64vEi3fDD046uqYcrWdgoQsffuBbxMAizc6Ez1ia+f0Flue6p15Qaltg== - dependencies: - "@sentry/core" "6.19.7" - "@sentry/hub" "6.19.7" - "@sentry/types" "6.19.7" - "@sentry/utils" "6.19.7" - cookie "^0.4.1" - https-proxy-agent "^5.0.0" - lru_map "^0.3.3" - tslib "^1.9.3" - "@sentry/node@^7.64.0": version "7.64.0" resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.64.0.tgz#c6f7a67c1442324298f0525e7191bc18572ee1ce" @@ -2011,24 +1968,11 @@ lru_map "^0.3.3" tslib "^2.4.1 || ^1.9.3" -"@sentry/types@6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.19.7.tgz#c6b337912e588083fc2896eb012526cf7cfec7c7" - integrity sha512-jH84pDYE+hHIbVnab3Hr+ZXr1v8QABfhx39KknxqKWr2l0oEItzepV0URvbEhB446lk/S/59230dlUUIBGsXbg== - "@sentry/types@7.64.0": version "7.64.0" resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.64.0.tgz#21fc545ea05c3c8c4c3e518583eca1a8c5429506" integrity sha512-LqjQprWXjUFRmzIlUjyA+KL+38elgIYmAeoDrdyNVh8MK5IC1W2Lh1Q87b4yOiZeMiIhIVNBd7Ecoh2rodGrGA== -"@sentry/utils@6.19.7": - version "6.19.7" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.19.7.tgz#6edd739f8185fd71afe49cbe351c1bbf5e7b7c79" - integrity sha512-z95ECmE3i9pbWoXQrD/7PgkBAzJYR+iXtPuTkpBjDKs86O3mT+PXOT3BAn79w2wkn7/i3vOGD2xVr1uiMl26dA== - dependencies: - "@sentry/types" "6.19.7" - tslib "^1.9.3" - "@sentry/utils@7.64.0": version "7.64.0" resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.64.0.tgz#6fe3ce9a56d3433ed32119f914907361a54cc184" @@ -11583,7 +11527,7 @@ tsconfig-paths@^4.1.2: minimist "^1.2.6" strip-bom "^3.0.0" -tslib@^1.8.1, tslib@^1.9.3: +tslib@^1.8.1: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== @@ -11872,10 +11816,10 @@ uuid@8.3.2, uuid@^8.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== -uuid@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5" - integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg== +uuid@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== v8-compile-cache-lib@^3.0.1: version "3.0.1"