Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BigQuery logging update process (incorrect field reference) #599

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastly/block_fastly_service_logging_bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (h *BigQueryLoggingServiceAttributeHandler) Update(_ context.Context, d *sc
if v, ok := modified["template_suffix"]; ok {
opts.Template = gofastly.String(v.(string))
}
if v, ok := modified["user"]; ok {
if v, ok := modified["email"]; ok {
opts.User = gofastly.String(v.(string))
}
if v, ok := modified["secret_key"]; ok {
Expand Down
44 changes: 33 additions & 11 deletions fastly/block_fastly_service_logging_bigquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestAccFastlyServiceVCL_bigquerylogging(t *testing.T) {

name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bqName := fmt.Sprintf("bq %s", acctest.RandString(10))
email := "email@example.com"
emailUpdate := "update@example.com"

secretKey, err := generateKey()
if err != nil {
Expand All @@ -32,10 +34,17 @@ func TestAccFastlyServiceVCL_bigquerylogging(t *testing.T) {
CheckDestroy: testAccCheckServiceVCLDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey),
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_vcl.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, email),
),
},
{
Config: testAccServiceVCLConfigBigQuery(name, bqName, secretKey, emailUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_vcl.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, emailUpdate),
),
},
},
Expand All @@ -47,6 +56,8 @@ func TestAccFastlyServiceVCL_bigquerylogging_compute(t *testing.T) {

name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bqName := fmt.Sprintf("bq %s", acctest.RandString(10))
email := "email@example.com"
emailUpdate := "update@example.com"

secretKey, err := generateKey()
if err != nil {
Expand All @@ -61,10 +72,17 @@ func TestAccFastlyServiceVCL_bigquerylogging_compute(t *testing.T) {
CheckDestroy: testAccCheckServiceVCLDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey),
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey, email),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_compute.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, email),
),
},
{
Config: testAccServiceVCLConfigBigQueryCompute(name, bqName, secretKey, emailUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceVCLExists("fastly_service_compute.foo", &service),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName),
testAccCheckFastlyServiceVCLAttributesBQ(&service, name, bqName, emailUpdate),
),
},
},
Expand Down Expand Up @@ -116,7 +134,7 @@ func TestBigqueryloggingEnvDefaultFuncAttributes(t *testing.T) {
}
}

func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, name, bqName string) resource.TestCheckFunc {
func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, name, bqName, email string) resource.TestCheckFunc {
return func(_ *terraform.State) error {
if service.Name != name {
return fmt.Errorf("bad name, expected (%s), got (%s)", name, service.Name)
Expand All @@ -139,11 +157,15 @@ func testAccCheckFastlyServiceVCLAttributesBQ(service *gofastly.ServiceDetail, n
return fmt.Errorf("bigQuery logging endpoint name mismatch, expected: %s, got: %#v", bqName, bqList[0].Name)
}

if bqList[0].User != email {
return fmt.Errorf("bigQuery logging endpoint user/email mismatch, expected: %s, got: %#v", email, bqList[0].User)
}

return nil
}
}

func testAccServiceVCLConfigBigQuery(name, gcsName, secretKey string) string {
func testAccServiceVCLConfigBigQuery(name, gcsName, secretKey, email string) string {
backendName := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
domainName := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
return fmt.Sprintf(`
Expand All @@ -162,8 +184,8 @@ resource "fastly_service_vcl" "foo" {

logging_bigquery {
name = "%s"
email = "email@example.com"
secret_key = trimspace(%q)
email = "%s"
project_id = "example-gcp-project"
dataset = "example_bq_dataset"
table = "example_bq_table"
Expand All @@ -172,10 +194,10 @@ resource "fastly_service_vcl" "foo" {
}

force_destroy = true
}`, name, domainName, backendName, gcsName, secretKey)
}`, name, domainName, backendName, gcsName, secretKey, email)
}

func testAccServiceVCLConfigBigQueryCompute(name, gcsName, secretKey string) string {
func testAccServiceVCLConfigBigQueryCompute(name, gcsName, secretKey, email string) string {
backendName := fmt.Sprintf("%s.aws.amazon.com", acctest.RandString(3))
domainName := fmt.Sprintf("fastly-test.tf-%s.com", acctest.RandString(10))
return fmt.Sprintf(`
Expand All @@ -194,8 +216,8 @@ resource "fastly_service_compute" "foo" {

logging_bigquery {
name = "%s"
email = "email@example.com"
secret_key = trimspace(%q)
email = "%s"
project_id = "example-gcp-project"
dataset = "example_bq_dataset"
table = "example_bq_table"
Expand All @@ -207,7 +229,7 @@ resource "fastly_service_compute" "foo" {
}

force_destroy = true
}`, name, domainName, backendName, gcsName, secretKey)
}`, name, domainName, backendName, gcsName, secretKey, email)
}

func setBQEnv(email, secretKey string, t *testing.T) func() {
Expand Down