Skip to content

Commit

Permalink
Merge branch 'main' into chore_rename_tf_to_tofu
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisiaM authored Apr 9, 2024
2 parents 065ea6f + 9848ca2 commit a3aeb84
Show file tree
Hide file tree
Showing 38 changed files with 249 additions and 39 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,6 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
8 changes: 8 additions & 0 deletions integrationtest/fixtures/binding-cleanup/fake-bad-bind.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
// Fails as required "length" parameter is missing
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_string" "random" {}

output bind_output { value = random_string.random.result }
8 changes: 8 additions & 0 deletions integrationtest/fixtures/binding-cleanup/fake-good-bind.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_string" "random" {
length = 10
}
Expand Down
8 changes: 8 additions & 0 deletions integrationtest/fixtures/binding-cleanup/fake-provision.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_uuid" "random" {}

output provision_output { value = random_uuid.random.result }
8 changes: 8 additions & 0 deletions integrationtest/fixtures/golden-path/fake-uuid-bind.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_uuid" "random" {}

output bind_output { value = random_uuid.random.result }
8 changes: 8 additions & 0 deletions integrationtest/fixtures/golden-path/fake-uuid-provision.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_uuid" "random" {}

output provision_output { value = random_uuid.random.result }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
Expand Down
8 changes: 7 additions & 1 deletion integrationtest/fixtures/osbapi/fake-provision.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "random" { }
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_integer" "priority" {
min = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "random" { }
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

variable length { type = number }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
// Fails as required "length" parameter is missing
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_string" "random" {}

output provision_output { value = random_string.random.result }
1 change: 1 addition & 0 deletions integrationtest/fixtures/subsume/fake-string-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ provision:
import_parameters_to_delete: [ "random_string.random.id", "random_string.random.result" ]
template_refs:
main: fake-string-provision.tf
versions: versions.tf
outputs:
- field_name: provision_output
type: string
Expand Down
1 change: 1 addition & 0 deletions integrationtest/fixtures/subsume/fake-uuid-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ provision:
import_parameters_to_delete: [ "random_uuid.random.id" , "random_uuid.random.result" ]
template_refs:
main: fake-uuid-provision.tf
versions: versions.tf
outputs:
- field_name: provision_output
type: string
Expand Down
7 changes: 7 additions & 0 deletions integrationtest/fixtures/subsume/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_uuid" "random" {}

output bind_output { value = random_uuid.random.result }
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_uuid" "random" {}

output provision_output { value = random_uuid.random.result }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

provider "random" { }

resource "random_integer" "priority" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "random" { }
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_password" "password" {
length = 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "ContentSquare/random"
source = "registry.terraform.io/ContentSquare/random"
version = "3.1.0"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
Expand Down
8 changes: 7 additions & 1 deletion integrationtest/fixtures/terraform-upgrade/fake-bind.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "random" { }
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_integer" "priority" {
min = 1
Expand Down
8 changes: 7 additions & 1 deletion integrationtest/fixtures/terraform-upgrade/fake-provision.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
provider "random" { }
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
}
}
}

resource "random_integer" "priority" {
min = 1
Expand Down
10 changes: 0 additions & 10 deletions integrationtest/fixtures/tf_attribute_skip/fake-provision.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
## new versions of terraform fail with a different error to the one we want to trigger if this file is empty.
## adding some dummy terraform to test errors when a particular field is not present.

terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "3.5.1"
}
}
}

