@@ -384,6 +384,29 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_update(t *testing.T) {
384
384
})
385
385
}
386
386
387
+ func testAccBigqueryDataTransferConfig_CMEK (t * testing.T ) {
388
+ // Uses time.Now
389
+ acctest .SkipIfVcr (t )
390
+ random_suffix := acctest .RandString (t , 10 )
391
+
392
+ acctest .VcrTest (t , resource.TestCase {
393
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
394
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
395
+ CheckDestroy : testAccCheckBigqueryDataTransferConfigDestroyProducer (t ),
396
+ Steps : []resource.TestStep {
397
+ {
398
+ Config : testAccBigqueryDataTransferConfig_CMEK_basic (random_suffix ),
399
+ },
400
+ {
401
+ ResourceName : "google_bigquery_data_transfer_config.query_config" ,
402
+ ImportState : true ,
403
+ ImportStateVerify : true ,
404
+ ImportStateVerifyIgnore : []string {"location" },
405
+ },
406
+ },
407
+ })
408
+ }
409
+
387
410
func testAccBigqueryDataTransferConfig_scheduledQuery_no_destination (t * testing.T ) {
388
411
// Uses time.Now
389
412
acctest .SkipIfVcr (t )
@@ -768,6 +791,74 @@ resource "google_bigquery_data_transfer_config" "copy_config" {
768
791
` , random_suffix , random_suffix , random_suffix )
769
792
}
770
793
794
+ func testAccBigqueryDataTransferConfig_CMEK_basic (random_suffix string ) string {
795
+ return fmt .Sprintf (`
796
+ data "google_project" "project" {
797
+ }
798
+
799
+ resource "google_kms_key_ring" "example_keyring" {
800
+ name = "keyring-test-%s"
801
+ location = "us-central1"
802
+ }
803
+
804
+ resource "google_kms_crypto_key" "example_crypto_key" {
805
+ name = "crypto-key-%s"
806
+ key_ring = google_kms_key_ring.example_keyring.id
807
+ purpose = "ENCRYPT_DECRYPT"
808
+ }
809
+
810
+ resource "google_service_account" "bqwriter%s" {
811
+ account_id = "bqwriter%s"
812
+ }
813
+
814
+ resource "google_project_iam_member" "data_editor" {
815
+ project = data.google_project.project.project_id
816
+
817
+ role = "roles/bigquery.dataEditor"
818
+ member = "serviceAccount:${google_service_account.bqwriter%s.email}"
819
+ }
820
+
821
+ data "google_iam_policy" "owner" {
822
+ binding {
823
+ role = "roles/bigquery.dataOwner"
824
+
825
+ members = [
826
+ "serviceAccount:${google_service_account.bqwriter%s.email}",
827
+ ]
828
+ }
829
+ }
830
+
831
+ resource "google_bigquery_dataset_iam_policy" "dataset" {
832
+ dataset_id = google_bigquery_dataset.my_dataset.dataset_id
833
+ policy_data = data.google_iam_policy.owner.policy_data
834
+ }
835
+
836
+ resource "google_bigquery_data_transfer_config" "query_config" {
837
+ depends_on = [ google_kms_crypto_key.example_crypto_key ]
838
+ encryption_configuration {
839
+ kms_key_name = google_kms_crypto_key.example_crypto_key.id
840
+ }
841
+ display_name = "my-query-%s"
842
+ location = "us-central1"
843
+ data_source_id = "scheduled_query"
844
+ schedule = "first sunday of quarter 00:00"
845
+ destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
846
+ params = {
847
+ destination_table_name_template = "my_table"
848
+ write_disposition = "WRITE_APPEND"
849
+ query = "SELECT name FROM table WHERE x = 'y'"
850
+ }
851
+ }
852
+
853
+ resource "google_bigquery_dataset" "my_dataset" {
854
+ dataset_id = "my_dataset_%s"
855
+ friendly_name = "foo"
856
+ description = "bar"
857
+ location = "us-central1"
858
+ }
859
+ ` , random_suffix , random_suffix , random_suffix , random_suffix , random_suffix , random_suffix , random_suffix , random_suffix )
860
+ }
861
+
771
862
func testAccBigqueryDataTransferConfig_update_params_force_new (random_suffix , path , table string ) string {
772
863
return fmt .Sprintf (`
773
864
resource "google_bigquery_dataset" "dataset" {
0 commit comments