From dc2314a9062bdbaeb86bf015743ae0897648665a Mon Sep 17 00:00:00 2001 From: balu-ce Date: Wed, 3 Jan 2024 23:04:56 +0530 Subject: [PATCH 01/16] Added tfplan in status --- apis/v1beta1/workspace_types.go | 1 + internal/controller/workspace/workspace.go | 25 ++++++----- internal/terraform/terraform.go | 52 +++++++++++++++++++--- package/crds/tf.upbound.io_workspaces.yaml | 2 + 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index b87461de..08677d85 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -135,6 +135,7 @@ type WorkspaceParameters struct { // WorkspaceObservation are the observable fields of a Workspace. type WorkspaceObservation struct { + TFPlan string `json:"tfPlan,omitempty"` Checksum string `json:"checksum,omitempty"` Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"` } diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 5c07d610..aaa18a61 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -100,7 +100,7 @@ type tfclient interface { Workspace(ctx context.Context, name string) error Outputs(ctx context.Context) ([]terraform.Output, error) Resources(ctx context.Context) ([]string, error) - Diff(ctx context.Context, o ...terraform.Option) (bool, error) + Diff(ctx context.Context, o ...terraform.Option) (bool, string, error) Apply(ctx context.Context, o ...terraform.Option) error Destroy(ctx context.Context, o ...terraform.Option) error DeleteCurrentWorkspace(ctx context.Context) error @@ -301,23 +301,19 @@ type external struct { logger logging.Logger } -func (c *external) checkDiff(ctx context.Context, cr *v1beta1.Workspace) (bool, error) { - o, err := c.options(ctx, cr.Spec.ForProvider) - if err != nil { - return false, errors.Wrap(err, errOptions) - } - +func (c *external) checkDiff(ctx context.Context, cr *v1beta1.Workspace, o []terraform.Option) (bool, string, error) { o = append(o, terraform.WithArgs(cr.Spec.ForProvider.PlanArgs)) - differs, err := c.tf.Diff(ctx, o...) + differs, planOutput, err := c.tf.Diff(ctx, o...) + if err != nil { if !meta.WasDeleted(cr) { - return false, errors.Wrap(err, errDiff) + return false, planOutput, errors.Wrap(err, errDiff) } // terraform plan can fail on deleted resources, so let the reconciliation loop // call Delete() if there are still resources in the tfstate file differs = false } - return differs, nil + return differs, planOutput, nil } func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) { @@ -326,7 +322,12 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex return managed.ExternalObservation{}, errors.New(errNotWorkspace) } - differs, err := c.checkDiff(ctx, cr) + o, err := c.options(ctx, cr.Spec.ForProvider) + if err != nil { + return managed.ExternalObservation{}, errors.Wrap(err, errOptions) + } + + differs, planOutput, err := c.checkDiff(ctx, cr, o) if err != nil { return managed.ExternalObservation{}, err } @@ -354,6 +355,8 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } cr.Status.AtProvider.Checksum = checksum + cr.Status.AtProvider.TFPlan = planOutput + if !differs { // TODO(negz): Allow Workspaces to optionally derive their readiness from an // output - similar to the logic XRs use to derive readiness from a field of diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 750ac069..6ab9c092 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -49,6 +49,11 @@ const ( const varFilePrefix = "crossplane-provider-terraform-" +// Info message to show plan change +const ( + noDiffInPlan = "No Change in terraform plan" +) + // Terraform often returns a summary of the error it encountered on a single // line, prefixed with 'Error: '. var tfError = regexp.MustCompile(`Error: (.+)\n`) @@ -105,6 +110,35 @@ func formatTerraformErrorOutput(errorOutput string) (string, string, error) { return summary, base64FullErr, nil } +// Format Terraform error output as gzipped and base64 encoded string +func formatTerraformPlanOutput(output string) (string, error) { + // Gzip compress the output and base64 encode it. + var buffer bytes.Buffer + gz := gzip.NewWriter(&buffer) + + if _, err := gz.Write([]byte(output)); err != nil { + return "", err + } + + if err := gz.Flush(); err != nil { + return "", err + } + + if err := gz.Close(); err != nil { + return "", err + } + + if err := gz.Flush(); err != nil { + return "", err + } + + formatString := "Terraform Plan. To see the full plan run: echo \"%s\" | base64 -d | gunzip" + + base64FullPlan := base64.StdEncoding.EncodeToString(buffer.Bytes()) + + return fmt.Sprintf(formatString, base64FullPlan), nil +} + // NOTE(negz): The gosec linter returns a G204 warning anytime a command is // executed with any kind of variable input. This isn't inherently a problem, // and is apparently mostly intended to catch the attention of code auditors per @@ -480,7 +514,7 @@ func WithVarFile(data []byte, f FileFormat) Option { // Diff invokes 'terraform plan' to determine whether there is a diff between // the desired and the actual state of the configuration. It returns true if // there is a diff. -func (h Harness) Diff(ctx context.Context, o ...Option) (bool, error) { +func (h Harness) Diff(ctx context.Context, o ...Option) (bool, string, error) { ao := &options{} for _, fn := range o { fn(ao) @@ -488,7 +522,7 @@ func (h Harness) Diff(ctx context.Context, o ...Option) (bool, error) { for _, vf := range ao.varFiles { if err := os.WriteFile(filepath.Join(h.Dir, vf.filename), vf.data, 0600); err != nil { - return false, errors.Wrap(err, errWriteVarFile) + return false, noDiffInPlan, errors.Wrap(err, errWriteVarFile) } } @@ -503,11 +537,19 @@ func (h Harness) Diff(ctx context.Context, o ...Option) (bool, error) { // 0 - Succeeded, diff is empty (no changes) // 1 - Errored // 2 - Succeeded, there is a diff - _, err := cmd.Output() + planVal, err := cmd.Output() + if cmd.ProcessState.ExitCode() == 2 { - return true, nil + + base64FullPlan, err := formatTerraformPlanOutput(string(planVal)) + if err != nil { + return false, noDiffInPlan, Classify(err) + } + + return true, base64FullPlan, nil } - return false, Classify(err) + + return false, noDiffInPlan, Classify(err) } // Apply a Terraform configuration. diff --git a/package/crds/tf.upbound.io_workspaces.yaml b/package/crds/tf.upbound.io_workspaces.yaml index acfd650d..a5ca2978 100644 --- a/package/crds/tf.upbound.io_workspaces.yaml +++ b/package/crds/tf.upbound.io_workspaces.yaml @@ -360,6 +360,8 @@ spec: additionalProperties: x-kubernetes-preserve-unknown-fields: true type: object + tfPlan: + type: string type: object conditions: description: Conditions of the resource. From 6959ecb85fc374a401a1df74d6c691b1532e6d3d Mon Sep 17 00:00:00 2001 From: balu-ce Date: Fri, 5 Jan 2024 13:20:31 +0530 Subject: [PATCH 02/16] Added test cass --- .github/ISSUE_TEMPLATE/bug_report.md | 0 .github/ISSUE_TEMPLATE/feature_request.md | 0 .../ISSUE_TEMPLATE/new_resource_request.md | 0 .github/PULL_REQUEST_TEMPLATE.md | 0 .github/renovate.json5 | 0 .github/stale.yml | 0 .github/workflows/backport.yml | 0 .github/workflows/ci.yml | 0 .github/workflows/commands.yml | 0 .github/workflows/e2e.yaml | 0 .github/workflows/scan.yml | 0 .github/workflows/tag.yaml | 0 .github/workflows/updoc.yml | 0 .gitignore | 0 .gitmodules | 0 .golangci.yml | 0 CODEOWNERS | 0 CONTRIBUTING.md | 0 LICENSE | 0 Makefile | 0 NOTICE | 0 OWNERS.md | 0 README.md | 0 apis/generate.go | 0 apis/terraform.go | 0 apis/v1beta1/doc.go | 0 apis/v1beta1/register.go | 0 apis/v1beta1/storeconfig_types.go | 0 apis/v1beta1/types.go | 0 apis/v1beta1/workspace_types.go | 0 apis/v1beta1/zz_generated.deepcopy.go | 0 apis/v1beta1/zz_generated.managed.go | 0 apis/v1beta1/zz_generated.managedlist.go | 0 apis/v1beta1/zz_generated.pc.go | 0 apis/v1beta1/zz_generated.pcu.go | 0 apis/v1beta1/zz_generated.pculist.go | 0 catalog-info.yaml | 0 cluster/images/provider-terraform/.gitconfig | 0 cluster/images/provider-terraform/Dockerfile | 0 cluster/images/provider-terraform/Makefile | 0 cmd/provider/main.go | 0 docs/Configuration.md | 0 docs/MigrationGuide.md | 0 docs/Quickstart.md | 0 examples/.terraformrc | 0 examples/aws-eks-irsa-setup.yaml | 0 examples/creationblocker/README.md | 0 examples/creationblocker/composition.yaml | 0 examples/creationblocker/definition.yaml | 0 examples/creationblocker/xsubnetblocking.yaml | 0 .../creationblocker/xsubnetnotblocking.yaml | 0 examples/importer/README.md | 0 examples/importer/composition.yaml | 0 examples/importer/definition.yaml | 0 examples/importer/xsubnet.yaml | 0 examples/install.yaml | 0 examples/observe-only-composition/README.md | 0 .../observe-only-composition/composition.yaml | 0 .../observe-only-composition/definition.yaml | 0 .../observe-only-composition/xsubnet.yaml | 0 examples/providerconfig-aws.yaml | 0 examples/providerconfig-azure.yaml | 0 examples/providerconfig-terraformrc.yaml | 0 examples/providerconfig.yaml | 0 .../00-mr-tf-workspace/workspace-inline.yaml | 0 .../00-mr-tf-workspace/workspace-remote.yaml | 0 .../01-composition-tf-only/composition.yaml | 0 .../01-composition-tf-only/subnet-tf.yaml | 0 .../composition.yaml | 0 .../subnet-mixed.yaml | 0 .../composition.yaml | 0 .../subnet-native.yaml | 0 examples/transition/README.md | 0 examples/transition/definition.yaml | 0 examples/workspace-inline-aws.yaml | 0 examples/workspace-inline.yaml | 0 examples/workspace-random-generator.yaml | 0 examples/workspace-remote.yaml | 0 go.mod | 0 go.sum | 0 hack/boilerplate.go.txt | 0 internal/controller/config/config.go | 0 internal/controller/doc.go | 0 internal/controller/features/features.go | 0 internal/controller/terraform.go | 0 internal/controller/workspace/workspace.go | 14 +++--- .../controller/workspace/workspace_test.go | 43 +++++++++++++------ internal/terraform/terraform.go | 4 +- internal/terraform/terraform_harness_test.go | 0 internal/terraform/terraform_test.go | 0 .../terraform/testdata/invalidmodule/main.tf | 0 .../terraform/testdata/nullmodule/main.tf | 0 .../testdata/nullmodule/terraform.tfstate | 0 .../terraform/testdata/outputmodule/main.tf | 0 .../testdata/outputmodule/terraform.tfstate | 0 .../terraform/testdata/validmodule/main.tf | 0 internal/workdir/workdir.go | 0 internal/workdir/workdir_test.go | 0 package/crossplane.yaml | 0 99 files changed, 40 insertions(+), 21 deletions(-) mode change 100644 => 100755 .github/ISSUE_TEMPLATE/bug_report.md mode change 100644 => 100755 .github/ISSUE_TEMPLATE/feature_request.md mode change 100644 => 100755 .github/ISSUE_TEMPLATE/new_resource_request.md mode change 100644 => 100755 .github/PULL_REQUEST_TEMPLATE.md mode change 100644 => 100755 .github/renovate.json5 mode change 100644 => 100755 .github/stale.yml mode change 100644 => 100755 .github/workflows/backport.yml mode change 100644 => 100755 .github/workflows/ci.yml mode change 100644 => 100755 .github/workflows/commands.yml mode change 100644 => 100755 .github/workflows/e2e.yaml mode change 100644 => 100755 .github/workflows/scan.yml mode change 100644 => 100755 .github/workflows/tag.yaml mode change 100644 => 100755 .github/workflows/updoc.yml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .gitmodules mode change 100644 => 100755 .golangci.yml mode change 100644 => 100755 CODEOWNERS mode change 100644 => 100755 CONTRIBUTING.md mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Makefile mode change 100644 => 100755 NOTICE mode change 100644 => 100755 OWNERS.md mode change 100644 => 100755 README.md mode change 100644 => 100755 apis/generate.go mode change 100644 => 100755 apis/terraform.go mode change 100644 => 100755 apis/v1beta1/doc.go mode change 100644 => 100755 apis/v1beta1/register.go mode change 100644 => 100755 apis/v1beta1/storeconfig_types.go mode change 100644 => 100755 apis/v1beta1/types.go mode change 100644 => 100755 apis/v1beta1/workspace_types.go mode change 100644 => 100755 apis/v1beta1/zz_generated.deepcopy.go mode change 100644 => 100755 apis/v1beta1/zz_generated.managed.go mode change 100644 => 100755 apis/v1beta1/zz_generated.managedlist.go mode change 100644 => 100755 apis/v1beta1/zz_generated.pc.go mode change 100644 => 100755 apis/v1beta1/zz_generated.pcu.go mode change 100644 => 100755 apis/v1beta1/zz_generated.pculist.go mode change 100644 => 100755 catalog-info.yaml mode change 100644 => 100755 cluster/images/provider-terraform/.gitconfig mode change 100644 => 100755 cluster/images/provider-terraform/Dockerfile mode change 100644 => 100755 cluster/images/provider-terraform/Makefile mode change 100644 => 100755 cmd/provider/main.go mode change 100644 => 100755 docs/Configuration.md mode change 100644 => 100755 docs/MigrationGuide.md mode change 100644 => 100755 docs/Quickstart.md mode change 100644 => 100755 examples/.terraformrc mode change 100644 => 100755 examples/aws-eks-irsa-setup.yaml mode change 100644 => 100755 examples/creationblocker/README.md mode change 100644 => 100755 examples/creationblocker/composition.yaml mode change 100644 => 100755 examples/creationblocker/definition.yaml mode change 100644 => 100755 examples/creationblocker/xsubnetblocking.yaml mode change 100644 => 100755 examples/creationblocker/xsubnetnotblocking.yaml mode change 100644 => 100755 examples/importer/README.md mode change 100644 => 100755 examples/importer/composition.yaml mode change 100644 => 100755 examples/importer/definition.yaml mode change 100644 => 100755 examples/importer/xsubnet.yaml mode change 100644 => 100755 examples/install.yaml mode change 100644 => 100755 examples/observe-only-composition/README.md mode change 100644 => 100755 examples/observe-only-composition/composition.yaml mode change 100644 => 100755 examples/observe-only-composition/definition.yaml mode change 100644 => 100755 examples/observe-only-composition/xsubnet.yaml mode change 100644 => 100755 examples/providerconfig-aws.yaml mode change 100644 => 100755 examples/providerconfig-azure.yaml mode change 100644 => 100755 examples/providerconfig-terraformrc.yaml mode change 100644 => 100755 examples/providerconfig.yaml mode change 100644 => 100755 examples/transition/00-mr-tf-workspace/workspace-inline.yaml mode change 100644 => 100755 examples/transition/00-mr-tf-workspace/workspace-remote.yaml mode change 100644 => 100755 examples/transition/01-composition-tf-only/composition.yaml mode change 100644 => 100755 examples/transition/01-composition-tf-only/subnet-tf.yaml mode change 100644 => 100755 examples/transition/02-composition-tf-and-native/composition.yaml mode change 100644 => 100755 examples/transition/02-composition-tf-and-native/subnet-mixed.yaml mode change 100644 => 100755 examples/transition/03-composition-native-only/composition.yaml mode change 100644 => 100755 examples/transition/03-composition-native-only/subnet-native.yaml mode change 100644 => 100755 examples/transition/README.md mode change 100644 => 100755 examples/transition/definition.yaml mode change 100644 => 100755 examples/workspace-inline-aws.yaml mode change 100644 => 100755 examples/workspace-inline.yaml mode change 100644 => 100755 examples/workspace-random-generator.yaml mode change 100644 => 100755 examples/workspace-remote.yaml mode change 100644 => 100755 go.mod mode change 100644 => 100755 go.sum mode change 100644 => 100755 hack/boilerplate.go.txt mode change 100644 => 100755 internal/controller/config/config.go mode change 100644 => 100755 internal/controller/doc.go mode change 100644 => 100755 internal/controller/features/features.go mode change 100644 => 100755 internal/controller/terraform.go mode change 100644 => 100755 internal/controller/workspace/workspace.go mode change 100644 => 100755 internal/controller/workspace/workspace_test.go mode change 100644 => 100755 internal/terraform/terraform.go mode change 100644 => 100755 internal/terraform/terraform_harness_test.go mode change 100644 => 100755 internal/terraform/terraform_test.go mode change 100644 => 100755 internal/terraform/testdata/invalidmodule/main.tf mode change 100644 => 100755 internal/terraform/testdata/nullmodule/main.tf mode change 100644 => 100755 internal/terraform/testdata/nullmodule/terraform.tfstate mode change 100644 => 100755 internal/terraform/testdata/outputmodule/main.tf mode change 100644 => 100755 internal/terraform/testdata/outputmodule/terraform.tfstate mode change 100644 => 100755 internal/terraform/testdata/validmodule/main.tf mode change 100644 => 100755 internal/workdir/workdir.go mode change 100644 => 100755 internal/workdir/workdir_test.go mode change 100644 => 100755 package/crossplane.yaml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/new_resource_request.md b/.github/ISSUE_TEMPLATE/new_resource_request.md old mode 100644 new mode 100755 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md old mode 100644 new mode 100755 diff --git a/.github/renovate.json5 b/.github/renovate.json5 old mode 100644 new mode 100755 diff --git a/.github/stale.yml b/.github/stale.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml old mode 100644 new mode 100755 diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml old mode 100644 new mode 100755 diff --git a/.github/workflows/updoc.yml b/.github/workflows/updoc.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/.golangci.yml b/.golangci.yml old mode 100644 new mode 100755 diff --git a/CODEOWNERS b/CODEOWNERS old mode 100644 new mode 100755 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/NOTICE b/NOTICE old mode 100644 new mode 100755 diff --git a/OWNERS.md b/OWNERS.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/apis/generate.go b/apis/generate.go old mode 100644 new mode 100755 diff --git a/apis/terraform.go b/apis/terraform.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/doc.go b/apis/v1beta1/doc.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/register.go b/apis/v1beta1/register.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/storeconfig_types.go b/apis/v1beta1/storeconfig_types.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/types.go b/apis/v1beta1/types.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.managed.go b/apis/v1beta1/zz_generated.managed.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.managedlist.go b/apis/v1beta1/zz_generated.managedlist.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.pc.go b/apis/v1beta1/zz_generated.pc.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.pcu.go b/apis/v1beta1/zz_generated.pcu.go old mode 100644 new mode 100755 diff --git a/apis/v1beta1/zz_generated.pculist.go b/apis/v1beta1/zz_generated.pculist.go old mode 100644 new mode 100755 diff --git a/catalog-info.yaml b/catalog-info.yaml old mode 100644 new mode 100755 diff --git a/cluster/images/provider-terraform/.gitconfig b/cluster/images/provider-terraform/.gitconfig old mode 100644 new mode 100755 diff --git a/cluster/images/provider-terraform/Dockerfile b/cluster/images/provider-terraform/Dockerfile old mode 100644 new mode 100755 diff --git a/cluster/images/provider-terraform/Makefile b/cluster/images/provider-terraform/Makefile old mode 100644 new mode 100755 diff --git a/cmd/provider/main.go b/cmd/provider/main.go old mode 100644 new mode 100755 diff --git a/docs/Configuration.md b/docs/Configuration.md old mode 100644 new mode 100755 diff --git a/docs/MigrationGuide.md b/docs/MigrationGuide.md old mode 100644 new mode 100755 diff --git a/docs/Quickstart.md b/docs/Quickstart.md old mode 100644 new mode 100755 diff --git a/examples/.terraformrc b/examples/.terraformrc old mode 100644 new mode 100755 diff --git a/examples/aws-eks-irsa-setup.yaml b/examples/aws-eks-irsa-setup.yaml old mode 100644 new mode 100755 diff --git a/examples/creationblocker/README.md b/examples/creationblocker/README.md old mode 100644 new mode 100755 diff --git a/examples/creationblocker/composition.yaml b/examples/creationblocker/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/creationblocker/definition.yaml b/examples/creationblocker/definition.yaml old mode 100644 new mode 100755 diff --git a/examples/creationblocker/xsubnetblocking.yaml b/examples/creationblocker/xsubnetblocking.yaml old mode 100644 new mode 100755 diff --git a/examples/creationblocker/xsubnetnotblocking.yaml b/examples/creationblocker/xsubnetnotblocking.yaml old mode 100644 new mode 100755 diff --git a/examples/importer/README.md b/examples/importer/README.md old mode 100644 new mode 100755 diff --git a/examples/importer/composition.yaml b/examples/importer/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/importer/definition.yaml b/examples/importer/definition.yaml old mode 100644 new mode 100755 diff --git a/examples/importer/xsubnet.yaml b/examples/importer/xsubnet.yaml old mode 100644 new mode 100755 diff --git a/examples/install.yaml b/examples/install.yaml old mode 100644 new mode 100755 diff --git a/examples/observe-only-composition/README.md b/examples/observe-only-composition/README.md old mode 100644 new mode 100755 diff --git a/examples/observe-only-composition/composition.yaml b/examples/observe-only-composition/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/observe-only-composition/definition.yaml b/examples/observe-only-composition/definition.yaml old mode 100644 new mode 100755 diff --git a/examples/observe-only-composition/xsubnet.yaml b/examples/observe-only-composition/xsubnet.yaml old mode 100644 new mode 100755 diff --git a/examples/providerconfig-aws.yaml b/examples/providerconfig-aws.yaml old mode 100644 new mode 100755 diff --git a/examples/providerconfig-azure.yaml b/examples/providerconfig-azure.yaml old mode 100644 new mode 100755 diff --git a/examples/providerconfig-terraformrc.yaml b/examples/providerconfig-terraformrc.yaml old mode 100644 new mode 100755 diff --git a/examples/providerconfig.yaml b/examples/providerconfig.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/00-mr-tf-workspace/workspace-inline.yaml b/examples/transition/00-mr-tf-workspace/workspace-inline.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/00-mr-tf-workspace/workspace-remote.yaml b/examples/transition/00-mr-tf-workspace/workspace-remote.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/01-composition-tf-only/composition.yaml b/examples/transition/01-composition-tf-only/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/01-composition-tf-only/subnet-tf.yaml b/examples/transition/01-composition-tf-only/subnet-tf.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/02-composition-tf-and-native/composition.yaml b/examples/transition/02-composition-tf-and-native/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/02-composition-tf-and-native/subnet-mixed.yaml b/examples/transition/02-composition-tf-and-native/subnet-mixed.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/03-composition-native-only/composition.yaml b/examples/transition/03-composition-native-only/composition.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/03-composition-native-only/subnet-native.yaml b/examples/transition/03-composition-native-only/subnet-native.yaml old mode 100644 new mode 100755 diff --git a/examples/transition/README.md b/examples/transition/README.md old mode 100644 new mode 100755 diff --git a/examples/transition/definition.yaml b/examples/transition/definition.yaml old mode 100644 new mode 100755 diff --git a/examples/workspace-inline-aws.yaml b/examples/workspace-inline-aws.yaml old mode 100644 new mode 100755 diff --git a/examples/workspace-inline.yaml b/examples/workspace-inline.yaml old mode 100644 new mode 100755 diff --git a/examples/workspace-random-generator.yaml b/examples/workspace-random-generator.yaml old mode 100644 new mode 100755 diff --git a/examples/workspace-remote.yaml b/examples/workspace-remote.yaml old mode 100644 new mode 100755 diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt old mode 100644 new mode 100755 diff --git a/internal/controller/config/config.go b/internal/controller/config/config.go old mode 100644 new mode 100755 diff --git a/internal/controller/doc.go b/internal/controller/doc.go old mode 100644 new mode 100755 diff --git a/internal/controller/features/features.go b/internal/controller/features/features.go old mode 100644 new mode 100755 diff --git a/internal/controller/terraform.go b/internal/controller/terraform.go old mode 100644 new mode 100755 diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go old mode 100644 new mode 100755 index aaa18a61..09f86633 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -301,7 +301,12 @@ type external struct { logger logging.Logger } -func (c *external) checkDiff(ctx context.Context, cr *v1beta1.Workspace, o []terraform.Option) (bool, string, error) { +func (c *external) checkDiff(ctx context.Context, cr *v1beta1.Workspace) (bool, string, error) { + o, err := c.options(ctx, cr.Spec.ForProvider) + if err != nil { + return false, "", errors.Wrap(err, errOptions) + } + o = append(o, terraform.WithArgs(cr.Spec.ForProvider.PlanArgs)) differs, planOutput, err := c.tf.Diff(ctx, o...) @@ -322,12 +327,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex return managed.ExternalObservation{}, errors.New(errNotWorkspace) } - o, err := c.options(ctx, cr.Spec.ForProvider) - if err != nil { - return managed.ExternalObservation{}, errors.Wrap(err, errOptions) - } - - differs, planOutput, err := c.checkDiff(ctx, cr, o) + differs, planOutput, err := c.checkDiff(ctx, cr) if err != nil { return managed.ExternalObservation{}, err } diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go old mode 100644 new mode 100755 index 3bdf3681..c05d5d46 --- a/internal/controller/workspace/workspace_test.go +++ b/internal/controller/workspace/workspace_test.go @@ -43,7 +43,8 @@ import ( ) const ( - tfChecksum = "checksum" + tfChecksum = "checksum" + noDiffInPlan = "No Change in terraform plan" ) type ErrFs struct { @@ -72,7 +73,7 @@ type MockTf struct { MockWorkspace func(ctx context.Context, name string) error MockOutputs func(ctx context.Context) ([]terraform.Output, error) MockResources func(ctx context.Context) ([]string, error) - MockDiff func(ctx context.Context, o ...terraform.Option) (bool, error) + MockDiff func(ctx context.Context, o ...terraform.Option) (bool, string, error) MockApply func(ctx context.Context, o ...terraform.Option) error MockDestroy func(ctx context.Context, o ...terraform.Option) error MockDeleteCurrentWorkspace func(ctx context.Context) error @@ -99,7 +100,7 @@ func (tf *MockTf) Resources(ctx context.Context) ([]string, error) { return tf.MockResources(ctx) } -func (tf *MockTf) Diff(ctx context.Context, o ...terraform.Option) (bool, error) { +func (tf *MockTf) Diff(ctx context.Context, o ...terraform.Option) (bool, string, error) { return tf.MockDiff(ctx, o...) } @@ -816,7 +817,9 @@ func TestObserve(t *testing.T) { reason: "We should return any error encountered while diffing the Terraform configuration", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, errBoom }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, noDiffInPlan, errBoom + }, }, }, args: args{ @@ -830,7 +833,9 @@ func TestObserve(t *testing.T) { reason: "We should return ResourceUpToDate true when resource is deleted and there are existing resources but terraform plan fails", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, errBoom }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, "", errBoom + }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, nil }, MockResources: func(ctx context.Context) ([]string, error) { @@ -861,7 +866,9 @@ func TestObserve(t *testing.T) { reason: "We should return ResourceUpToDate true when resource is deleted and there are no existing resources and terraform plan fails", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, errBoom }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, "", errBoom + }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, nil }, MockResources: func(ctx context.Context) ([]string, error) { return nil, nil }, @@ -891,7 +898,9 @@ func TestObserve(t *testing.T) { reason: "We should return ResourceUpToDate true when resource is deleted and there are no existing resources and terraform plan fails", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, errBoom }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, noDiffInPlan, errBoom + }, MockResources: func(ctx context.Context) ([]string, error) { return nil, nil }, MockDeleteCurrentWorkspace: func(ctx context.Context) error { return errBoom }, }, @@ -911,7 +920,9 @@ func TestObserve(t *testing.T) { reason: "We should return any error encountered while listing extant Terraform resources", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, noDiffInPlan, nil + }, MockResources: func(ctx context.Context) ([]string, error) { return nil, errBoom }, }, }, @@ -926,7 +937,9 @@ func TestObserve(t *testing.T) { reason: "We should return any error encountered while listing Terraform outputs", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, noDiffInPlan, nil + }, MockResources: func(ctx context.Context) ([]string, error) { return nil, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, errBoom }, }, @@ -942,7 +955,9 @@ func TestObserve(t *testing.T) { reason: "A workspace with zero resources should be considered to be non-existent", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, "", nil + }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { return []string{}, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, nil }, @@ -967,7 +982,9 @@ func TestObserve(t *testing.T) { reason: "A workspace with resources should return its outputs as connection details", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, "", nil + }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { return []string{"cool_resource.very"}, nil @@ -1010,7 +1027,9 @@ func TestObserve(t *testing.T) { reason: "A workspace with only outputs and no resources should set ResourceExists to true", fields: fields{ tf: &MockTf{ - MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil }, + MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { + return false, "", nil + }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { return nil, nil diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go old mode 100644 new mode 100755 index 6ab9c092..f3b387ae --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -522,7 +522,7 @@ func (h Harness) Diff(ctx context.Context, o ...Option) (bool, string, error) { for _, vf := range ao.varFiles { if err := os.WriteFile(filepath.Join(h.Dir, vf.filename), vf.data, 0600); err != nil { - return false, noDiffInPlan, errors.Wrap(err, errWriteVarFile) + return false, "", errors.Wrap(err, errWriteVarFile) } } @@ -543,7 +543,7 @@ func (h Harness) Diff(ctx context.Context, o ...Option) (bool, string, error) { base64FullPlan, err := formatTerraformPlanOutput(string(planVal)) if err != nil { - return false, noDiffInPlan, Classify(err) + return false, "", err } return true, base64FullPlan, nil diff --git a/internal/terraform/terraform_harness_test.go b/internal/terraform/terraform_harness_test.go old mode 100644 new mode 100755 diff --git a/internal/terraform/terraform_test.go b/internal/terraform/terraform_test.go old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/invalidmodule/main.tf b/internal/terraform/testdata/invalidmodule/main.tf old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/nullmodule/main.tf b/internal/terraform/testdata/nullmodule/main.tf old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/nullmodule/terraform.tfstate b/internal/terraform/testdata/nullmodule/terraform.tfstate old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/outputmodule/main.tf b/internal/terraform/testdata/outputmodule/main.tf old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/outputmodule/terraform.tfstate b/internal/terraform/testdata/outputmodule/terraform.tfstate old mode 100644 new mode 100755 diff --git a/internal/terraform/testdata/validmodule/main.tf b/internal/terraform/testdata/validmodule/main.tf old mode 100644 new mode 100755 diff --git a/internal/workdir/workdir.go b/internal/workdir/workdir.go old mode 100644 new mode 100755 diff --git a/internal/workdir/workdir_test.go b/internal/workdir/workdir_test.go old mode 100644 new mode 100755 diff --git a/package/crossplane.yaml b/package/crossplane.yaml old mode 100644 new mode 100755 From c9271b1b12aabee89753b16c96ef6d59e1830bcb Mon Sep 17 00:00:00 2001 From: balu-ce Date: Fri, 5 Jan 2024 14:18:01 +0530 Subject: [PATCH 03/16] reverted files --- .github/ISSUE_TEMPLATE/bug_report.md | 0 .github/ISSUE_TEMPLATE/feature_request.md | 0 .github/ISSUE_TEMPLATE/new_resource_request.md | 0 .github/PULL_REQUEST_TEMPLATE.md | 0 .github/renovate.json5 | 0 .github/stale.yml | 0 .github/workflows/backport.yml | 0 .github/workflows/ci.yml | 0 .github/workflows/commands.yml | 0 .github/workflows/e2e.yaml | 0 .github/workflows/scan.yml | 0 .github/workflows/tag.yaml | 0 .github/workflows/updoc.yml | 0 .gitignore | 0 .gitmodules | 0 .golangci.yml | 0 CODEOWNERS | 0 CONTRIBUTING.md | 0 LICENSE | 0 Makefile | 0 NOTICE | 0 OWNERS.md | 0 README.md | 0 apis/generate.go | 0 apis/terraform.go | 0 apis/v1beta1/doc.go | 0 apis/v1beta1/register.go | 0 apis/v1beta1/storeconfig_types.go | 0 apis/v1beta1/types.go | 0 apis/v1beta1/workspace_types.go | 0 apis/v1beta1/zz_generated.deepcopy.go | 0 apis/v1beta1/zz_generated.managed.go | 0 apis/v1beta1/zz_generated.managedlist.go | 0 apis/v1beta1/zz_generated.pc.go | 0 apis/v1beta1/zz_generated.pcu.go | 0 apis/v1beta1/zz_generated.pculist.go | 0 catalog-info.yaml | 0 cluster/images/provider-terraform/.gitconfig | 0 cluster/images/provider-terraform/Dockerfile | 0 cluster/images/provider-terraform/Makefile | 0 cluster/test/setup.sh | 0 cmd/provider/main.go | 0 docs/Configuration.md | 0 docs/MigrationGuide.md | 0 docs/Quickstart.md | 0 docs/index.json | 0 examples/.terraformrc | 0 examples/aws-eks-irsa-setup.yaml | 0 examples/creationblocker/README.md | 0 examples/creationblocker/composition.yaml | 0 examples/creationblocker/definition.yaml | 0 examples/creationblocker/xsubnetblocking.yaml | 0 examples/creationblocker/xsubnetnotblocking.yaml | 0 examples/importer/README.md | 0 examples/importer/composition.yaml | 0 examples/importer/definition.yaml | 0 examples/importer/xsubnet.yaml | 0 examples/install.yaml | 0 examples/observe-only-composition/README.md | 0 examples/observe-only-composition/composition.yaml | 0 examples/observe-only-composition/definition.yaml | 0 examples/observe-only-composition/xsubnet.yaml | 0 examples/providerconfig-aws.yaml | 0 examples/providerconfig-azure.yaml | 0 examples/providerconfig-terraformrc.yaml | 0 examples/providerconfig.yaml | 0 examples/transition/00-mr-tf-workspace/workspace-inline.yaml | 0 examples/transition/00-mr-tf-workspace/workspace-remote.yaml | 0 examples/transition/01-composition-tf-only/composition.yaml | 0 examples/transition/01-composition-tf-only/subnet-tf.yaml | 0 examples/transition/02-composition-tf-and-native/composition.yaml | 0 .../transition/02-composition-tf-and-native/subnet-mixed.yaml | 0 examples/transition/03-composition-native-only/composition.yaml | 0 examples/transition/03-composition-native-only/subnet-native.yaml | 0 examples/transition/README.md | 0 examples/transition/definition.yaml | 0 examples/workspace-inline-aws.yaml | 0 examples/workspace-inline.yaml | 0 examples/workspace-random-generator.yaml | 0 examples/workspace-remote.yaml | 0 go.mod | 0 go.sum | 0 hack/boilerplate.go.txt | 0 internal/controller/config/config.go | 0 internal/controller/doc.go | 0 internal/controller/features/features.go | 0 internal/controller/terraform.go | 0 internal/controller/workspace/workspace.go | 0 internal/controller/workspace/workspace_test.go | 0 internal/terraform/terraform.go | 0 internal/terraform/terraform_harness_test.go | 0 internal/terraform/terraform_test.go | 0 internal/terraform/testdata/invalidmodule/main.tf | 0 internal/terraform/testdata/nullmodule/main.tf | 0 internal/terraform/testdata/nullmodule/terraform.tfstate | 0 internal/terraform/testdata/outputmodule/main.tf | 0 internal/terraform/testdata/outputmodule/terraform.tfstate | 0 internal/terraform/testdata/validmodule/main.tf | 0 internal/workdir/workdir.go | 0 internal/workdir/workdir_test.go | 0 package/crossplane.yaml | 0 scripts/check-examples.py | 0 102 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 .github/ISSUE_TEMPLATE/bug_report.md mode change 100755 => 100644 .github/ISSUE_TEMPLATE/feature_request.md mode change 100755 => 100644 .github/ISSUE_TEMPLATE/new_resource_request.md mode change 100755 => 100644 .github/PULL_REQUEST_TEMPLATE.md mode change 100755 => 100644 .github/renovate.json5 mode change 100755 => 100644 .github/stale.yml mode change 100755 => 100644 .github/workflows/backport.yml mode change 100755 => 100644 .github/workflows/ci.yml mode change 100755 => 100644 .github/workflows/commands.yml mode change 100755 => 100644 .github/workflows/e2e.yaml mode change 100755 => 100644 .github/workflows/scan.yml mode change 100755 => 100644 .github/workflows/tag.yaml mode change 100755 => 100644 .github/workflows/updoc.yml mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .gitmodules mode change 100755 => 100644 .golangci.yml mode change 100755 => 100644 CODEOWNERS mode change 100755 => 100644 CONTRIBUTING.md mode change 100755 => 100644 LICENSE mode change 100755 => 100644 Makefile mode change 100755 => 100644 NOTICE mode change 100755 => 100644 OWNERS.md mode change 100755 => 100644 README.md mode change 100755 => 100644 apis/generate.go mode change 100755 => 100644 apis/terraform.go mode change 100755 => 100644 apis/v1beta1/doc.go mode change 100755 => 100644 apis/v1beta1/register.go mode change 100755 => 100644 apis/v1beta1/storeconfig_types.go mode change 100755 => 100644 apis/v1beta1/types.go mode change 100755 => 100644 apis/v1beta1/workspace_types.go mode change 100755 => 100644 apis/v1beta1/zz_generated.deepcopy.go mode change 100755 => 100644 apis/v1beta1/zz_generated.managed.go mode change 100755 => 100644 apis/v1beta1/zz_generated.managedlist.go mode change 100755 => 100644 apis/v1beta1/zz_generated.pc.go mode change 100755 => 100644 apis/v1beta1/zz_generated.pcu.go mode change 100755 => 100644 apis/v1beta1/zz_generated.pculist.go mode change 100755 => 100644 catalog-info.yaml mode change 100755 => 100644 cluster/images/provider-terraform/.gitconfig mode change 100755 => 100644 cluster/images/provider-terraform/Dockerfile mode change 100755 => 100644 cluster/images/provider-terraform/Makefile mode change 100755 => 100644 cluster/test/setup.sh mode change 100755 => 100644 cmd/provider/main.go mode change 100755 => 100644 docs/Configuration.md mode change 100755 => 100644 docs/MigrationGuide.md mode change 100755 => 100644 docs/Quickstart.md mode change 100755 => 100644 docs/index.json mode change 100755 => 100644 examples/.terraformrc mode change 100755 => 100644 examples/aws-eks-irsa-setup.yaml mode change 100755 => 100644 examples/creationblocker/README.md mode change 100755 => 100644 examples/creationblocker/composition.yaml mode change 100755 => 100644 examples/creationblocker/definition.yaml mode change 100755 => 100644 examples/creationblocker/xsubnetblocking.yaml mode change 100755 => 100644 examples/creationblocker/xsubnetnotblocking.yaml mode change 100755 => 100644 examples/importer/README.md mode change 100755 => 100644 examples/importer/composition.yaml mode change 100755 => 100644 examples/importer/definition.yaml mode change 100755 => 100644 examples/importer/xsubnet.yaml mode change 100755 => 100644 examples/install.yaml mode change 100755 => 100644 examples/observe-only-composition/README.md mode change 100755 => 100644 examples/observe-only-composition/composition.yaml mode change 100755 => 100644 examples/observe-only-composition/definition.yaml mode change 100755 => 100644 examples/observe-only-composition/xsubnet.yaml mode change 100755 => 100644 examples/providerconfig-aws.yaml mode change 100755 => 100644 examples/providerconfig-azure.yaml mode change 100755 => 100644 examples/providerconfig-terraformrc.yaml mode change 100755 => 100644 examples/providerconfig.yaml mode change 100755 => 100644 examples/transition/00-mr-tf-workspace/workspace-inline.yaml mode change 100755 => 100644 examples/transition/00-mr-tf-workspace/workspace-remote.yaml mode change 100755 => 100644 examples/transition/01-composition-tf-only/composition.yaml mode change 100755 => 100644 examples/transition/01-composition-tf-only/subnet-tf.yaml mode change 100755 => 100644 examples/transition/02-composition-tf-and-native/composition.yaml mode change 100755 => 100644 examples/transition/02-composition-tf-and-native/subnet-mixed.yaml mode change 100755 => 100644 examples/transition/03-composition-native-only/composition.yaml mode change 100755 => 100644 examples/transition/03-composition-native-only/subnet-native.yaml mode change 100755 => 100644 examples/transition/README.md mode change 100755 => 100644 examples/transition/definition.yaml mode change 100755 => 100644 examples/workspace-inline-aws.yaml mode change 100755 => 100644 examples/workspace-inline.yaml mode change 100755 => 100644 examples/workspace-random-generator.yaml mode change 100755 => 100644 examples/workspace-remote.yaml mode change 100755 => 100644 go.mod mode change 100755 => 100644 go.sum mode change 100755 => 100644 hack/boilerplate.go.txt mode change 100755 => 100644 internal/controller/config/config.go mode change 100755 => 100644 internal/controller/doc.go mode change 100755 => 100644 internal/controller/features/features.go mode change 100755 => 100644 internal/controller/terraform.go mode change 100755 => 100644 internal/controller/workspace/workspace.go mode change 100755 => 100644 internal/controller/workspace/workspace_test.go mode change 100755 => 100644 internal/terraform/terraform.go mode change 100755 => 100644 internal/terraform/terraform_harness_test.go mode change 100755 => 100644 internal/terraform/terraform_test.go mode change 100755 => 100644 internal/terraform/testdata/invalidmodule/main.tf mode change 100755 => 100644 internal/terraform/testdata/nullmodule/main.tf mode change 100755 => 100644 internal/terraform/testdata/nullmodule/terraform.tfstate mode change 100755 => 100644 internal/terraform/testdata/outputmodule/main.tf mode change 100755 => 100644 internal/terraform/testdata/outputmodule/terraform.tfstate mode change 100755 => 100644 internal/terraform/testdata/validmodule/main.tf mode change 100755 => 100644 internal/workdir/workdir.go mode change 100755 => 100644 internal/workdir/workdir_test.go mode change 100755 => 100644 package/crossplane.yaml mode change 100755 => 100644 scripts/check-examples.py diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100755 new mode 100644 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md old mode 100755 new mode 100644 diff --git a/.github/ISSUE_TEMPLATE/new_resource_request.md b/.github/ISSUE_TEMPLATE/new_resource_request.md old mode 100755 new mode 100644 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md old mode 100755 new mode 100644 diff --git a/.github/renovate.json5 b/.github/renovate.json5 old mode 100755 new mode 100644 diff --git a/.github/stale.yml b/.github/stale.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml old mode 100755 new mode 100644 diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml old mode 100755 new mode 100644 diff --git a/.github/workflows/updoc.yml b/.github/workflows/updoc.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.gitmodules b/.gitmodules old mode 100755 new mode 100644 diff --git a/.golangci.yml b/.golangci.yml old mode 100755 new mode 100644 diff --git a/CODEOWNERS b/CODEOWNERS old mode 100755 new mode 100644 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100755 new mode 100644 diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/NOTICE b/NOTICE old mode 100755 new mode 100644 diff --git a/OWNERS.md b/OWNERS.md old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/apis/generate.go b/apis/generate.go old mode 100755 new mode 100644 diff --git a/apis/terraform.go b/apis/terraform.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/doc.go b/apis/v1beta1/doc.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/register.go b/apis/v1beta1/register.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/storeconfig_types.go b/apis/v1beta1/storeconfig_types.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/types.go b/apis/v1beta1/types.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.managed.go b/apis/v1beta1/zz_generated.managed.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.managedlist.go b/apis/v1beta1/zz_generated.managedlist.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.pc.go b/apis/v1beta1/zz_generated.pc.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.pcu.go b/apis/v1beta1/zz_generated.pcu.go old mode 100755 new mode 100644 diff --git a/apis/v1beta1/zz_generated.pculist.go b/apis/v1beta1/zz_generated.pculist.go old mode 100755 new mode 100644 diff --git a/catalog-info.yaml b/catalog-info.yaml old mode 100755 new mode 100644 diff --git a/cluster/images/provider-terraform/.gitconfig b/cluster/images/provider-terraform/.gitconfig old mode 100755 new mode 100644 diff --git a/cluster/images/provider-terraform/Dockerfile b/cluster/images/provider-terraform/Dockerfile old mode 100755 new mode 100644 diff --git a/cluster/images/provider-terraform/Makefile b/cluster/images/provider-terraform/Makefile old mode 100755 new mode 100644 diff --git a/cluster/test/setup.sh b/cluster/test/setup.sh old mode 100755 new mode 100644 diff --git a/cmd/provider/main.go b/cmd/provider/main.go old mode 100755 new mode 100644 diff --git a/docs/Configuration.md b/docs/Configuration.md old mode 100755 new mode 100644 diff --git a/docs/MigrationGuide.md b/docs/MigrationGuide.md old mode 100755 new mode 100644 diff --git a/docs/Quickstart.md b/docs/Quickstart.md old mode 100755 new mode 100644 diff --git a/docs/index.json b/docs/index.json old mode 100755 new mode 100644 diff --git a/examples/.terraformrc b/examples/.terraformrc old mode 100755 new mode 100644 diff --git a/examples/aws-eks-irsa-setup.yaml b/examples/aws-eks-irsa-setup.yaml old mode 100755 new mode 100644 diff --git a/examples/creationblocker/README.md b/examples/creationblocker/README.md old mode 100755 new mode 100644 diff --git a/examples/creationblocker/composition.yaml b/examples/creationblocker/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/creationblocker/definition.yaml b/examples/creationblocker/definition.yaml old mode 100755 new mode 100644 diff --git a/examples/creationblocker/xsubnetblocking.yaml b/examples/creationblocker/xsubnetblocking.yaml old mode 100755 new mode 100644 diff --git a/examples/creationblocker/xsubnetnotblocking.yaml b/examples/creationblocker/xsubnetnotblocking.yaml old mode 100755 new mode 100644 diff --git a/examples/importer/README.md b/examples/importer/README.md old mode 100755 new mode 100644 diff --git a/examples/importer/composition.yaml b/examples/importer/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/importer/definition.yaml b/examples/importer/definition.yaml old mode 100755 new mode 100644 diff --git a/examples/importer/xsubnet.yaml b/examples/importer/xsubnet.yaml old mode 100755 new mode 100644 diff --git a/examples/install.yaml b/examples/install.yaml old mode 100755 new mode 100644 diff --git a/examples/observe-only-composition/README.md b/examples/observe-only-composition/README.md old mode 100755 new mode 100644 diff --git a/examples/observe-only-composition/composition.yaml b/examples/observe-only-composition/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/observe-only-composition/definition.yaml b/examples/observe-only-composition/definition.yaml old mode 100755 new mode 100644 diff --git a/examples/observe-only-composition/xsubnet.yaml b/examples/observe-only-composition/xsubnet.yaml old mode 100755 new mode 100644 diff --git a/examples/providerconfig-aws.yaml b/examples/providerconfig-aws.yaml old mode 100755 new mode 100644 diff --git a/examples/providerconfig-azure.yaml b/examples/providerconfig-azure.yaml old mode 100755 new mode 100644 diff --git a/examples/providerconfig-terraformrc.yaml b/examples/providerconfig-terraformrc.yaml old mode 100755 new mode 100644 diff --git a/examples/providerconfig.yaml b/examples/providerconfig.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/00-mr-tf-workspace/workspace-inline.yaml b/examples/transition/00-mr-tf-workspace/workspace-inline.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/00-mr-tf-workspace/workspace-remote.yaml b/examples/transition/00-mr-tf-workspace/workspace-remote.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/01-composition-tf-only/composition.yaml b/examples/transition/01-composition-tf-only/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/01-composition-tf-only/subnet-tf.yaml b/examples/transition/01-composition-tf-only/subnet-tf.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/02-composition-tf-and-native/composition.yaml b/examples/transition/02-composition-tf-and-native/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/02-composition-tf-and-native/subnet-mixed.yaml b/examples/transition/02-composition-tf-and-native/subnet-mixed.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/03-composition-native-only/composition.yaml b/examples/transition/03-composition-native-only/composition.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/03-composition-native-only/subnet-native.yaml b/examples/transition/03-composition-native-only/subnet-native.yaml old mode 100755 new mode 100644 diff --git a/examples/transition/README.md b/examples/transition/README.md old mode 100755 new mode 100644 diff --git a/examples/transition/definition.yaml b/examples/transition/definition.yaml old mode 100755 new mode 100644 diff --git a/examples/workspace-inline-aws.yaml b/examples/workspace-inline-aws.yaml old mode 100755 new mode 100644 diff --git a/examples/workspace-inline.yaml b/examples/workspace-inline.yaml old mode 100755 new mode 100644 diff --git a/examples/workspace-random-generator.yaml b/examples/workspace-random-generator.yaml old mode 100755 new mode 100644 diff --git a/examples/workspace-remote.yaml b/examples/workspace-remote.yaml old mode 100755 new mode 100644 diff --git a/go.mod b/go.mod old mode 100755 new mode 100644 diff --git a/go.sum b/go.sum old mode 100755 new mode 100644 diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt old mode 100755 new mode 100644 diff --git a/internal/controller/config/config.go b/internal/controller/config/config.go old mode 100755 new mode 100644 diff --git a/internal/controller/doc.go b/internal/controller/doc.go old mode 100755 new mode 100644 diff --git a/internal/controller/features/features.go b/internal/controller/features/features.go old mode 100755 new mode 100644 diff --git a/internal/controller/terraform.go b/internal/controller/terraform.go old mode 100755 new mode 100644 diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go old mode 100755 new mode 100644 diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go old mode 100755 new mode 100644 diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go old mode 100755 new mode 100644 diff --git a/internal/terraform/terraform_harness_test.go b/internal/terraform/terraform_harness_test.go old mode 100755 new mode 100644 diff --git a/internal/terraform/terraform_test.go b/internal/terraform/terraform_test.go old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/invalidmodule/main.tf b/internal/terraform/testdata/invalidmodule/main.tf old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/nullmodule/main.tf b/internal/terraform/testdata/nullmodule/main.tf old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/nullmodule/terraform.tfstate b/internal/terraform/testdata/nullmodule/terraform.tfstate old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/outputmodule/main.tf b/internal/terraform/testdata/outputmodule/main.tf old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/outputmodule/terraform.tfstate b/internal/terraform/testdata/outputmodule/terraform.tfstate old mode 100755 new mode 100644 diff --git a/internal/terraform/testdata/validmodule/main.tf b/internal/terraform/testdata/validmodule/main.tf old mode 100755 new mode 100644 diff --git a/internal/workdir/workdir.go b/internal/workdir/workdir.go old mode 100755 new mode 100644 diff --git a/internal/workdir/workdir_test.go b/internal/workdir/workdir_test.go old mode 100755 new mode 100644 diff --git a/package/crossplane.yaml b/package/crossplane.yaml old mode 100755 new mode 100644 diff --git a/scripts/check-examples.py b/scripts/check-examples.py old mode 100755 new mode 100644 From 806d519370a295f69d3220c1887cb5e30eb4ef6f Mon Sep 17 00:00:00 2001 From: balu-ce Date: Fri, 5 Jan 2024 14:25:02 +0530 Subject: [PATCH 04/16] Revertted permissions for docs --- cluster/test/setup.sh | 0 docs/index.json | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 cluster/test/setup.sh mode change 100644 => 100755 docs/index.json diff --git a/cluster/test/setup.sh b/cluster/test/setup.sh old mode 100644 new mode 100755 diff --git a/docs/index.json b/docs/index.json old mode 100644 new mode 100755 From 675d146c9a71c65fa8447be909a5f872e6879c0c Mon Sep 17 00:00:00 2001 From: balu-ce Date: Fri, 5 Jan 2024 16:54:04 +0530 Subject: [PATCH 05/16] Making the file executable permission --- scripts/check-examples.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/check-examples.py diff --git a/scripts/check-examples.py b/scripts/check-examples.py old mode 100644 new mode 100755 From d320a9e848191833c3a5aede8c6e7fb6460c0c98 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:49:00 +0530 Subject: [PATCH 06/16] Update apis/v1beta1/workspace_types.go Co-authored-by: Alper Rifat Ulucinar --- apis/v1beta1/workspace_types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index 08677d85..66f5b0d2 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -135,7 +135,8 @@ type WorkspaceParameters struct { // WorkspaceObservation are the observable fields of a Workspace. type WorkspaceObservation struct { - TFPlan string `json:"tfPlan,omitempty"` + // +optional + TFPlan *string `json:"tfPlan,omitempty"` Checksum string `json:"checksum,omitempty"` Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"` } From 6d1b103e09c082c54e809b42738590804f1828e9 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:49:13 +0530 Subject: [PATCH 07/16] Update internal/terraform/terraform.go Co-authored-by: Alper Rifat Ulucinar --- internal/terraform/terraform.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index f3b387ae..cbb43604 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -51,7 +51,7 @@ const varFilePrefix = "crossplane-provider-terraform-" // Info message to show plan change const ( - noDiffInPlan = "No Change in terraform plan" + noDiffInPlan = "No change in the terraform plan" ) // Terraform often returns a summary of the error it encountered on a single From 7ae2cdffa4c4bc057201e87ca122060ab65fcb78 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:49:48 +0530 Subject: [PATCH 08/16] Update internal/terraform/terraform.go Co-authored-by: Alper Rifat Ulucinar --- internal/terraform/terraform.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index cbb43604..5e7d6f97 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -115,6 +115,7 @@ func formatTerraformPlanOutput(output string) (string, error) { // Gzip compress the output and base64 encode it. var buffer bytes.Buffer gz := gzip.NewWriter(&buffer) + defer func() { _ = gz.Close() }() if _, err := gz.Write([]byte(output)); err != nil { return "", err From a6650bf9b4eb1e1a8778caf428a8417f53107d5e Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:49:59 +0530 Subject: [PATCH 09/16] Update internal/terraform/terraform.go Co-authored-by: Alper Rifat Ulucinar --- internal/terraform/terraform.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 5e7d6f97..781c2a92 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -129,9 +129,6 @@ func formatTerraformPlanOutput(output string) (string, error) { return "", err } - if err := gz.Flush(); err != nil { - return "", err - } formatString := "Terraform Plan. To see the full plan run: echo \"%s\" | base64 -d | gunzip" From 9470044aa70fa92f32ff80214a021e937a542b56 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:50:16 +0530 Subject: [PATCH 10/16] Update internal/terraform/terraform.go Co-authored-by: Alper Rifat Ulucinar --- internal/terraform/terraform.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 781c2a92..639c032d 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -130,7 +130,7 @@ func formatTerraformPlanOutput(output string) (string, error) { } - formatString := "Terraform Plan. To see the full plan run: echo \"%s\" | base64 -d | gunzip" + formatString := `Terraform Plan. To see the full plan run: echo "%s" | base64 -d | gunzip` base64FullPlan := base64.StdEncoding.EncodeToString(buffer.Bytes()) From 4a44ed94cc1dee20836b4a00652b29d666e1e6b8 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 22 Jan 2024 19:50:41 +0530 Subject: [PATCH 11/16] Update internal/terraform/terraform.go Co-authored-by: Alper Rifat Ulucinar --- internal/terraform/terraform.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 639c032d..f05dec07 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -125,9 +125,6 @@ func formatTerraformPlanOutput(output string) (string, error) { return "", err } - if err := gz.Close(); err != nil { - return "", err - } formatString := `Terraform Plan. To see the full plan run: echo "%s" | base64 -d | gunzip` From 0834fc7cbd34279e25821a7bab92a266c21eafba Mon Sep 17 00:00:00 2001 From: balu-ce Date: Thu, 25 Jan 2024 14:59:46 +0530 Subject: [PATCH 12/16] Fixing syntax issues --- apis/v1beta1/workspace_types.go | 2 +- apis/v1beta1/zz_generated.deepcopy.go | 5 +++++ internal/controller/workspace/workspace.go | 2 +- .../controller/workspace/workspace_test.go | 21 ++++++++++++++----- internal/terraform/terraform.go | 5 +++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index 66f5b0d2..222f4fb4 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -136,7 +136,7 @@ type WorkspaceParameters struct { // WorkspaceObservation are the observable fields of a Workspace. type WorkspaceObservation struct { // +optional - TFPlan *string `json:"tfPlan,omitempty"` + TFPlan *string `json:"tfPlan,omitempty"` Checksum string `json:"checksum,omitempty"` Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"` } diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 38d741c9..036a4f61 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -424,6 +424,11 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceObservation) DeepCopyInto(out *WorkspaceObservation) { *out = *in + if in.TFPlan != nil { + in, out := &in.TFPlan, &out.TFPlan + *out = new(string) + **out = **in + } if in.Outputs != nil { in, out := &in.Outputs, &out.Outputs *out = make(map[string]v1.JSON, len(*in)) diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 3fc068f9..1fc8c215 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -366,7 +366,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } cr.Status.AtProvider.Checksum = checksum - cr.Status.AtProvider.TFPlan = planOutput + cr.Status.AtProvider.TFPlan = &planOutput if !differs { // TODO(negz): Allow Workspaces to optionally derive their readiness from an diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go index 9f903c07..1cf3cf5a 100644 --- a/internal/controller/workspace/workspace_test.go +++ b/internal/controller/workspace/workspace_test.go @@ -47,6 +47,10 @@ const ( noDiffInPlan = "No Change in terraform plan" ) +var ( + emptyString = "" +) + type ErrFs struct { afero.Fs @@ -600,6 +604,7 @@ func TestConnect(t *testing.T) { }, Status: v1beta1.WorkspaceStatus{ AtProvider: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, }, }, @@ -635,6 +640,7 @@ func TestConnect(t *testing.T) { }, Status: v1beta1.WorkspaceStatus{ AtProvider: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, }, }, @@ -881,7 +887,7 @@ func TestObserve(t *testing.T) { fields: fields{ tf: &MockTf{ MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { - return false, "", errBoom + return false, emptyString, errBoom }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, nil }, @@ -904,6 +910,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -914,7 +921,7 @@ func TestObserve(t *testing.T) { fields: fields{ tf: &MockTf{ MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { - return false, "", errBoom + return false, emptyString, errBoom }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockOutputs: func(ctx context.Context) ([]terraform.Output, error) { return nil, nil }, @@ -936,6 +943,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1003,7 +1011,7 @@ func TestObserve(t *testing.T) { fields: fields{ tf: &MockTf{ MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { - return false, "", nil + return false, emptyString, nil }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { return []string{}, nil }, @@ -1020,6 +1028,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1030,7 +1039,7 @@ func TestObserve(t *testing.T) { fields: fields{ tf: &MockTf{ MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { - return false, "", nil + return false, emptyString, nil }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { @@ -1063,6 +1072,7 @@ func TestObserve(t *testing.T) { }, }, wo: v1beta1.WorkspaceObservation{ + TFPlan: &emptyString, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, @@ -1075,7 +1085,7 @@ func TestObserve(t *testing.T) { fields: fields{ tf: &MockTf{ MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, string, error) { - return false, "", nil + return false, emptyString, nil }, MockGenerateChecksum: func(ctx context.Context) (string, error) { return tfChecksum, nil }, MockResources: func(ctx context.Context) ([]string, error) { @@ -1109,6 +1119,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, + TFPlan: &emptyString, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, }, diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 130b4823..0fbce20b 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -119,7 +119,6 @@ func formatTerraformPlanOutput(output string) (string, error) { // Gzip compress the output and base64 encode it. var buffer bytes.Buffer gz := gzip.NewWriter(&buffer) - defer func() { _ = gz.Close() }() if _, err := gz.Write([]byte(output)); err != nil { return "", err @@ -129,7 +128,9 @@ func formatTerraformPlanOutput(output string) (string, error) { return "", err } - + if err := gz.Close(); err != nil { + return "", err + } formatString := `Terraform Plan. To see the full plan run: echo "%s" | base64 -d | gunzip` From 7a830618d8e9f16a551a13b903f6fb5755d78037 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Mon, 29 Jan 2024 18:18:40 +0530 Subject: [PATCH 13/16] Conditional var for show plan --- apis/v1beta1/workspace_types.go | 4 ++++ internal/controller/workspace/workspace.go | 5 ++++- internal/controller/workspace/workspace_test.go | 10 +++++----- package/crds/tf.upbound.io_workspaces.yaml | 5 +++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index 222f4fb4..2d1be41c 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -107,6 +107,10 @@ type WorkspaceParameters struct { // +optional Entrypoint string `json:"entrypoint"` + // Variable to show a plan on CR based on condition + // +kubebuilder:default=false + ShowPlan bool `json:"showPlan"` + // Configuration variables. // +optional Vars []Var `json:"vars,omitempty"` diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 1fc8c215..2d25d98e 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -332,6 +332,7 @@ func (c *external) checkDiff(ctx context.Context, cr *v1beta1.Workspace) (bool, return differs, planOutput, nil } +//nolint:gocyclo func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) { cr, ok := mg.(*v1beta1.Workspace) if !ok { @@ -366,7 +367,9 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } cr.Status.AtProvider.Checksum = checksum - cr.Status.AtProvider.TFPlan = &planOutput + if cr.Spec.ForProvider.ShowPlan { + cr.Status.AtProvider.TFPlan = &planOutput + } if !differs { // TODO(negz): Allow Workspaces to optionally derive their readiness from an diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go index 1cf3cf5a..5612e848 100644 --- a/internal/controller/workspace/workspace_test.go +++ b/internal/controller/workspace/workspace_test.go @@ -910,7 +910,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + TFPlan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -943,7 +943,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + TFPlan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1028,7 +1028,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + TFPlan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1072,7 +1072,7 @@ func TestObserve(t *testing.T) { }, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + TFPlan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, @@ -1119,7 +1119,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - TFPlan: &emptyString, + TFPlan: nil, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, }, diff --git a/package/crds/tf.upbound.io_workspaces.yaml b/package/crds/tf.upbound.io_workspaces.yaml index a5ca2978..36ba46a7 100644 --- a/package/crds/tf.upbound.io_workspaces.yaml +++ b/package/crds/tf.upbound.io_workspaces.yaml @@ -101,6 +101,10 @@ spec: items: type: string type: array + showPlan: + default: false + description: Variable to show a plan on CR based on condition + type: boolean source: description: Source of the root module of this workspace. enum: @@ -185,6 +189,7 @@ spec: type: array required: - module + - showPlan - source type: object managementPolicies: From e4e29d6a1692a781cbbf2b35f68dfaa54bc10647 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Wed, 31 Jan 2024 11:26:35 +0530 Subject: [PATCH 14/16] Removed plan format string --- examples/workspace-inline.yaml | 3 ++- internal/terraform/terraform.go | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/workspace-inline.yaml b/examples/workspace-inline.yaml index 9ddfa7a6..fde57557 100644 --- a/examples/workspace-inline.yaml +++ b/examples/workspace-inline.yaml @@ -13,6 +13,7 @@ spec: # For simple cases you can use an inline source to specify the content of # main.tf as opaque, inline HCL. source: Inline + showPlan: true module: | // Outputs are written to the connection secret. output "url" { @@ -29,7 +30,7 @@ spec: name = "crossplane-example-${terraform.workspace}-${random_id.example.hex}" location = "US" force_destroy = true - + public_access_prevention = "enforced" } writeConnectionSecretToRef: diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index 0fbce20b..c907079b 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -132,11 +132,9 @@ func formatTerraformPlanOutput(output string) (string, error) { return "", err } - formatString := `Terraform Plan. To see the full plan run: echo "%s" | base64 -d | gunzip` - base64FullPlan := base64.StdEncoding.EncodeToString(buffer.Bytes()) - return fmt.Sprintf(formatString, base64FullPlan), nil + return base64FullPlan, nil } // NOTE(negz): The gosec linter returns a G204 warning anytime a command is From 8ae4f304051a3bb6ef12975c0cbe5d9e4c7a1789 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Wed, 31 Jan 2024 12:39:22 +0530 Subject: [PATCH 15/16] Change in variables format --- apis/v1beta1/workspace_types.go | 7 ++++--- apis/v1beta1/zz_generated.deepcopy.go | 4 ++-- internal/controller/workspace/workspace.go | 4 ++-- internal/controller/workspace/workspace_test.go | 14 +++++++------- package/crds/tf.upbound.io_workspaces.yaml | 11 ++++++----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index 2d1be41c..d60b4f29 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -107,9 +107,10 @@ type WorkspaceParameters struct { // +optional Entrypoint string `json:"entrypoint"` - // Variable to show a plan on CR based on condition + // Include the output of terraform plan in the status. + // The plan will be gzipped and base64 encoded. // +kubebuilder:default=false - ShowPlan bool `json:"showPlan"` + IncludePlan bool `json:"includePlan"` // Configuration variables. // +optional @@ -140,7 +141,7 @@ type WorkspaceParameters struct { // WorkspaceObservation are the observable fields of a Workspace. type WorkspaceObservation struct { // +optional - TFPlan *string `json:"tfPlan,omitempty"` + Plan *string `json:"tfPlan,omitempty"` Checksum string `json:"checksum,omitempty"` Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"` } diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 036a4f61..5ff3a260 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -424,8 +424,8 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceObservation) DeepCopyInto(out *WorkspaceObservation) { *out = *in - if in.TFPlan != nil { - in, out := &in.TFPlan, &out.TFPlan + if in.Plan != nil { + in, out := &in.Plan, &out.Plan *out = new(string) **out = **in } diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 2d25d98e..021c5934 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -367,8 +367,8 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } cr.Status.AtProvider.Checksum = checksum - if cr.Spec.ForProvider.ShowPlan { - cr.Status.AtProvider.TFPlan = &planOutput + if cr.Spec.ForProvider.IncludePlan { + cr.Status.AtProvider.Plan = &planOutput } if !differs { diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go index 5612e848..b4b2218d 100644 --- a/internal/controller/workspace/workspace_test.go +++ b/internal/controller/workspace/workspace_test.go @@ -604,7 +604,7 @@ func TestConnect(t *testing.T) { }, Status: v1beta1.WorkspaceStatus{ AtProvider: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + Plan: &emptyString, Checksum: tfChecksum, }, }, @@ -640,7 +640,7 @@ func TestConnect(t *testing.T) { }, Status: v1beta1.WorkspaceStatus{ AtProvider: v1beta1.WorkspaceObservation{ - TFPlan: &emptyString, + Plan: &emptyString, Checksum: tfChecksum, }, }, @@ -910,7 +910,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: nil, + Plan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -943,7 +943,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: nil, + Plan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1028,7 +1028,7 @@ func TestObserve(t *testing.T) { ConnectionDetails: managed.ConnectionDetails{}, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: nil, + Plan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{}, }, @@ -1072,7 +1072,7 @@ func TestObserve(t *testing.T) { }, }, wo: v1beta1.WorkspaceObservation{ - TFPlan: nil, + Plan: nil, Checksum: tfChecksum, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, @@ -1119,7 +1119,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - TFPlan: nil, + Plan: nil, Outputs: map[string]extensionsV1.JSON{ "string": {Raw: []byte("null")}, }, diff --git a/package/crds/tf.upbound.io_workspaces.yaml b/package/crds/tf.upbound.io_workspaces.yaml index 36ba46a7..08d82e41 100644 --- a/package/crds/tf.upbound.io_workspaces.yaml +++ b/package/crds/tf.upbound.io_workspaces.yaml @@ -81,6 +81,11 @@ spec: default: "" description: Entrypoint for `terraform init` within the module type: string + includePlan: + default: false + description: Include the output of terraform plan in the status. + The plan will be gzipped and base64 encoded. + type: boolean initArgs: description: Arguments to be included in the terraform init CLI command @@ -101,10 +106,6 @@ spec: items: type: string type: array - showPlan: - default: false - description: Variable to show a plan on CR based on condition - type: boolean source: description: Source of the root module of this workspace. enum: @@ -188,8 +189,8 @@ spec: type: object type: array required: + - includePlan - module - - showPlan - source type: object managementPolicies: From bd894e1aa3c2c2159c321a1bc1891a8bcf35a263 Mon Sep 17 00:00:00 2001 From: balu-ce Date: Fri, 2 Feb 2024 10:48:18 +0530 Subject: [PATCH 16/16] Added includePlan as optional --- apis/v1beta1/workspace_types.go | 3 ++- apis/v1beta1/zz_generated.deepcopy.go | 5 +++++ go.mod | 2 +- go.sum | 4 ++-- internal/controller/workspace/workspace.go | 3 ++- package/crds/tf.upbound.io_workspaces.yaml | 1 - 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index d60b4f29..309e3f96 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -110,7 +110,8 @@ type WorkspaceParameters struct { // Include the output of terraform plan in the status. // The plan will be gzipped and base64 encoded. // +kubebuilder:default=false - IncludePlan bool `json:"includePlan"` + // +optional + IncludePlan *bool `json:"includePlan"` // Configuration variables. // +optional diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 5ff3a260..351bbf29 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -451,6 +451,11 @@ func (in *WorkspaceObservation) DeepCopy() *WorkspaceObservation { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkspaceParameters) DeepCopyInto(out *WorkspaceParameters) { *out = *in + if in.IncludePlan != nil { + in, out := &in.IncludePlan, &out.IncludePlan + *out = new(bool) + **out = **in + } if in.Vars != nil { in, out := &in.Vars, &out.Vars *out = make([]Var, len(*in)) diff --git a/go.mod b/go.mod index f80e8bb7..653829da 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( k8s.io/apiextensions-apiserver v0.28.4 k8s.io/apimachinery v0.28.4 k8s.io/client-go v0.28.4 + k8s.io/utils v0.0.0-20240102154912-e7106e64919e sigs.k8s.io/controller-runtime v0.16.3 sigs.k8s.io/controller-tools v0.13.0 ) @@ -107,7 +108,6 @@ require ( k8s.io/component-base v0.28.4 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect - k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/go.sum b/go.sum index 72397104..1a02c66e 100644 --- a/go.sum +++ b/go.sum @@ -1082,8 +1082,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= -k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU= -k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= +k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 021c5934..75b9459f 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -30,6 +30,7 @@ import ( corev1 "k8s.io/api/core/v1" extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -367,7 +368,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } cr.Status.AtProvider.Checksum = checksum - if cr.Spec.ForProvider.IncludePlan { + if ptr.Deref[bool](cr.Spec.ForProvider.IncludePlan, false) { cr.Status.AtProvider.Plan = &planOutput } diff --git a/package/crds/tf.upbound.io_workspaces.yaml b/package/crds/tf.upbound.io_workspaces.yaml index 08d82e41..6fdeb34e 100644 --- a/package/crds/tf.upbound.io_workspaces.yaml +++ b/package/crds/tf.upbound.io_workspaces.yaml @@ -189,7 +189,6 @@ spec: type: object type: array required: - - includePlan - module - source type: object