Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Add helpers for basic acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed May 5, 2020
1 parent 323b28b commit 5144d3e
Show file tree
Hide file tree
Showing 898 changed files with 203,609 additions and 6 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ require (
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/terraform-json v0.4.0
github.com/hashicorp/terraform-plugin-sdk v1.4.1
github.com/hashicorp/terraform-plugin-test v1.3.0
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTj
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest/autorest v0.9.0 h1:MRvx8gncNaXJqOoLmhNjUAKh33JJF8LyxPhomEtOsjs=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
github.com/Azure/go-autorest/autorest/adal v0.5.0 h1:q2gDruN08/guU9vAjuPWff0+QIrpH6ediguzdAzXAUU=
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM=
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/mocks v0.2.0 h1:Ww5g4zThfD/6cLb4z6xxgeyDa7QDkizMkJKe0ysZXp0=
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k=
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
Expand Down Expand Up @@ -79,6 +85,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down Expand Up @@ -197,6 +204,7 @@ github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down Expand Up @@ -228,6 +236,7 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs=
github.com/hashicorp/go-getter v1.4.0 h1:ENHNi8494porjD0ZhIrjlAHnveSFhY7hvOJrV/fsKkw=
github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
Expand All @@ -254,8 +263,12 @@ github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
github.com/hashicorp/terraform-json v0.4.0 h1:KNh29iNxozP5adfUFBJ4/fWd0Cu3taGgjHB38JYqOF4=
github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU=
github.com/hashicorp/terraform-plugin-sdk v1.4.1 h1:REgN6WbySD6aIYdF6Uob3ic4eQkfh4NXSWU/casmgb4=
github.com/hashicorp/terraform-plugin-sdk v1.4.1/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg=
github.com/hashicorp/terraform-plugin-test v1.3.0 h1:hU5LoxrOn9qvOo+LTKN6mSav2J+dAMprbdxJPEQvp4U=
github.com/hashicorp/terraform-plugin-test v1.3.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
Expand Down Expand Up @@ -424,6 +437,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8=
github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
Expand Down Expand Up @@ -627,6 +642,7 @@ k8s.io/apiextensions-apiserver v0.18.0 h1:HN4/P8vpGZFvB5SOMuPPH2Wt9Y/ryX+KRvIyAk
k8s.io/apiextensions-apiserver v0.18.0/go.mod h1:18Cwn1Xws4xnWQNC00FLq1E350b9lUF+aOdIWDOZxgo=
k8s.io/apimachinery v0.18.0 h1:fuPfYpk3cs1Okp/515pAf0dNhL66+8zk8RLbSX+EgAE=
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.2 h1:44CmtbmkzVDAhCpRVSiP2R5PPrC2RtlIv/MoB8xpdRA=
k8s.io/apiserver v0.18.0/go.mod h1:3S2O6FeBBd6XTo0njUrLxiqk8GNy6wWOftjhJcXYnjw=
k8s.io/client-go v0.18.0 h1:yqKw4cTUQraZK3fcVCMeSa+lqKwcjZ5wtcOIPnxQno4=
k8s.io/client-go v0.18.0/go.mod h1:uQSYDYs4WhVZ9i6AIoEZuwUggLVEF64HOD37boKAtF8=
Expand Down
53 changes: 53 additions & 0 deletions provider/kubernetes_manifest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package provider

import (
"fmt"
"testing"
)

func TestAccKubernetesManifestBasicConfigMap(t *testing.T) {
wd := helper.RequireNewWorkingDir(t)

namespace := randName()
createKubernetesNamespace(t, namespace)

name := randName()
tfconfig := testAccManifestBasicConfigMap(namespace, name)
wd.RequireSetConfig(t, tfconfig)

wd.RequireInit(t)
wd.RequireApply(t)

assertKubernetesNamespacedResourceExists(t, "v1", "configmaps", namespace, name)

state := wd.RequireState(t)
object := getObjectFromResourceState(t, state, "kubernetes_manifest.test")
assertObjectFieldEqual(t, object, "metadata.namespace", namespace)
assertObjectFieldEqual(t, object, "metadata.name", name)
assertObjectFieldEqual(t, object, "data.foo", "bar")

wd.Destroy()
assertKubernetesNamespacedResourceNotExists(t, "v1", "configmaps", namespace, name)
deleteKubernetesNamespace(t, namespace)

wd.Close()
}

func testAccManifestBasicConfigMap(namespace, name string) string {
return fmt.Sprintf(`
resource "kubernetes_manifest" "test" {
provider = kubernetes-alpha
manifest = {
"apiVersion" = "v1"
"kind" = "ConfigMap"
"metadata" = {
"name" = %q
"namespace" = %q
}
"data" = {
"foo" = "bar"
}
}
}`, name, namespace)
}
204 changes: 204 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package provider

import (
"context"
"fmt"
"math/rand"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"

tfjson "github.com/hashicorp/terraform-json"
tftest "github.com/hashicorp/terraform-plugin-test"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

var providerName = "kubernetes-alpha"
var helper *tftest.Helper
var kubernetesClient dynamic.Interface

func TestMain(m *testing.M) {
if tftest.RunningAsPlugin() {
Serve()
os.Exit(0)
return
}

sourceDir, err := os.Getwd()
if err != nil {
panic(err)
}

client, err := configureKubernetesClient()
if err != nil {
panic(err)
}
kubernetesClient = client

helper = tftest.AutoInitProviderHelper(providerName, sourceDir)
defer helper.Close()

exitcode := m.Run()
os.Exit(exitcode)
}

func configureKubernetesClient() (dynamic.Interface, error) {
rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides).ClientConfig()
if err != nil {
return nil, err
}

if config == nil {
config = &rest.Config{}
}

client, err := dynamic.NewForConfig(config)
if err != nil {
return nil, err
}

return client, nil
}

func createGroupVersionResource(gv, resource string) schema.GroupVersionResource {
var group, groupVersion string
gvparts := strings.Split(gv, "/")
if len(gvparts) < 2 {
group = ""
groupVersion = gv
} else {
group = gvparts[0]
groupVersion = gvparts[1]
}

return schema.GroupVersionResource{
Group: group,
Version: groupVersion,
Resource: resource,
}
}

func assertKubernetesNamespacedResourceExists(t *testing.T, gv, resource, namespace, name string) {
gvr := createGroupVersionResource(gv, resource)
_, err := kubernetesClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if errors.IsNotFound(err) {
t.Errorf("Resource %s/%s does not exist", namespace, name)
return
}

if err != nil {
t.Errorf("Error when trying to get resource %s/%s: %v", namespace, name, err)
}
}

func assertKubernetesNamespacedResourceNotExists(t *testing.T, gv, resource, namespace, name string) {
gvr := createGroupVersionResource(gv, resource)
_, err := kubernetesClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if errors.IsNotFound(err) {
return
}

if err != nil {
t.Errorf("Error when trying to get resource %s/%s: %v", namespace, name, err)
return
}

t.Errorf("Resource %s/%s still exists", namespace, name)
}

func createKubernetesNamespace(t *testing.T, name string) {
namespace := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": map[string]interface{}{
"name": name,
},
},
}
gvr := createGroupVersionResource("v1", "namespaces")
_, err := kubernetesClient.Resource(gvr).Create(context.TODO(), namespace, metav1.CreateOptions{})
if err != nil {
t.Errorf("Failed to create namespace %q: %v", name, err)
}
}

