Skip to content

Commit

Permalink
Merge pull request #13 from daltonmatos/feat/fix-multiple-versions-crds
Browse files Browse the repository at this point in the history
Corrige erro de validação para CRDs com múltiplas versões usando tipos complexos (object, array)
  • Loading branch information
lukerops authored Mar 6, 2024
2 parents 505e7e3 + 759aa10 commit de23ba2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
9 changes: 0 additions & 9 deletions modules/CustomResourceDefinition/v1alpha1/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ output "schemas" {
)
}

precondition {
condition = can(tolist(var.manifest.spec.versions))
error_message = format(
local.error_messages.versions_field_is_not_a_list,
var.manifest.metadata.name,
var.manifest.path,
)
}

precondition {
condition = try(
length(var.manifest.spec.versions) > 0,
Expand Down
48 changes: 48 additions & 0 deletions tests/fixtures/user.gcp.iam.crd_with_multiple_versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: tf-gapi.lukerops.com/v1alpha1
kind: CustomResourceDefinition
metadata:
name: user.gcp.iam
spec:
group: gcp.iam
kind: User
versions:
- name: v1alpha1
specSchema:
type: object
properties:
namme:
type: string
active:
type: bool
extra:
type: array
items:
type: integer
- name: v1alpha2
specSchema:
type: object
properties:
myname:
type: string
other:
type: object
properties:
name:
type: string
active:
type: bool
- name: v1alpha3
specSchema:
type: object
properties:
name:
type: string
active:
type: bool

- name: v1alpha4
specSchema:
type: object
properties:
othername:
type: string
16 changes: 16 additions & 0 deletions tests/test_crd_with_multiple_versions.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

run "parse_crd_with_multiple_versions" {
command = plan

variables {
yamls = [
"tests/fixtures/user.gcp.iam.crd_with_multiple_versions.yaml"
]
}

assert {
condition = length(module.custom_resource_definitions_v1alpha1[0].schemas) == 4
error_message = "Não parseou todas as versões do CRD"
}

}

0 comments on commit de23ba2

Please sign in to comment.