diff --git a/mmv1/third_party/terraform/acctest/vcr_utils.go b/mmv1/third_party/terraform/acctest/vcr_utils.go index 33b1551010f2..4e8753d8c9ec 100644 --- a/mmv1/third_party/terraform/acctest/vcr_utils.go +++ b/mmv1/third_party/terraform/acctest/vcr_utils.go @@ -24,9 +24,7 @@ import ( "github.com/hashicorp/terraform-provider-google/google/fwprovider" tpgprovider "github.com/hashicorp/terraform-provider-google/google/provider" - "github.com/hashicorp/terraform-provider-google/google/services/compute" - "github.com/hashicorp/terraform-provider-google/google/services/pubsublite" - "github.com/hashicorp/terraform-provider-google/google/services/sql" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" @@ -376,13 +374,13 @@ func (p *frameworkTestProvider) Configure(ctx context.Context, req provider.Conf func (p *frameworkTestProvider) DataSources(ctx context.Context) []func() datasource.DataSource { ds := p.FrameworkProvider.DataSources(ctx) ds = append(ds, fwprovider.NewGoogleProviderConfigPluginFrameworkDataSource) // google_provider_config_plugin_framework - ds = append(ds, compute.NewComputeNetworkFWDataSource) // google_fw_compute_network + return ds } func (p *frameworkTestProvider) Resources(ctx context.Context) []func() fwResource.Resource { r := p.FrameworkProvider.Resources(ctx) - r = append(r, pubsublite.NewGooglePubsubLiteReservationFWResource, sql.NewSQLUserFWResource) // google_fwprovider_pubsub_lite_reservation + return r } diff --git a/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network.go.tmpl b/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network.go.tmpl deleted file mode 100644 index e265b1e4dfbe..000000000000 --- a/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network.go.tmpl +++ /dev/null @@ -1,187 +0,0 @@ -package compute - -import ( - "context" - "fmt" - "strconv" - - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" - {{ if eq $.TargetVersionName `ga` }} - "google.golang.org/api/compute/v1" - {{- else }} - compute "google.golang.org/api/compute/v0.beta" - {{- end }} - - "github.com/hashicorp/terraform-provider-google/google/fwmodels" - "github.com/hashicorp/terraform-provider-google/google/fwresource" - "github.com/hashicorp/terraform-provider-google/google/fwtransport" - transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" -) - -// Ensure the implementation satisfies the expected interfaces. -var ( - _ datasource.DataSource = &ComputeNetworkFWDataSource{} - _ datasource.DataSourceWithConfigure = &ComputeNetworkFWDataSource{} -) - -// NewComputeNetworkFWDataSource is a helper function to simplify the provider implementation. -func NewComputeNetworkFWDataSource() datasource.DataSource { - return &ComputeNetworkFWDataSource{} -} - -// ComputeNetworkFWDataSource is the data source implementation. -type ComputeNetworkFWDataSource struct { - client *compute.Service - providerConfig *transport_tpg.Config -} - -type ComputeNetworkModel struct { - Id types.String `tfsdk:"id"` - Project types.String `tfsdk:"project"` - Name types.String `tfsdk:"name"` - Description types.String `tfsdk:"description"` - NetworkId types.Int64 `tfsdk:"network_id"` - NumericId types.String `tfsdk:"numeric_id"` - GatewayIpv4 types.String `tfsdk:"gateway_ipv4"` - InternalIpv6Range types.String `tfsdk:"internal_ipv6_range"` - SelfLink types.String `tfsdk:"self_link"` - // NetworkProfile types.String `tfsdk:"network_profile"` - // SubnetworksSelfLinks types.List `tfsdk:"subnetworks_self_links"` -} - -// Metadata returns the data source type name. -func (d *ComputeNetworkFWDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_fw_compute_network" -} - -func (d *ComputeNetworkFWDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - config, ok := req.ProviderData.(*transport_tpg.Config) - if !ok { - resp.Diagnostics.AddError( - "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected *transport_tpg.Config, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - return - } - - d.client = NewClient(config, config.UserAgent) - if resp.Diagnostics.HasError() { - return - } - d.providerConfig = config -} - -// Schema defines the schema for the data source. -func (d *ComputeNetworkFWDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "A data source to get network details.", - - Attributes: map[string]schema.Attribute{ - "project": schema.StringAttribute{ - Description: `The project name.`, - MarkdownDescription: `The project name.`, - Optional: true, - }, - "name": schema.StringAttribute{ - Description: `The name of the Compute network.`, - MarkdownDescription: `The name of the Compute network.`, - Required: true, - }, - "description": schema.StringAttribute{ - Description: `The description of the network.`, - MarkdownDescription: `The description of the network.`, - Computed: true, - }, - "network_id": schema.Int64Attribute{ - Description: `The network ID.`, - MarkdownDescription: `The network ID.`, - Computed: true, - }, - "numeric_id": schema.StringAttribute{ - Description: `The numeric ID of the network. Deprecated in favor of network_id.`, - MarkdownDescription: `The numeric ID of the network. Deprecated in favor of network_id.`, - Computed: true, - DeprecationMessage: "`numeric_id` is deprecated and will be removed in a future major release. Use `network_id` instead.", - }, - "gateway_ipv4": schema.StringAttribute{ - Description: `The gateway address for default routing out of the network.`, - MarkdownDescription: `The gateway address for default routing out of the network.`, - Computed: true, - }, - "internal_ipv6_range": schema.StringAttribute{ - Description: `The internal ipv6 address range of the network.`, - MarkdownDescription: `The internal ipv6 address range of the network.`, - Computed: true, - }, - "self_link": schema.StringAttribute{ - Description: `The network self link.`, - MarkdownDescription: `The network self link.`, - Computed: true, - }, - // This is included for backwards compatibility with the original, SDK-implemented data source. - "id": schema.StringAttribute{ - Description: "Project identifier", - MarkdownDescription: "Project identifier", - Computed: true, - }, - }, - } -} - -// Read refreshes the Terraform state with the latest data. -func (d *ComputeNetworkFWDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data ComputeNetworkModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - d.client.UserAgent = fwtransport.GenerateFrameworkUserAgentString(metaData, d.client.UserAgent) - - project := fwresource.GetProjectFramework(data.Project, types.StringValue(d.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - // GET Request - clientResp, err := d.client.Networks.Get(project.ValueString(), data.Name.ValueString()).Do() - if err != nil { - fwtransport.HandleNotFoundError(ctx, err, &resp.State, fmt.Sprintf("dataSourceComputeNetwork %q", data.Name.ValueString()), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - } - - tflog.Trace(ctx, "read compute network data source") - - // Put data in model - id := fmt.Sprintf("projects/%s/global/networks/%s", project.ValueString(), clientResp.Name) - data.Id = types.StringValue(id) - data.Description = types.StringValue(clientResp.Description) - data.NetworkId = types.Int64Value(int64(clientResp.Id)) - data.NumericId = types.StringValue(strconv.Itoa(int(clientResp.Id))) - data.GatewayIpv4 = types.StringValue(clientResp.GatewayIPv4) - data.InternalIpv6Range = types.StringValue(clientResp.InternalIpv6Range) - data.SelfLink = types.StringValue(clientResp.SelfLink) - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} diff --git a/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network_test.go b/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network_test.go deleted file mode 100644 index ae82326c793d..000000000000 --- a/mmv1/third_party/terraform/services/compute/fw_data_source_google_compute_network_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package compute_test - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/hashicorp/terraform-provider-google/google/acctest" - "github.com/hashicorp/terraform-provider-google/google/tpgresource" -) - -func TestAccDataSourceGoogleFWNetwork(t *testing.T) { - t.Parallel() - - networkName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - Steps: []resource.TestStep{ - { - Config: testAccDataSourceGoogleNetworkFWConfig(networkName), - Check: resource.ComposeTestCheckFunc( - testAccDataSourceGoogleFWNetworkCheck("data.google_fw_compute_network.my_network", "google_compute_network.foobar"), - ), - }, - }, - }) -} - -func testAccDataSourceGoogleFWNetworkCheck(data_source_name string, resource_name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ds, ok := s.RootModule().Resources[data_source_name] - if !ok { - return fmt.Errorf("root module has no resource called %s", data_source_name) - } - - rs, ok := s.RootModule().Resources[resource_name] - if !ok { - return fmt.Errorf("can't find %s in state", resource_name) - } - - ds_attr := ds.Primary.Attributes - rs_attr := rs.Primary.Attributes - network_attrs_to_test := []string{ - "id", - "name", - "network_id", - "numeric_id", - "description", - "internal_ipv6_range", - } - - for _, attr_to_check := range network_attrs_to_test { - if ds_attr[attr_to_check] != rs_attr[attr_to_check] { - return fmt.Errorf( - "%s is %s; want %s", - attr_to_check, - ds_attr[attr_to_check], - rs_attr[attr_to_check], - ) - } - } - - if !tpgresource.CompareSelfLinkOrResourceName("", ds_attr["self_link"], rs_attr["self_link"], nil) && ds_attr["self_link"] != rs_attr["self_link"] { - return fmt.Errorf("self link does not match: %s vs %s", ds_attr["self_link"], rs_attr["self_link"]) - } - - return nil - } -} - -func testAccDataSourceGoogleNetworkFWConfig(name string) string { - return fmt.Sprintf(` -resource "google_compute_network" "foobar" { - name = "%s" - description = "my-description" - enable_ula_internal_ipv6 = true - auto_create_subnetworks = false -} - -data "google_fw_compute_network" "my_network" { - name = google_compute_network.foobar.name -} -`, name) -} diff --git a/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation.go b/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation.go deleted file mode 100644 index adfb5a863999..000000000000 --- a/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation.go +++ /dev/null @@ -1,386 +0,0 @@ -package pubsublite - -import ( - "context" - "fmt" - "net/http" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" - - "github.com/hashicorp/terraform-provider-google/google/fwmodels" - "github.com/hashicorp/terraform-provider-google/google/fwresource" - "github.com/hashicorp/terraform-provider-google/google/fwtransport" - transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" - "google.golang.org/api/pubsublite/v1" -) - -//resource is non-functional, preserved for reference with ongoing fwprovider work -//any changes to `google_pubsublite_reservation` should be performed at mmv1/products/pubsublite/Reservation.yaml - -// Ensure the implementation satisfies the expected interfaces. -var ( - _ resource.Resource = &GooglePubsubLiteReservationFWResource{} - _ resource.ResourceWithConfigure = &GooglePubsubLiteReservationFWResource{} -) - -// NewGooglePubsubLiteReservationResource is a helper function to simplify the provider implementation. -func NewGooglePubsubLiteReservationFWResource() resource.Resource { - return &GooglePubsubLiteReservationFWResource{} -} - -// GooglePubsubLiteReservationResource is the resource implementation. -type GooglePubsubLiteReservationFWResource struct { - client *pubsublite.Service - providerConfig *transport_tpg.Config -} - -type GooglePubsubLiteReservationModel struct { - Id types.String `tfsdk:"id"` - Project types.String `tfsdk:"project"` - Region types.String `tfsdk:"region"` - Name types.String `tfsdk:"name"` - ThroughputCapacity types.Int64 `tfsdk:"throughput_capacity"` -} - -// Metadata returns the resource type name. -func (d *GooglePubsubLiteReservationFWResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_fwprovider_pubsub_lite_reservation" -} - -func (d *GooglePubsubLiteReservationFWResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - p, ok := req.ProviderData.(*transport_tpg.Config) - if !ok { - resp.Diagnostics.AddError( - "Unexpected Resource Configure Type", - fmt.Sprintf("Expected *transport_tpg.Config, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - return - } - - d.providerConfig = p -} - -// Schema defines the schema for the data source. -func (d *GooglePubsubLiteReservationFWResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "Pubsub Lite Reservation resource description", - - Attributes: map[string]schema.Attribute{ - "project": schema.StringAttribute{ - Description: "The project id of the Pubsub Lite Reservation.", - MarkdownDescription: "The project id of the Pubsub Lite Reservation.", - Required: true, - }, - "region": schema.StringAttribute{ - Description: "The region of the Pubsub Lite Reservation.", - MarkdownDescription: "The region of the Pubsub Lite Reservation.", - Required: true, - }, - "name": schema.StringAttribute{ - Description: `The display name of the project.`, - MarkdownDescription: `The display name of the project.`, - Required: true, - }, - "throughput_capacity": schema.Int64Attribute{ - Description: `The reserved throughput capacity. Every unit of throughput capacity is equivalent to 1 MiB/s of published messages or 2 MiB/s of subscribed messages.`, - MarkdownDescription: `The reserved throughput capacity. Every unit of throughput capacity is equivalent to 1 MiB/s of published messages or 2 MiB/s of subscribed messages.`, - Required: true, - }, - // This is included for backwards compatibility with the original, SDK-implemented data source. - "id": schema.StringAttribute{ - Description: "Project identifier", - MarkdownDescription: "Project identifier", - Computed: true, - }, - }, - } -} - -func (d *GooglePubsubLiteReservationFWResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data GooglePubsubLiteReservationModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - userAgent := fwtransport.GenerateFrameworkUserAgentString(metaData, d.providerConfig.UserAgent) - - obj := make(map[string]interface{}) - - obj["throughputCapacity"] = data.ThroughputCapacity.ValueInt64() - - data.Project = fwresource.GetProjectFramework(data.Project, types.StringValue(d.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - data.Region = fwresource.GetRegionFramework(data.Region, types.StringValue(d.providerConfig.Region), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - billingProject := data.Project - - var schemaDefaultVals fwtransport.DefaultVars - schemaDefaultVals.Project = data.Project - schemaDefaultVals.Region = data.Region - - url := fwtransport.ReplaceVars(ctx, req, &resp.Diagnostics, schemaDefaultVals, d.providerConfig, "{{PubsubLiteBasePath}}projects/{{project}}/locations/{{region}}/reservations?reservationId={{name}}") - if resp.Diagnostics.HasError() { - return - } - tflog.Trace(ctx, fmt.Sprintf("[DEBUG] Creating new Reservation: %#v", obj)) - - headers := make(http.Header) - res, _ := fwtransport.SendRequest(fwtransport.SendRequestOptions{ - Config: d.providerConfig, - Method: "POST", - Project: billingProject.ValueString(), - RawURL: url, - UserAgent: userAgent, - Body: obj, - Headers: headers, - }, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - tflog.Trace(ctx, "create fwprovider google_pubsub_lite resource") - - // Put data in model - data.Id = types.StringValue(fmt.Sprintf("projects/%s/locations/%s/reservations/%s", data.Project.ValueString(), data.Region.ValueString(), data.Name.ValueString())) - data.ThroughputCapacity = types.Int64Value(res["throughputCapacity"].(int64)) - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -// Read refreshes the Terraform state with the latest data. -func (d *GooglePubsubLiteReservationFWResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data GooglePubsubLiteReservationModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - userAgent := fwtransport.GenerateFrameworkUserAgentString(metaData, d.providerConfig.UserAgent) - - data.Project = fwresource.GetProjectFramework(data.Project, types.StringValue(d.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - data.Region = fwresource.GetRegionFramework(data.Region, types.StringValue(d.providerConfig.Region), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - billingProject := data.Project - - var schemaDefaultVals fwtransport.DefaultVars - schemaDefaultVals.Project = data.Project - schemaDefaultVals.Region = data.Region - - url := fwtransport.ReplaceVars(ctx, req, &resp.Diagnostics, schemaDefaultVals, d.providerConfig, "{{PubSubLiteBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") - - if resp.Diagnostics.HasError() { - return - } - - headers := make(http.Header) - res, _ := fwtransport.SendRequest(fwtransport.SendRequestOptions{ - Config: d.providerConfig, - Method: "GET", - Project: billingProject.ValueString(), - RawURL: url, - UserAgent: userAgent, - Headers: headers, - }, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - tflog.Trace(ctx, "read fwprovider google_pubsub_lite resource") - - // Put data in model - data.Id = types.StringValue(fmt.Sprintf("projects/%s/locations/%s/instances/%s", data.Project.ValueString(), data.Region.ValueString(), data.Name.ValueString())) - data.ThroughputCapacity = types.Int64Value(res["throughputCapacity"].(int64)) - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (d *GooglePubsubLiteReservationFWResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan, state GooglePubsubLiteReservationModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - userAgent := fwtransport.GenerateFrameworkUserAgentString(metaData, d.providerConfig.UserAgent) - - obj := make(map[string]interface{}) - - obj["throughputCapacity"] = plan.ThroughputCapacity.ValueInt64() - - plan.Project = fwresource.GetProjectFramework(plan.Project, types.StringValue(d.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - plan.Region = fwresource.GetRegionFramework(plan.Region, types.StringValue(d.providerConfig.Region), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - billingProject := plan.Project - - var schemaDefaultVals fwtransport.DefaultVars - schemaDefaultVals.Project = plan.Project - schemaDefaultVals.Region = plan.Region - - url := fwtransport.ReplaceVars(ctx, req, &resp.Diagnostics, schemaDefaultVals, d.providerConfig, "{{PubSubLiteBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") - - if resp.Diagnostics.HasError() { - return - } - tflog.Trace(ctx, fmt.Sprintf("[DEBUG] Updating Reservation: %#v", obj)) - - headers := make(http.Header) - - updateMask := []string{} - if !plan.ThroughputCapacity.Equal(state.ThroughputCapacity) { - updateMask = append(updateMask, "throughputCapacity") - } - - // updateMask is a URL parameter but not present in the schema, so ReplaceVars - // won't set it - var err error - url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) - if err != nil { - resp.Diagnostics.AddError("Error when sending HTTP request: ", err.Error()) - return - } - - res, _ := fwtransport.SendRequest(fwtransport.SendRequestOptions{ - Config: d.providerConfig, - Method: "PATCH", - Project: billingProject.ValueString(), - RawURL: url, - UserAgent: userAgent, - Body: obj, - Headers: headers, - }, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - tflog.Trace(ctx, "update fwprovider google_pubsub_lite resource") - - // Put data in model - plan.Id = types.StringValue(fmt.Sprintf("projects/%s/locations/%s/instances/%s", plan.Project.ValueString(), plan.Region.ValueString(), plan.Name.ValueString())) - plan.ThroughputCapacity = types.Int64Value(res["throughputCapacity"].(int64)) - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) -} -func (d *GooglePubsubLiteReservationFWResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data GooglePubsubLiteReservationModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - // Use provider_meta to set User-Agent - userAgent := fwtransport.GenerateFrameworkUserAgentString(metaData, d.providerConfig.UserAgent) - - obj := make(map[string]interface{}) - - data.Project = fwresource.GetProjectFramework(data.Project, types.StringValue(d.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - data.Region = fwresource.GetRegionFramework(data.Region, types.StringValue(d.providerConfig.Region), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - billingProject := data.Project - - var schemaDefaultVals fwtransport.DefaultVars - schemaDefaultVals.Project = data.Project - schemaDefaultVals.Region = data.Region - - url := fwtransport.ReplaceVars(ctx, req, &resp.Diagnostics, schemaDefaultVals, d.providerConfig, "{{PubSubLiteBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") - - if resp.Diagnostics.HasError() { - return - } - tflog.Trace(ctx, fmt.Sprintf("[DEBUG] Deleting Reservation: %#v", obj)) - - headers := make(http.Header) - res, _ := fwtransport.SendRequest(fwtransport.SendRequestOptions{ - Config: d.providerConfig, - Method: "DELETE", - Project: billingProject.ValueString(), - RawURL: url, - UserAgent: userAgent, - Body: obj, - Headers: headers, - }, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - tflog.Trace(ctx, fmt.Sprintf("[DEBUG] Deleted Reservation: %#v", res)) -} diff --git a/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation_test.go b/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation_test.go deleted file mode 100644 index e642be5341ff..000000000000 --- a/mmv1/third_party/terraform/services/pubsublite/fw_resource_pubsub_lite_reservation_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package pubsublite_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-provider-google/google/acctest" -) - -func TestAccResourceFWPubsubLiteReservation_basic(t *testing.T) { - //tests and resource are non-functional, preserved for reference with ongoing fwprovider work - t.Skip() - t.Parallel() - - context := map[string]interface{}{ - "random_suffix": acctest.RandString(t, 10), - } - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - Steps: []resource.TestStep{ - { - Config: testAccResourceFWPubsubLiteReservation_basic(context), - }, - { - Config: testAccResourceFWPubsubLiteReservation_upgrade(context), - }, - }, - }) -} - -func testAccResourceFWPubsubLiteReservation_basic(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_fwprovider_pubsub_lite_reservation" "basic" { - name = "tf-test-example-reservation%{random_suffix}" - region = "us-central1" - project = data.google_project.project.number - throughput_capacity = 2 -} - -data "google_project" "project" { -} -`, context) -} - -func testAccResourceFWPubsubLiteReservation_upgrade(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_fwprovider_pubsub_lite_reservation" "basic" { - name = "tf-test-example-reservation%{random_suffix}" - region = "us-central1" - project = data.google_project.project.number - throughput_capacity = 3 -} - -data "google_project" "project" { -} -`, context) -} diff --git a/mmv1/third_party/terraform/services/sql/fw_resource_sql_user.go b/mmv1/third_party/terraform/services/sql/fw_resource_sql_user.go deleted file mode 100644 index 1855c3aea9e5..000000000000 --- a/mmv1/third_party/terraform/services/sql/fw_resource_sql_user.go +++ /dev/null @@ -1,510 +0,0 @@ -package sql - -import ( - "context" - "fmt" - "strings" - "time" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" - - "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "github.com/hashicorp/terraform-provider-google/google/fwmodels" - "github.com/hashicorp/terraform-provider-google/google/fwresource" - "github.com/hashicorp/terraform-provider-google/google/fwtransport" - "github.com/hashicorp/terraform-provider-google/google/transport" - transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" - sqladmin "google.golang.org/api/sqladmin/v1beta4" -) - -//resource is non-functional, preserved for reference with ongoing fwprovider work -//any changes to `google_sql_user` should be performed at mmv1/third_party/terraform/services/sql/resource_sql_user.go - -var ( - _ resource.Resource = &SQLUserFWResource{} - _ resource.ResourceWithConfigure = &SQLUserFWResource{} -) - -func NewSQLUserFWResource() resource.Resource { - return &SQLUserFWResource{} -} - -type SQLUserFWResource struct { - client *sqladmin.Service - providerConfig *transport_tpg.Config -} - -type SQLUserModel struct { - Id types.String `tfsdk:"id"` - Project types.String `tfsdk:"project"` - Name types.String `tfsdk:"name"` - Host types.String `tfsdk:"host"` - Instance types.String `tfsdk:"instance"` - Password types.String `tfsdk:"password"` - // PasswordWO types.String `tfsdk:"password_wo"` - // PasswordWOVersion types.String `tfsdk:"password_wo_version"` - Type types.String `tfsdk:"type"` - // SqlServerUserDetails types.List `tfsdk:"sql_server_user_details"` - // PasswordPolicy types.List `tfsdk:"password_policy"` - // DeletionPolicy types.String `tfsdk:"deletion_policy"` - Timeouts timeouts.Value `tfsdk:"timeouts"` -} - -// Metadata returns the resource type name. -func (d *SQLUserFWResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_fw_sql_user" -} - -func (r *SQLUserFWResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - config, ok := req.ProviderData.(*transport_tpg.Config) - if !ok { - resp.Diagnostics.AddError( - "Unexpected Resource Configure Type", - fmt.Sprintf("Expected *transport_tpg.Config, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - return - } - - r.client = NewClient(config, config.UserAgent) - if resp.Diagnostics.HasError() { - return - } - r.providerConfig = config -} - -func (d *SQLUserFWResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "A resource to represent a SQL User object.", - - Attributes: map[string]schema.Attribute{ - "project": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - stringplanmodifier.UseStateForUnknown(), - }, - }, - "host": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - stringplanmodifier.UseStateForUnknown(), - }, - }, - "instance": schema.StringAttribute{ - Required: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - }, - }, - "name": schema.StringAttribute{ - Description: `The name of the user. Changing this forces a new resource to be created.`, - Required: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - SQLUserNameIAMPlanModifier(), - }, - }, - "password": schema.StringAttribute{ - Optional: true, - Sensitive: true, - }, - "type": schema.StringAttribute{ - Optional: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplace(), - // TODO DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("BUILT_IN"), - }, - }, - // This is included for backwards compatibility with the original, SDK-implemented resource. - "id": schema.StringAttribute{ - Description: "Project identifier", - MarkdownDescription: "Project identifier", - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, - }, - Blocks: map[string]schema.Block{ - "timeouts": timeouts.Block(ctx, timeouts.Opts{ - Create: true, - }), - }, - } -} - -func (r *SQLUserFWResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data SQLUserModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform plan data into the model - resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - project := fwresource.GetProjectFramework(data.Project, types.StringValue(r.providerConfig.Project), &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - nameData, diags := data.Name.ToStringValue(ctx) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - instanceData, diags := data.Instance.ToStringValue(ctx) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - hostData, diags := data.Host.ToStringValue(ctx) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - typeData, diags := data.Type.ToStringValue(ctx) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - passwordData, diags := data.Password.ToStringValue(ctx) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - createTimeout, diags := data.Timeouts.Create(ctx, 20*time.Minute) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - user := &sqladmin.User{ - Name: nameData.ValueString(), - Instance: instanceData.ValueString(), - Password: passwordData.ValueString(), - Host: hostData.ValueString(), - Type: typeData.ValueString(), - } - - transport_tpg.MutexStore.Lock(instanceMutexKey(project.ValueString(), instanceData.ValueString())) - defer transport_tpg.MutexStore.Unlock(instanceMutexKey(project.ValueString(), instanceData.ValueString())) - - r.client.UserAgent = fwtransport.GenerateFrameworkUserAgentString(metaData, r.client.UserAgent) - - // TODO host check logic - - var op *sqladmin.Operation - var err error - insertFunc := func() error { - op, err = r.client.Users.Insert(project.ValueString(), instanceData.ValueString(), - user).Do() - return err - } - err = transport_tpg.Retry(transport_tpg.RetryOptions{ - RetryFunc: insertFunc, - Timeout: createTimeout, - }) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("Error, failed to insert "+ - "user %s into instance %s", nameData.ValueString(), instanceData.ValueString()), err.Error()) - return - } - - err = SqlAdminOperationWaitTime(r.providerConfig, op, project.ValueString(), "Insert User", r.client.UserAgent, createTimeout) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("Error, failure waiting to insert "+ - "user %s into instance %s", nameData.ValueString(), instanceData.ValueString()), err.Error()) - return - } - - tflog.Trace(ctx, "created sql user resource") - - // This will include a double-slash (//) for postgres instances, - // for which user.Host is an empty string. That's okay. - data.Id = types.StringValue(fmt.Sprintf("%s/%s/%s", user.Name, user.Host, user.Instance)) - data.Project = project - - // read back sql user - r.SQLUserRefresh(ctx, &data, &resp.State, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *SQLUserFWResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data SQLUserModel - var metaData *fwmodels.ProviderMetaModel - - // Read Provider meta into the meta model - resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...) - if resp.Diagnostics.HasError() { - return - } - - // Read Terraform configuration data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - r.client.UserAgent = fwtransport.GenerateFrameworkUserAgentString(metaData, r.client.UserAgent) - - tflog.Trace(ctx, "read sql user resource") - - // read back sql user - r.SQLUserRefresh(ctx, &data, &resp.State, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - // Save data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *SQLUserFWResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var old, new SQLUserModel - var metaData *fwmodels.ProviderMetaModel - - resp.Diagnostics.Append(req.State.Get(ctx, &old)...) - if resp.Diagnostics.HasError() { - return - } - - resp.Diagnostics.Append(req.Plan.Get(ctx, &new)...) - if resp.Diagnostics.HasError() { - return - } - - // Use provider_meta to set User-Agent - r.client.UserAgent = fwtransport.GenerateFrameworkUserAgentString(metaData, r.client.UserAgent) - - if !old.Password.Equal(new.Password) { - project := new.Project.ValueString() - instance := new.Instance.ValueString() - name := new.Name.ValueString() - host := new.Host.ValueString() - password := new.Password.ValueString() - - updateTimeout, diags := new.Timeouts.Update(ctx, 20*time.Minute) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - user := &sqladmin.User{ - Name: name, - Instance: instance, - Password: password, - } - transport_tpg.MutexStore.Lock(instanceMutexKey(project, instance)) - defer transport_tpg.MutexStore.Unlock(instanceMutexKey(project, instance)) - var op *sqladmin.Operation - var err error - updateFunc := func() error { - op, err = r.client.Users.Update(project, instance, user).Host(host).Name(name).Do() - return err - } - err = transport_tpg.Retry(transport_tpg.RetryOptions{ - RetryFunc: updateFunc, - Timeout: updateTimeout, - }) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("failed to update"+ - "user %s in instance %s", name, instance), err.Error()) - return - } - - err = SqlAdminOperationWaitTime(r.providerConfig, op, project, "Update User", r.client.UserAgent, updateTimeout) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("failure waiting for update"+ - "user %s in instance %s", name, instance), err.Error()) - return - } - - // read back sql user - r.SQLUserRefresh(ctx, &new, &resp.State, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - } - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &new)...) -} - -func (r *SQLUserFWResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data SQLUserModel - - // Read Terraform prior state data into the model - resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { - return - } - - project := data.Project.ValueString() - instance := data.Instance.ValueString() - name := data.Name.ValueString() - host := data.Host.ValueString() - - deleteTimeout, diags := data.Timeouts.Delete(ctx, 20*time.Minute) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - transport_tpg.MutexStore.Lock(instanceMutexKey(project, instance)) - defer transport_tpg.MutexStore.Unlock(instanceMutexKey(project, instance)) - var op *sqladmin.Operation - var err error - deleteFunc := func() error { - op, err = r.client.Users.Delete(project, instance).Host(host).Name(name).Do() - return err - } - err = transport_tpg.Retry(transport_tpg.RetryOptions{ - RetryFunc: deleteFunc, - Timeout: deleteTimeout, - }) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("failed to delete"+ - "user %s in instance %s", name, instance), err.Error()) - return - } - - err = SqlAdminOperationWaitTime(r.providerConfig, op, project, "Delete User", r.client.UserAgent, deleteTimeout) - - if err != nil { - resp.Diagnostics.AddError(fmt.Sprintf("Error, failure waiting to delete "+ - "user %s", name), err.Error()) - return - } -} - -func (r *SQLUserFWResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - idParts := strings.Split(req.ID, "/") - - // TODO recreate all import cases - if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" { - resp.Diagnostics.AddError( - "Unexpected Import Identifier", - fmt.Sprintf("Expected import identifier with format: project/instance/host/name. Got: %q", req.ID), - ) - return - } - - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project"), idParts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("host"), idParts[2])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[3])...) -} - -func (r *SQLUserFWResource) SQLUserRefresh(ctx context.Context, data *SQLUserModel, state *tfsdk.State, diag *diag.Diagnostics) { - userReadResp, err := r.client.Users.Get(data.Project.ValueString(), data.Instance.ValueString(), data.Name.ValueString()).Host(data.Host.ValueString()).Do() - if err != nil { - // Treat HTTP 404 Not Found status as a signal to recreate resource - // and return early - if userReadResp != nil && transport.IsGoogleApiErrorWithCode(err, userReadResp.HTTPStatusCode) { - tflog.Trace(ctx, "sql user resource not found, removing from state") - state.RemoveResource(ctx) - return - } - diag.AddError(fmt.Sprintf("Error, failure waiting to read "+ - "user %s", data.Name.ValueString()), err.Error()) - return - } - - id := fmt.Sprintf("projects/%s/global/networks/%s", userReadResp.Project, userReadResp.Name) - data.Id = types.StringValue(id) - data.Project = types.StringValue(userReadResp.Project) - data.Instance = types.StringValue(userReadResp.Instance) - if userReadResp.Host != "" { - data.Host = types.StringValue(userReadResp.Host) - } - if userReadResp.Type != "" { - data.Type = types.StringValue(userReadResp.Type) - } -} - -// Plan Modifiers -func SQLUserNameIAMPlanModifier() planmodifier.String { - return &sqlUserNameIAMPlanModifier{} -} - -type sqlUserNameIAMPlanModifier struct { -} - -func (d *sqlUserNameIAMPlanModifier) Description(ctx context.Context) string { - return "Suppresses name diffs for IAM user types." -} -func (d *sqlUserNameIAMPlanModifier) MarkdownDescription(ctx context.Context) string { - return d.Description(ctx) -} - -// Plan modifier to emulate the SDK diffSuppressIamUserName -func (d *sqlUserNameIAMPlanModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { - // Retrieve relevant fields - var oldName types.String - diags := req.State.GetAttribute(ctx, path.Root("name"), &oldName) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - var newName types.String - diags = req.Plan.GetAttribute(ctx, path.Root("name"), &newName) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - var userType types.String - diags = req.Plan.GetAttribute(ctx, path.Root("type"), &userType) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - // Old diff suppress logic - strippedNewName := strings.Split(newName.ValueString(), "@")[0] - - if oldName.ValueString() == strippedNewName && strings.Contains(userType.ValueString(), "IAM") { - // Suppress the diff by setting the planned value to the old value - resp.PlanValue = oldName - } -} diff --git a/mmv1/third_party/terraform/services/sql/fw_resource_sql_user_test.go b/mmv1/third_party/terraform/services/sql/fw_resource_sql_user_test.go deleted file mode 100644 index acec7e6bfc16..000000000000 --- a/mmv1/third_party/terraform/services/sql/fw_resource_sql_user_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package sql_test - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-provider-google/google/acctest" - "github.com/hashicorp/terraform-provider-google/google/envvar" -) - -func TestAccSqlUserFW_mysql(t *testing.T) { - //tests and resource are non-functional, preserved for reference with ongoing fwprovider work - t.Skip() - // Multiple fine-grained resources - //acctest.SkipIfVcr(t) - t.Parallel() - - instance := fmt.Sprintf("tf-test-%d", acctest.RandInt(t)) - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccSqlUserDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testGoogleSqlUserFW_mysql(instance, "password"), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleSqlUserExists(t, "google_fw_sql_user.user1"), - testAccCheckGoogleSqlUserExists(t, "google_fw_sql_user.user2"), - ), - }, - { - // Update password - Config: testGoogleSqlUserFW_mysql(instance, "new_password"), - Check: resource.ComposeTestCheckFunc( - testAccCheckGoogleSqlUserExists(t, "google_fw_sql_user.user1"), - testAccCheckGoogleSqlUserExists(t, "google_fw_sql_user.user2"), - testAccCheckGoogleSqlUserExists(t, "google_fw_sql_user.user3"), - ), - }, - { - ResourceName: "google_fw_sql_user.user2", - ImportStateId: fmt.Sprintf("%s/%s/gmail.com/admin", envvar.GetTestProjectFromEnv(), instance), - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"password"}, - }, - { - ResourceName: "google_fw_sql_user.user3", - ImportStateId: fmt.Sprintf("%s/%s/10.0.0.0/24/admin", envvar.GetTestProjectFromEnv(), instance), - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"password"}, - }, - }, - }) -} - -func testGoogleSqlUserFW_mysql(instance, password string) string { - return fmt.Sprintf(` -resource "google_sql_database_instance" "instance" { - name = "%s" - region = "us-central1" - database_version = "MYSQL_5_7" - deletion_protection = false - settings { - tier = "db-f1-micro" - } -} - -resource "google_fw_sql_user" "user1" { - name = "admin" - instance = google_sql_database_instance.instance.name - host = "google.com" - password = "%s" -} - -resource "google_fw_sql_user" "user2" { - name = "admin" - instance = google_sql_database_instance.instance.name - host = "gmail.com" - password = "hunter2" -} - -resource "google_fw_sql_user" "user3" { - name = "admin" - instance = google_sql_database_instance.instance.name - host = "10.0.0.0/24" - password = "hunter3" -} -`, instance, password) -}