Skip to content

Commit

Permalink
Go rewrite handwritten provider files (GoogleCloudPlatform#11638)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored and Mehul3217 committed Sep 5, 2024
1 parent af8d9e5 commit 95b2cc1
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 16 deletions.
11 changes: 0 additions & 11 deletions mmv1/third_party/terraform/fwtransport/go/framework_config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import (
)

type FrameworkProviderConfig struct {
// Temporary, as we'll replace use of FrameworkProviderConfig with transport_tpg.Config soon
// transport_tpg.Config has a Credentials field, hence this change is needed
Credentials types.String
// End temporary

BillingProject types.String
Client *http.Client
Context context.Context
Expand Down Expand Up @@ -101,12 +96,6 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.{{ $product.Name }}BasePath = data.{{ $product.Name }}CustomEndpoint.ValueString()
{{- end }}

// Temporary
p.Credentials = data.Credentials
// End temporary

// Copy values from the ProviderModel struct containing data about the provider configuration (present only when responsing to ConfigureProvider rpc calls)
// to the FrameworkProviderConfig struct that will be passed and available to all resources/data sources
p.Context = ctx
p.BillingProject = data.BillingProject
p.DefaultLabels = data.DefaultLabels
Expand Down
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,116 @@ func TestAccCloudRunService_csiVolume(t *testing.T) {
project := envvar.GetTestProjectFromEnv()
name := "tftest-cloudrun-" + acctest.RandString(t, 6)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceWithNoVolume(name, project),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdateWithGcsVolume(name, project,),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"},
},
},
})
}


func testAccCloudRunService_cloudRunServiceWithNoVolume(name, project string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
name = "%s"
location = "us-central1"

metadata {
namespace = "%s"
annotations = {
generated-by = "magic-modules"
}
}

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
}
}
}

lifecycle {
ignore_changes = [
metadata.0.annotations,
]
}
}
`, name, project)
}


func testAccCloudRunService_cloudRunServiceUpdateWithGcsVolume(name, project string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
name = "%s"
location = "us-central1"

metadata {
namespace = "%s"
annotations = {
generated-by = "magic-modules"
}
}

template {
metadata {
annotations = {
"run.googleapis.com/execution-environment" = "gen2"
}
}
spec {
containers {
image = "gcr.io/cloudrun/hello"
volume_mounts {
name = "vol1"
mount_path = "/mnt/vol1"
}
}
volumes {
name = "vol1"
csi {
driver = "gcsfuse.run.googleapis.com"
read_only = true
volume_attributes = {
bucketName = "gcp-public-data-landsat"
}
}
}
}
}

}
`, name, project)
}

{{ if ne $.TargetVersionName `ga` -}}

func TestAccCloudRunService_emptyDirVolume(t *testing.T) {
t.Parallel()

project := envvar.GetTestProjectFromEnv()
name := "tftest-cloudrun-" + acctest.RandString(t, 6)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func testAccCloudRunV2Job_cloudrunv2JobWithNoVolume(context map[string]interface
name = "%{job_name}"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
template {
template {
containers {
Expand All @@ -374,7 +373,6 @@ func testAccCloudRunV2Job_cloudrunv2JobWithGcsVolume(context map[string]interfac
name = "%{job_name}"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
template {
template {
containers {
Expand Down Expand Up @@ -444,7 +442,6 @@ func testAccCloudRunV2Job_cloudrunv2JobWithNfsVolume(context map[string]interfac
name = "%{job_name}"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"
template {
template {
containers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ resource "google_cloud_run_v2_service" "default" {
description = "description creating"
location = "us-central1"
deletion_protection = false
launch_stage = "BETA"

annotations = {
generated-by = "magic-modules"
}
Expand Down

0 comments on commit 95b2cc1

Please sign in to comment.