From 35c71235e1d8c686b6b53cae3fc1985e9ab2f415 Mon Sep 17 00:00:00 2001 From: mvsphani-rafay <93969387+mvsphani-rafay@users.noreply.github.com> Date: Tue, 20 Aug 2024 09:19:00 +0530 Subject: [PATCH] RC-35102 system provider tf changes (#655) * system provider support --- docs/resources/resource_template.md | 13 ++- go.mod | 5 +- go.sum | 12 +-- rafay/resource_resourcetemplate.go | 151 +++++++++++++++++++++++++++- 4 files changed, 167 insertions(+), 14 deletions(-) diff --git a/docs/resources/resource_template.md b/docs/resources/resource_template.md index 34ce2500..7ca862b5 100644 --- a/docs/resources/resource_template.md +++ b/docs/resources/resource_template.md @@ -148,7 +148,7 @@ resource "rafay_resource_template" "aws-elasticache-rt-example" { ***Required*** -- `provider` (String) Specify the resource template provider, Accepted values are `terraform`, `hcpterraform`, `opentofu`, `custom` +- `provider` (String) Specify the resource template provider, Accepted values are `terraform`, `hcpterraform`, `opentofu`, `custom`, `system` - `repository_options` (Block List, Max: 1) Repository options to be provided (see [below for nested schema](#nestedblock--spec--repository_options)) - `version` (String) Version of the resource template @@ -1684,6 +1684,7 @@ resource "rafay_resource_template" "aws-elasticache-rt-example" { - `hcp_terraform` (Block List, Max: 1) Specify the HCP terraform specific options if any (see [below for nested schema](#nestedblock--spec--provider_options--hcpterraform)) - `open_tofu` (Block List, Max: 1) Specify the opentofu specific options if any (see [below for nested schema](#nestedblock--spec--provider_options--opentofu)) - `custom` (Block List, Max: 1) Specify the custom options if any (see [below for nested schema](#nestedblock--spec--provider_options--custom)) +- `system` (Block List, Max: 1) Specify the system options if any (see [below for nested schema](#nestedblock--spec--provider_options--system)) ### Nested Schema for `spec.provider_options.driver` @@ -2489,4 +2490,12 @@ Optional: - `driver` (Block List, Max: 1) Specify the driver responsible for execution (see [below for nested schema](#nestedblock--spec--provider_options--driver)) - `on_failure` (String) Specify the on failure action - `options` (Block List, Max: 1) Specify the hook options (see [below for nested schema](#nestedblock--spec--hooks--on_completion--options)) -- `timeout_seconds` (Number) Specify the timeout in seconds \ No newline at end of file +- `timeout_seconds` (Number) Specify the timeout in seconds + + + +### Nested Schema for `spec.provider_options.system` + +***Required*** + +- `kind` (String) Specify the type of rafay resource, Available options are `credential`, `cluster`. diff --git a/go.mod b/go.mod index 4959f72b..9e59d74d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.4 require ( github.com/RafaySystems/edge-common v1.24.1-0.20240813083948-ba69bed0bc1b - github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240813084031-834d0909294a + github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240819105128-51987ba404a9 github.com/RafaySystems/rctl v1.29.1-0.20240813175545-9dc352b7affb github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/go-yaml/yaml v2.1.0+incompatible @@ -68,7 +68,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect - github.com/RafaySystems/eaas-playground v0.0.0-20240725104726-6472e5c291bb // indirect + github.com/RafaySystems/eaas-playground v0.0.0-20240819062521-b1b317f32232 // indirect github.com/RoaringBitmap/roaring v1.9.4 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/armon/go-radix v1.0.0 // indirect @@ -218,6 +218,7 @@ require ( replace ( cloud.google.com/go => cloud.google.com/go v0.100.2 + // github.com/RafaySystems/eaas-playground => ../eaas-playground // github.com/RafaySystems/rafay-common => ../rafay-common // github.com/RafaySystems/rctl => github.com/RafaySystems/rctl v1.5.14 // github.com/RafaySystems/terraform-provider-rafay/rafay => ../rafay diff --git a/go.sum b/go.sum index 34eb4b39..a830e8e0 100644 --- a/go.sum +++ b/go.sum @@ -23,12 +23,12 @@ github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= -github.com/RafaySystems/eaas-playground v0.0.0-20240725104726-6472e5c291bb h1:YfBdiQgm+b8EOY3oy3WlPex8JG+RVt/2O0mjLVTEBIY= -github.com/RafaySystems/eaas-playground v0.0.0-20240725104726-6472e5c291bb/go.mod h1:nwtRApMyQyH1dBys1rBa2HwDrA44OlNienOEuxZ7vZk= +github.com/RafaySystems/eaas-playground v0.0.0-20240819062521-b1b317f32232 h1:OyvJD5nwBHjM7UUS9nX9DNLKeq2BZfWb/Tcsz3K3DHY= +github.com/RafaySystems/eaas-playground v0.0.0-20240819062521-b1b317f32232/go.mod h1:YN2q7XActj/AHM4F+6Czsip5++l7asf/hxK8YZjrmhU= github.com/RafaySystems/edge-common v1.24.1-0.20240813083948-ba69bed0bc1b h1:byYrgKmgq+JNPm9u/6/DJQSu8AW/TdgPhgrnzpmHBBs= github.com/RafaySystems/edge-common v1.24.1-0.20240813083948-ba69bed0bc1b/go.mod h1:Lp/hUW/sjTyEgvhmRsnpDQ0c5ccRHHd3DQC/nbJ/jb4= -github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240813084031-834d0909294a h1:Z10XQ6dZlb9+Rp3Zdyh6TJB8200rQ6Y63h2xwG8A/mI= -github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240813084031-834d0909294a/go.mod h1:8StKG6w/b27sf72oU0piJe0qiRBVRc/VdFvpM3mZVtY= +github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240819105128-51987ba404a9 h1:r5kpECouDiIcNvKqBPOe5Ly1v4oF6vcnhtDU6anlYZA= +github.com/RafaySystems/rafay-common v1.29.1-rc2.0.20240819105128-51987ba404a9/go.mod h1:s28/gkN7ii/bWnsfbnS5uxxYH1aaA/rm4JZu61rLdkM= github.com/RafaySystems/rctl v1.29.1-0.20240813175545-9dc352b7affb h1:bozmqi6NqEYngix6hO1TnO6bMTn4dRRyJPaiOubIwO8= github.com/RafaySystems/rctl v1.29.1-0.20240813175545-9dc352b7affb/go.mod h1:lsuKgPhI39u2kWzSOUoFI5jyWnldUif7HTrs4sVzXSc= github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv2QzDdQ= @@ -59,8 +59,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= -github.com/bufbuild/protocompile v0.14.0 h1:z3DW4IvXE5G/uTOnSQn+qwQQxvhckkTWLS/0No/o7KU= -github.com/bufbuild/protocompile v0.14.0/go.mod h1:N6J1NYzkspJo3ZwyL4Xjvli86XOj1xq4qAasUFxGups= +github.com/bufbuild/protocompile v0.10.0 h1:+jW/wnLMLxaCEG8AX9lD0bQ5v9h1RUiMKOBOT5ll9dM= +github.com/bufbuild/protocompile v0.10.0/go.mod h1:G9qQIQo0xZ6Uyj6CMNz0saGmx2so+KONo8/KrELABiY= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= diff --git a/rafay/resource_resourcetemplate.go b/rafay/resource_resourcetemplate.go index 7ac86462..62d045b0 100644 --- a/rafay/resource_resourcetemplate.go +++ b/rafay/resource_resourcetemplate.go @@ -544,7 +544,6 @@ func expandHcpTerraformProviderOptions(p []interface{}) *eaaspb.HCPTerraformProv if len(p) == 0 || p[0] == nil { return hcpTFOpts } - in := p[0].(map[string]interface{}) if vfiles, ok := in["var_files"].([]interface{}); ok && len(vfiles) > 0 { @@ -584,12 +583,17 @@ func expandHcpTerraformProviderOptions(p []interface{}) *eaaspb.HCPTerraformProv } func expandSystemProviderOptions(p []interface{}) *eaaspb.SystemProviderOptions { + spo := &eaaspb.SystemProviderOptions{} if len(p) == 0 || p[0] == nil { - return nil + return spo + } + in := p[0].(map[string]interface{}) + + if h, ok := in["kind"].(string); ok { + spo.Kind = h } - spo := &eaaspb.SystemProviderOptions{} - return spo + return spo } func expandTerragruntProviderOptions(p []interface{}) *eaaspb.TerragruntProviderOptions { @@ -632,6 +636,10 @@ func expandProviderHooks(p []interface{}) *eaaspb.ResourceTemplateProviderHooks rtph.HcpTerraform = expandHcpTerraformProviderHooks(h) } + if h, oj := in["system"].([]interface{}); oj && len(h) > 0 { + rtph.System = expandSystemProviderHooks(h) + } + return rtph } @@ -711,6 +719,24 @@ func expandHcpTerraformProviderHooks(p []interface{}) *eaaspb.HCPTerraformProvid return tph } +func expandSystemProviderHooks(p []interface{}) *eaaspb.SystemProviderHooks { + sph := &eaaspb.SystemProviderHooks{} + if len(p) == 0 || p[0] == nil { + return sph + } + + in := p[0].(map[string]interface{}) + + if h, ok := in["deploy"].([]interface{}); ok && len(h) > 0 { + sph.Deploy = expandSystemDeployHooks(h) + } + + if h, ok := in["destroy"].([]interface{}); ok && len(h) > 0 { + sph.Destroy = expandSystemDestroyHooks(h) + } + + return sph +} func expandTerraformDeployHooks(p []interface{}) *eaaspb.TerraformDeployHooks { tdh := &eaaspb.TerraformDeployHooks{} @@ -862,6 +888,36 @@ func expandHcpTerraformDestroyHooks(p []interface{}) *eaaspb.HCPTerraformDestroy return tdh } +func expandSystemDeployHooks(p []interface{}) *eaaspb.SystemDeployHooks { + sdh := &eaaspb.SystemDeployHooks{} + if len(p) == 0 || p[0] == nil { + return sdh + } + + in := p[0].(map[string]interface{}) + + if h, ok := in["apply"].([]interface{}); ok && len(h) > 0 { + sdh.Apply = expandLifecycleEventHooks(h) + } + + return sdh +} + +func expandSystemDestroyHooks(p []interface{}) *eaaspb.SystemDestroyHooks { + sdh := &eaaspb.SystemDestroyHooks{} + if len(p) == 0 || p[0] == nil { + return sdh + } + + in := p[0].(map[string]interface{}) + + if h, ok := in["destroy"].([]interface{}); ok && len(h) > 0 { + sdh.Destroy = expandLifecycleEventHooks(h) + } + + return sdh +} + func expandPulumiDeployHooks(p []interface{}) *eaaspb.PulumiDeployHooks { pdh := &eaaspb.PulumiDeployHooks{} if len(p) == 0 || p[0] == nil { @@ -1139,6 +1195,7 @@ func flattenSystemProviderOptions(in *eaaspb.SystemProviderOptions) []interface{ } obj := make(map[string]interface{}) + obj["kind"] = in.Kind return []interface{}{obj} } @@ -1314,6 +1371,14 @@ func flattenProviderHooks(input *eaaspb.ResourceTemplateProviderHooks, p []inter obj["hcp_terraform"] = flattenHcpTerraformProviderHooks(input.HcpTerraform, v) } + if input.System != nil { + v, ok := obj["system"].([]interface{}) + if !ok { + v = []interface{}{} + } + + obj["system"] = flattenSystemProviderHooks(input.System, v) + } return []interface{}{obj} } @@ -1413,6 +1478,38 @@ func flattenHcpTerraformProviderHooks(input *eaaspb.HCPTerraformProviderHooks, p return []interface{}{obj} } +func flattenSystemProviderHooks(input *eaaspb.SystemProviderHooks, p []interface{}) []interface{} { + log.Println("flatten system provider hooks start") + if input == nil { + return nil + } + + obj := make(map[string]interface{}) + if len(p) != 0 && p[0] != nil { + obj = p[0].(map[string]interface{}) + } + + if input.Deploy != nil { + v, ok := obj["deploy"].([]interface{}) + if !ok { + v = []interface{}{} + } + + obj["deploy"] = flattenSystemDeployHooks(input.Deploy, v) + } + + if input.Destroy != nil { + v, ok := obj["destroy"].([]interface{}) + if !ok { + v = []interface{}{} + } + + obj["destroy"] = flattenSystemDestroyHooks(input.Destroy, v) + } + + return []interface{}{obj} +} + func flattenPulumiProviderHooks(input *eaaspb.PulumiProviderHooks, p []interface{}) []interface{} { log.Println("flatten pulumi provider hooks start") if input == nil { @@ -1718,6 +1815,52 @@ func flattenHcpTerraformDestroyHooks(input *eaaspb.HCPTerraformDestroyHooks, p [ return []interface{}{obj} } +func flattenSystemDeployHooks(input *eaaspb.SystemDeployHooks, p []interface{}) []interface{} { + log.Println("flatten system deploy hooks start") + if input == nil { + return nil + } + + obj := make(map[string]interface{}) + if len(p) != 0 && p[0] != nil { + obj = p[0].(map[string]interface{}) + } + + if input.Apply != nil { + v, ok := obj["apply"].([]interface{}) + if !ok { + v = []interface{}{} + } + + obj["apply"] = flattenLifecycleEventHooks(input.Apply, v) + } + + return []interface{}{obj} +} + +func flattenSystemDestroyHooks(input *eaaspb.SystemDestroyHooks, p []interface{}) []interface{} { + log.Println("flatten system destroy hooks start") + if input == nil { + return nil + } + + obj := make(map[string]interface{}) + if len(p) != 0 && p[0] != nil { + obj = p[0].(map[string]interface{}) + } + + if input.Destroy != nil { + v, ok := obj["destroy"].([]interface{}) + if !ok { + v = []interface{}{} + } + + obj["destroy"] = flattenLifecycleEventHooks(input.Destroy, v) + } + + return []interface{}{obj} +} + func flattenPulumiDeployHooks(input *eaaspb.PulumiDeployHooks, p []interface{}) []interface{} { log.Println("flatten pulumi deploy hooks start") if input == nil {