resource "random_integer" "priority" {
min = 3
max = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plans:
provision:
template_refs:
main: fake-provision.tf
versions: versions.tf
user_inputs:
- field_name: skip
type: boolean
Expand Down
8 changes: 8 additions & 0 deletions integrationtest/fixtures/tf_attribute_skip/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
}
3 changes: 2 additions & 1 deletion integrationtest/subsume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var _ = Describe("Subsume", func() {
It("can subsume a resource", func() {
const serviceOfferingGUID = "547cad88-fa93-11eb-9f44-97feefe52547"
const servicePlanGUID = "59624c68-fa93-11eb-9081-e79b0e1ab5ae"
broker.Provision(serviceOfferingGUID, servicePlanGUID, testdrive.WithProvisionParams(`{"value":"a97fd57a-fa94-11eb-8256-930255607a99"}`))
_, err := broker.Provision(serviceOfferingGUID, servicePlanGUID, testdrive.WithProvisionParams(`{"value":"a97fd57a-fa94-11eb-8256-930255607a99"}`))
Expect(err).NotTo(HaveOccurred())
})

It("cancels a subsume operation when a resource would be deleted", func() {
Expand Down
6 changes: 3 additions & 3 deletions internal/brokerpak/manifest/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ var _ = Describe("Parser", func() {
Expect(err).NotTo(HaveOccurred())
Expect(m.TerraformProviders[1].Provider.String()).To(Equal(expected))
},
Entry("empty 'provider' field", "", "registry.opentofu.org/hashicorp/foo"),
Entry("just type", "lala", "registry.opentofu.org/hashicorp/lala"),
Entry("type and namespace", "mycorp/lala", "registry.opentofu.org/mycorp/lala"),
Entry("empty 'provider' field", "", "registry.terraform.io/hashicorp/foo"),
Entry("just type", "lala", "registry.terraform.io/hashicorp/lala"),
Entry("type and namespace", "mycorp/lala", "registry.terraform.io/mycorp/lala"),
Entry("fully qualified", "mything.io/mycorp/lala", "mything.io/mycorp/lala"),
)

Expand Down
6 changes: 6 additions & 0 deletions internal/brokerpak/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"archive/zip"
"fmt"
"io"
"log"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -268,6 +269,11 @@ func (pak *BrokerPakReader) readBytes(name string) ([]byte, error) {

func providerInstallPath(destination string, tfProvider manifest.TerraformProvider) string {
plat := platform.CurrentPlatform()
log.Println("ProviderInstallPath:", filepath.Join(
destination,
tfProvider.Provider.String(),
tfProvider.Version.String(),
fmt.Sprintf("%s_%s", plat.Os, plat.Arch)))
return filepath.Join(
destination,
tfProvider.Provider.String(),
Expand Down
9 changes: 7 additions & 2 deletions internal/brokerpak/reader/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var _ = Describe("reader", func() {
withTerraform(binaryV160),
withProvider("", "terraform-provider-google-beta", "1.19.0", "x4"),
withProvider("other-namespace/google", "terraform-provider-google", "1.19.0", "x5"),
withProvider("custom.registry.org/other-namespace/custom", "terraform-provider-custom", "1.19.0", "x5"),
)

pakReader, err := reader.OpenBrokerPak(pk)
Expand All @@ -44,11 +45,15 @@ var _ = Describe("reader", func() {
Expect(pakReader.ExtractPlatformBins(binOutput)).NotTo(HaveOccurred())

plat := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
hashicorpBinOutput := filepath.Join(binOutput, "registry.opentofu.org", "hashicorp")
hashicorpBinOutput := filepath.Join(binOutput, "registry.terraform.io", "hashicorp")
Expect(filepath.Join(hashicorpBinOutput, "google-beta", "1.19.0", plat, "terraform-provider-google-beta_v1.19.0_x4")).To(BeAnExistingFile())

otherNamespaceBinOutput := filepath.Join(binOutput, "registry.opentofu.org", "other-namespace")
otherNamespaceBinOutput := filepath.Join(binOutput, "registry.terraform.io", "other-namespace")
Expect(filepath.Join(otherNamespaceBinOutput, "google", "1.19.0", plat, "terraform-provider-google_v1.19.0_x5")).To(BeAnExistingFile())

customDomainBinOutput := filepath.Join(binOutput, "custom.registry.org", "other-namespace")
Expect(filepath.Join(customDomainBinOutput, "custom", "1.19.0", plat, "terraform-provider-custom_v1.19.0_x5")).To(BeAnExistingFile())

})

Context("single version of tofu", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/tfproviderfqn/tfproviderfqn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "fmt"

const (
prefix = "terraform-provider-"
defaultRegistry = "registry.opentofu.org"
defaultRegistry = "registry.terraform.io"
defaultNamespace = "hashicorp"
)

Expand Down
Loading

0 comments on commit a3aeb84

Please sign in to comment.