Skip to content

Commit

Permalink
fix(pullrequests): inherit all properties from original layer in pr l…
Browse files Browse the repository at this point in the history
…ayer (#539)
  • Loading branch information
LucasMrqes authored Mar 5, 2025
1 parent d8e1149 commit 6c78042
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
31 changes: 31 additions & 0 deletions internal/controllers/terraformpullrequest/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,37 @@ var _ = Describe("TerraformPullRequest controller", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(layers)).To(Equal(2))
})
It("should have created temp layers with the same values as the original layers, except for autoApply and Branch", func() {
layers, err := controller.GetLinkedLayers(k8sClient, pr)
Expect(err).NotTo(HaveOccurred())
layer1 := &configv1alpha1.TerraformLayer{}
err = k8sClient.Get(context.Background(), types.NamespacedName{
Name: "layer-nominal-case-1",
Namespace: "default",
}, layer1)
Expect(err).NotTo(HaveOccurred())
// Set the branch and autoApply to the same value as the original layer for comparison
// These are the two only fields that should be different
layer1.Spec.Branch = "<branch>"
layers[0].Spec.Branch = "<branch>"
layer1.Spec.RemediationStrategy.AutoApply = &[]bool{false}[0]
layers[0].Spec.RemediationStrategy.AutoApply = &[]bool{false}[0]
Expect(layers[0].Spec).To(Equal(layer1.Spec))

layer2 := &configv1alpha1.TerraformLayer{}
err = k8sClient.Get(context.Background(), types.NamespacedName{
Name: "layer-nominal-case-2",
Namespace: "default",
}, layer2)
Expect(err).NotTo(HaveOccurred())
// Set the branch and autoApply to the same value as the original layer for comparison
// These are the two only fields that should be different
layer2.Spec.Branch = "<branch>"
layers[1].Spec.Branch = "<branch>"
layer2.Spec.RemediationStrategy.AutoApply = &[]bool{false}[0]
layers[1].Spec.RemediationStrategy.AutoApply = &[]bool{false}[0]
Expect(layers[1].Spec).To(Equal(layer2.Spec))
})
})
Describe("When a TerraformPullRequest has all its layers planned", Ordered, func() {
BeforeAll(func() {
Expand Down
11 changes: 7 additions & 4 deletions internal/controllers/terraformpullrequest/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ func generateTempLayers(pr *configv1alpha1.TerraformPullRequest, layers []config
},
},
Spec: configv1alpha1.TerraformLayerSpec{
Path: layer.Spec.Path,
Branch: pr.Spec.Branch,
TerraformConfig: layer.Spec.TerraformConfig,
Repository: layer.Spec.Repository,
Path: layer.Spec.Path,
Branch: pr.Spec.Branch,
TerraformConfig: layer.Spec.TerraformConfig,
TerragruntConfig: layer.Spec.TerragruntConfig,
OpenTofuConfig: layer.Spec.OpenTofuConfig,
Repository: layer.Spec.Repository,
RemediationStrategy: configv1alpha1.RemediationStrategy{
AutoApply: &[]bool{false}[0],
},
RunHistoryPolicy: layer.Spec.RunHistoryPolicy,
OverrideRunnerSpec: layer.Spec.OverrideRunnerSpec,
},
}
Expand Down

0 comments on commit 6c78042

Please sign in to comment.