diff --git a/mmv1/products/datafusion/Instance.yaml b/mmv1/products/datafusion/Instance.yaml index 0b568e5ce1a1..8322fd02b88d 100644 --- a/mmv1/products/datafusion/Instance.yaml +++ b/mmv1/products/datafusion/Instance.yaml @@ -227,4 +227,28 @@ properties: The resource name of the Pub/Sub topic. Format: projects/{projectId}/topics/{topic_id} required: true input: true + - !ruby/object:Api::Type::Array + name: 'accelerators' + description: | + List of accelerators enabled for this CDF instance. + If accelerators are enabled it is possible a permadiff will be created with the Options field. + Users will need to either manually update their state file to include these diffed options, or include the field in a [lifecycle ignore changes block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes). + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::Enum + name: 'acceleratorType' + description: | + The type of an accelator for a CDF instance. + values: + - :CDC + - :HEALTHCARE + - :CCAI_INSIGHTS + required: true + - !ruby/object:Api::Type::Enum + name: 'state' + description: | + The type of an accelator for a CDF instance. + values: + - :ENABLED + - :DISABLED diff --git a/mmv1/products/datafusion/terraform.yaml b/mmv1/products/datafusion/terraform.yaml index b1e718382ace..3cfd257d3413 100644 --- a/mmv1/products/datafusion/terraform.yaml +++ b/mmv1/products/datafusion/terraform.yaml @@ -67,6 +67,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides instance_name: "my-instance" custom_code: !ruby/object:Provider::Terraform::CustomCode pre_update: templates/terraform/pre_update/datafusion_instance_update.go.erb + constants: templates/terraform/constants/data_fusion_instance_option.go.erb properties: region: !ruby/object:Overrides::Terraform::PropertyOverride ignore_read: true @@ -77,8 +78,13 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: !ruby/object:Overrides::Terraform::PropertyOverride custom_expand: 'templates/terraform/custom_expand/shortname_to_url.go.erb' custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' - zone: !ruby/object:Overrides::Terraform::PropertyOverride + options: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true + diff_suppress_func: 'instanceOptionsDiffSuppress' + zone: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true + accelerators.state: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true # This is for copying files over files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. diff --git a/mmv1/templates/terraform/constants/data_fusion_instance_option.go.erb b/mmv1/templates/terraform/constants/data_fusion_instance_option.go.erb new file mode 100644 index 000000000000..ede5560480b8 --- /dev/null +++ b/mmv1/templates/terraform/constants/data_fusion_instance_option.go.erb @@ -0,0 +1,21 @@ +var instanceAcceleratorOptions = []string{ + "delta.default.checkpoint.directory", + "ui.feature.cdc", +} + +func instanceOptionsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + // Suppress diffs for the options generated by adding an accelerator to a data fusion instance + for _, option := range instanceAcceleratorOptions { + if strings.Contains(k, option) && new == "" { + return true + } + } + + // Let diff be determined by options (above) + if strings.Contains(k, "options.%") { + return true + } + + // For other keys, don't suppress diff. + return false +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/data_fusion_instance_full.tf.erb b/mmv1/templates/terraform/examples/data_fusion_instance_full.tf.erb index 44daa5eb109e..44e3bee0a2c2 100644 --- a/mmv1/templates/terraform/examples/data_fusion_instance_full.tf.erb +++ b/mmv1/templates/terraform/examples/data_fusion_instance_full.tf.erb @@ -18,6 +18,10 @@ resource "google_data_fusion_instance" "<%= ctx[:primary_resource_id] %>" { ip_allocation = "${google_compute_global_address.private_ip_alloc.address}/${google_compute_global_address.private_ip_alloc.prefix_length}" } + accelerators { + accelerator_type = "CDC" + state = "ENABLED" + } <%= ctx[:vars]['prober_test_run'] %> } diff --git a/mmv1/third_party/terraform/tests/resource_data_fusion_instance_test.go b/mmv1/third_party/terraform/tests/resource_data_fusion_instance_test.go index 0ba6eedf6e81..111da1710700 100644 --- a/mmv1/third_party/terraform/tests/resource_data_fusion_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_data_fusion_instance_test.go @@ -48,6 +48,10 @@ resource "google_data_fusion_instance" "foobar" { options = { prober_test_run = "true" } + accelerators { + accelerator_type = "CDC" + state = "DISABLED" + } } `, instanceName) } @@ -66,6 +70,11 @@ resource "google_data_fusion_instance" "foobar" { label2 = "value2" } version = "6.8.0" + + accelerators { + accelerator_type = "CCAI_INSIGHTS" + state = "ENABLED" + } # Mark for testing to avoid service networking connection usage that is not cleaned up options = { prober_test_run = "true"