Skip to content

Commit

Permalink
go generate
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed Apr 28, 2024
1 parent 115ba7e commit 69a30e7
Show file tree
Hide file tree
Showing 15 changed files with 547 additions and 134 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/hashicorp/terraform-plugin-codegen-kubernetes v0.0.0-00010101000000-000000000000
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.7.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
github.com/hashicorp/terraform-plugin-go v0.22.1
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.15.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFcc
github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA=
github.com/hashicorp/terraform-plugin-framework v1.7.0 h1:wOULbVmfONnJo9iq7/q+iBOBJul5vRovaYJIu2cY/Pw=
github.com/hashicorp/terraform-plugin-framework v1.7.0/go.mod h1:jY9Id+3KbZ17OMpulgnWLSfwxNVYSoYBQFTgsx044CI=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY=
github.com/hashicorp/terraform-plugin-go v0.22.1 h1:iTS7WHNVrn7uhe3cojtvWWn83cm2Z6ryIUDTRO0EV7w=
github.com/hashicorp/terraform-plugin-go v0.22.1/go.mod h1:qrjnqRghvQ6KnDbB12XeZ4FluclYwptntoWCr9QaXTI=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand Down
50 changes: 22 additions & 28 deletions internal/framework/provider/corev1/base64.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package corev1

// func (r *Secret) BeforeCreate(m *SecretModel) {
// m.Data = base64EncodeStringMap(m.Data)
// }
import (
"encoding/base64"

// func (r *Secret) AfterCreate(m *SecretModel) {
// m.Data = base64DecodeStringMap(m.Data)
// }
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// func (r *Namespace) AfterCreate(m *NamespaceModel) {
// panic("damn")
// }
func base64EncodeStringMap(m map[string]basetypes.StringValue) map[string]basetypes.StringValue {
result := make(map[string]basetypes.StringValue)
for k, v := range m {
value := v.ValueString()
output := base64.StdEncoding.EncodeToString([]byte(value))
result[k] = basetypes.NewStringValue(output)
}
return result
}

// func base64EncodeStringMap(m map[string]basetypes.StringValue) map[string]basetypes.StringValue {
// result := make(map[string]basetypes.StringValue)
// for k, v := range m {
// value := v.ValueString()
// output := base64.StdEncoding.EncodeToString([]byte(value))
// result[k] = basetypes.NewStringValue(output)
// }
// return result
// }

// func base64DecodeStringMap(m map[string]basetypes.StringValue) map[string]basetypes.StringValue {
// result := make(map[string]basetypes.StringValue)
// for k, v := range m {
// value := v.ValueString()
// output, _ := base64.StdEncoding.DecodeString(value)
// result[k] = basetypes.NewStringValue(string(output))
// }
// return result
// }
func base64DecodeStringMap(m map[string]basetypes.StringValue) map[string]basetypes.StringValue {
result := make(map[string]basetypes.StringValue)
for k, v := range m {
value := v.ValueString()
output, _ := base64.StdEncoding.DecodeString(value)
result[k] = basetypes.NewStringValue(string(output))
}
return result
}
117 changes: 55 additions & 62 deletions internal/framework/provider/corev1/generate_namespace.hcl
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
// resource "kubernetes_namespace_v1_gen" {
// package = "corev1"

// api_version = "v1"
// kind = "Namespace"

// description = "description for namespace"

// output_filename_prefix = "namespace"

// openapi {
// filename = "./codegen/data/kubernetes-v1.28.3/api/openapi-spec/v3/api__v1_openapi.json"
// create_path = "/api/v1/namespaces"
// read_path = "/api/v1/namespaces/{name}"
// }

// generate {
// schema = true
// model = true
// autocrud = true

// autocrud_options {
// wait_for_deletion = true

// }
// autocrud_hooks{
// before_create = false
// after_create = false
// }
// }


// ignored_attributes = [
// "api_version",
// "kind",
// "metadata.finalizers",
// "metadata.managed_fields",
// "metadata.owner_references",
// "metadata.self_link",
// "metadata.creation_timestamp",
// "metadata.deletion_timestamp",
// "metadata.deletion_grace_period_seconds",
// "spec",
// "status"
// ]

// computed_attributes = [
// "metadata.uid",
// "metadata.resource_version",
// "metadata.generation",
// "metadata.name"
// ]

// immutable_attributes = [
// "metadata.name",
// "metadata.generate_name"
// ]

// required_attributes = [
// "metadata"
// ]
// }
resource "kubernetes_namespace_v1_gen" {
package = "corev1"

api_version = "v1"
kind = "Namespace"

description = "namespace"

output_filename_prefix = "namespace"

openapi {
filename = "./codegen/data/kubernetes-v1.28.3/api/openapi-spec/v3/api__v1_openapi.json"
create_path = "/api/v1/namespaces"
read_path = "/api/v1/namespaces/{name}"
}

generate {
schema = true
model = true
autocrud = true

autocrud_options {
wait_for_deletion = true
}
}

ignored_attributes = [
"api_version",
"kind",
"metadata.finalizers",
"metadata.managed_fields",
"metadata.owner_references",
"metadata.self_link",
"metadata.creation_timestamp",
"metadata.deletion_timestamp",
"metadata.deletion_grace_period_seconds",
"status",
"spec"
]

required_attributes = [
"metadata"
]

computed_attributes = [
"metadata.uid",
"metadata.resource_version",
"metadata.generation",
"metadata.name",
]

immutable_attributes = [
"metadata.name"
]
}
62 changes: 35 additions & 27 deletions internal/framework/provider/corev1/generate_secret.hcl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

resource "kubernetes_secret_v1_gen" {
package = "corev1"

api_version = "v1"
kind = "Secret"

description = "configmaps store information for pods"
description = "secrets store secret information for pods"

output_filename_prefix = "secret"

Expand All @@ -14,8 +13,28 @@ resource "kubernetes_secret_v1_gen" {
create_path = "/api/v1/namespaces/{namespace}/secrets"
read_path = "/api/v1/namespaces/{namespace}/secrets/{name}"
}

generate {
schema = true
model = true
autocrud = true

autocrud_options {
hooks {
before {
create = true
update = true
}
after {
create = true
update = true
read = true
}
}
}
}

ignored_attributes = [
ignored_attributes = [
"api_version",
"kind",
"metadata.finalizers",
Expand All @@ -25,36 +44,25 @@ ignored_attributes = [
"metadata.creation_timestamp",
"metadata.deletion_timestamp",
"metadata.deletion_grace_period_seconds",
"name",
"namespace",
"pretty"
]

computed_attributes = [
required_attributes = [
"metadata"
]

computed_attributes = [
"metadata.uid",
"metadata.resource_version",
"metadata.generation",
"metadata.name",
"type"
]

// default_values = {
// "id" = "testing"
// }
]

generate {
schema = true
model = true
autocrud = true
autocrud_options {
hooks{
before{
create = true
}
after{
sensitive_attributes = [
"data"
]

}
}
}
}
immutable_attributes = [
"metadata.name",
"metadata.namespace"
]
}
Loading

0 comments on commit 69a30e7

Please sign in to comment.