func deleteKubernetesNamespace(t *testing.T, name string) {
gvr := createGroupVersionResource("v1", "namespaces")
err := kubernetesClient.Resource(gvr).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
t.Errorf("Failed to delete namespace %q: %v", name, err)
}
}

var letters = []rune("abcdefghijklmnopqrstuvwxyz")

func randName() string {
b := make([]rune, 10)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return fmt.Sprintf("tf-acc-test-%s", string(b))
}

// getObjectFromResourceState will pull out the value of the `object` attribute of the resource and return it
// as a map[string]interface{}.
func getObjectFromResourceState(t *testing.T, state *tfjson.State, resourceAddr string) map[string]interface{} {
for _, r := range state.Values.RootModule.Resources {
if r.Address == resourceAddr {
value, ok := r.AttributeValues["object"].(map[string]interface{})
if !ok {
t.Errorf("Could not find get `object` attribute from %q", resourceAddr)
}
return value
}
}

t.Errorf("Could not find resource %q in state", resourceAddr)
return nil
}

// findFieldValue will return the value of a field in the object using dot notation
func findFieldValue(object map[string]interface{}, fieldPath string) (interface{}, error) {
pathKeys := strings.Split(fieldPath, ".")
fieldKey := pathKeys[len(pathKeys)-1]
parentFieldPathKeys := pathKeys[:len(pathKeys)-1]

m := object
for _, key := range parentFieldPathKeys {
// FIXME need to handle arrays like: spec.containers.0.name
v, ok := m[key].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Field %q does not exist", fieldPath)
}
m = v
}

