Skip to content

Commit

Permalink
fix: terraform module validation (#4509)
Browse files Browse the repository at this point in the history
* fix: terraform module validation

* chore: terraform-plugin: add test for terraform module type

* chore: terraform-plugin: add regression test for validation

* chore: terraform-plugin: fix gitignore for lockfiles

* chore: add license header
  • Loading branch information
Walther committed Jun 1, 2023
1 parent e5e742f commit 15483b2
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 5 deletions.
1 change: 0 additions & 1 deletion plugins/terraform/common.ts
Expand Up @@ -25,7 +25,6 @@ export const variablesSchema = () => joiStringMap(joi.any())
export interface TerraformBaseSpec {
allowDestroy: boolean
autoApply: boolean
dependencies: string[]
variables: PrimitiveMap
version: string | null
workspace?: string
Expand Down
14 changes: 11 additions & 3 deletions plugins/terraform/index.ts
Expand Up @@ -7,6 +7,7 @@
*/

import { join } from "path"
import { omit } from "lodash"
import { pathExists } from "fs-extra"
import { createGardenPlugin } from "@garden-io/sdk"
import { cleanupEnvironment, getEnvironmentStatus, prepareEnvironment } from "./init"
Expand Down Expand Up @@ -191,7 +192,7 @@ export const gardenPlugin = () =>
actions.push(dummyBuild)
}

actions.push({
const deployAction: TerraformDeployConfig = {
kind: "Deploy",
type: "terraform",
name: module.name,
Expand All @@ -202,9 +203,16 @@ export const gardenPlugin = () =>

timeout: defaultTerraformTimeoutSec,
spec: {
...module.spec,
allowDestroy: module.spec.allowDestroy || true,
autoApply: module.spec.autoApply || true,
root: module.spec.root || ".",
variables: module.spec.variables || {},
version: module.spec.version || defaultTerraformVersion,
...omit(module.spec, ["build", "dependencies"]),
},
})
}

actions.push(deployAction)

return {
group: {
Expand Down
1 change: 1 addition & 0 deletions plugins/terraform/module.ts
Expand Up @@ -19,6 +19,7 @@ import { terraformDeploySchemaKeys } from "./action"

export interface TerraformModuleSpec extends TerraformBaseSpec {
root: string
dependencies: string[]
}

export interface TerraformModule extends GardenModule<TerraformModuleSpec> {}
Expand Down
2 changes: 1 addition & 1 deletion plugins/terraform/test/.gitignore
@@ -1 +1 @@
test-project/**/*.lock.hcl
**/.terraform.lock.hcl

0 comments on commit 15483b2

Please sign in to comment.