value, ok := m[fieldKey].(interface{})
if !ok {
return nil, fmt.Errorf("Field %q does not exist", fieldPath)
}

return value, nil
}

func assertObjectFieldEqual(t *testing.T, object map[string]interface{}, fieldPath string, expectedValue interface{}) {
actualValue, err := findFieldValue(object, fieldPath)
if err != nil {
t.Errorf(err.Error())
}

assert.Equal(t, expectedValue, actualValue)
}
12 changes: 6 additions & 6 deletions provider/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (s *RawProviderServer) ApplyResourceChange(ctx context.Context, req *tfplug
if err != nil {
return resp, err
}
Dlog.Printf("[ApplyResourceChange][Request][PlannedState]\n%s\n", spew.Sdump(applyPlannedState))
// Dlog.Printf("[ApplyResourceChange][Request][PlannedState]\n%s\n", spew.Sdump(applyPlannedState))
// Dlog.Printf("[ApplyResourceChange][Request][PriorState]\n%s\n", spew.Sdump(applyPriorState))
// Dlog.Printf("[ApplyResourceChange][Request][PlannedPrivate]\n%s\n", spew.Sdump(req.PlannedPrivate))

Expand Down Expand Up @@ -352,17 +352,17 @@ func (s *RawProviderServer) ApplyResourceChange(ctx context.Context, req *tfplug
// Call the Kubernetes API to create the new resource
result, err := rs.Patch(ctx, rname, types.ApplyPatchType, jd, v1.PatchOptions{FieldManager: "Terraform"})
if err != nil {
Dlog.Printf("[ApplyResourceChange][Create] Error: %s\n%s\n", spew.Sdump(err), spew.Sdump(result))
// Dlog.Printf("[ApplyResourceChange][Create] Error: %s\n%s\n", spew.Sdump(err), spew.Sdump(result))
n := types.NamespacedName{Namespace: rnamespace, Name: rname}.String()
return resp, fmt.Errorf("CREATE resource %s failed: %s", n, err)
}
Dlog.Printf("[ApplyResourceChange][Create] API response:\n%s\n", spew.Sdump(result))
// Dlog.Printf("[ApplyResourceChange][Create] API response:\n%s\n", spew.Sdump(result))

newResObject, err := UnstructuredToCty(FilterEphemeralFields(result.Object))
if err != nil {
return resp, err
}
Dlog.Printf("[ApplyResourceChange][Create] transformed response:\n%s\n", spew.Sdump(newResObject))
// Dlog.Printf("[ApplyResourceChange][Create] transformed response:\n%s\n", spew.Sdump(newResObject))

newResState, err := cty.Transform(applyPlannedState,
ResourceDeepUpdateObjectAttr(cty.GetAttrPath("object"), &newResObject),
Expand Down Expand Up @@ -456,12 +456,12 @@ func (s *RawProviderServer) ApplyResourceChange(ctx context.Context, req *tfplug
})
return resp, fmt.Errorf("PATCH resource %s failed: %s", rn, err)
}
Dlog.Printf("[ApplyResourceChange][Update] API response:\n%s\n", spew.Sdump(result))
// Dlog.Printf("[ApplyResourceChange][Update] API response:\n%s\n", spew.Sdump(result))
newResObject, err := UnstructuredToCty(FilterEphemeralFields(result.Object))
if err != nil {
return resp, err
}
Dlog.Printf("[ApplyResourceChange][Update] transformed response:\n%s", spew.Sdump(newResObject))
// Dlog.Printf("[ApplyResourceChange][Update] transformed response:\n%s", spew.Sdump(newResObject))
newResState, err := cty.Transform(applyPlannedState,
ResourceDeepUpdateObjectAttr(cty.GetAttrPath("object"), &newResObject),
)
Expand Down
Loading

0 comments on commit 5144d3e

Please sign in to comment.