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

Data source addition for Backupdr Beta #8854

Merged
merged 34 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
47ed128
Add Backupdr with Management Server resource
niharika-98 Aug 10, 2023
72b0a4f
Merge pull request #2 from niharika-98/backupdr-ms
niharika-98 Aug 10, 2023
cab6956
Fixing lint issue
niharika-98 Aug 10, 2023
210fc35
Merge pull request #4 from niharika-98/backupdr-ms
niharika-98 Aug 10, 2023
e20740e
Fixing Variable name
niharika-98 Aug 10, 2023
f528716
Merge pull request #5 from niharika-98/backupdr-ms
niharika-98 Aug 10, 2023
14caf7e
FIxing values of type and peering mode
niharika-98 Aug 11, 2023
4d24393
Merge pull request #6 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
296b0c3
Fixing description and example
niharika-98 Aug 11, 2023
c67f382
Merge pull request #7 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
bb62751
Adding type and Peering_mode to coverage
niharika-98 Aug 11, 2023
3079e15
Merge pull request #8 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
82aa62e
Changing release version of provider to only beta
niharika-98 Aug 11, 2023
8a81d75
Merge pull request #9 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
210dd98
Changing variable name
niharika-98 Aug 11, 2023
08d8ce8
Merge pull request #10 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
f613d57
Fixing Acceptance test and trademark
niharika-98 Aug 11, 2023
9714b8b
Merge pull request #11 from niharika-98/backupdr-ms
niharika-98 Aug 11, 2023
82453bd
datasource changes
niharika-98 Aug 29, 2023
ceda8b2
Merge pull request #12 from niharika-98/budr-tf-provider
niharika-98 Sep 4, 2023
17e313f
Merge branch 'GoogleCloudPlatform:main' into main
niharika-98 Sep 4, 2023
1994a12
Making additional changes
niharika-98 Sep 11, 2023
68b5fe9
Fix data source and acceptance tests
niharika-98 Sep 12, 2023
6a6a941
Merging conditions for data source changes
niharika-98 Sep 12, 2023
6960767
Removing additional resources in examples
niharika-98 Sep 13, 2023
ed65a6f
Fixing data source review comments
niharika-98 Oct 9, 2023
9b70113
Added changes for backupdr management server
niharika-98 Oct 9, 2023
55d3d05
Merge pull request #13 from GoogleCloudPlatform/main
niharika-98 Oct 16, 2023
a55a814
Update mmv1/third_party/terraform/services/backupdr/data_source_backu…
niharika-98 Oct 24, 2023
c723b42
Update mmv1/third_party/terraform/provider/provider.go.erb
niharika-98 Nov 1, 2023
dd1e92a
Added comments as per review comment
niharika-98 Nov 1, 2023
9de6310
Update data_source_backup_dr_management_server.go.erb
niharika-98 Nov 1, 2023
32950f7
Update mmv1/third_party/terraform/services/backupdr/data_source_backu…
shuyama1 Nov 1, 2023
79513bd
Update mmv1/third_party/terraform/services/backupdr/data_source_backu…
shuyama1 Nov 1, 2023
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
3 changes: 3 additions & 0 deletions mmv1/third_party/terraform/provider/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_alloydb_supported_database_flags": alloydb.DataSourceAlloydbSupportedDatabaseFlags(),
"google_artifact_registry_repository": artifactregistry.DataSourceArtifactRegistryRepository(),
"google_app_engine_default_service_account": appengine.DataSourceGoogleAppEngineDefaultServiceAccount(),
<% unless version == 'ga' -%>
"google_backup_dr_management_server": backupdr.DataSourceGoogleCloudBackupDRService(),
<% end -%>
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
"google_beyondcorp_app_connector": beyondcorp.DataSourceGoogleBeyondcorpAppConnector(),
"google_beyondcorp_app_gateway": beyondcorp.DataSourceGoogleBeyondcorpAppGateway(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<% autogen_exception -%>
package backupdr
<% unless version == 'ga' -%>

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"strings"
)

func DataSourceGoogleCloudBackupDRService() *schema.Resource {

dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceBackupDRManagementServer().Schema)
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location")
shuyama1 marked this conversation as resolved.
Show resolved Hide resolved

return &schema.Resource{
Read: dataSourceGoogleCloudBackupDRServiceRead,
Schema: dsSchema,
}
}
func flattenBackupDRManagementServerName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenBackupDRManagementServerResourceResp(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) map[string]interface{} {
if v == nil {
fmt.Printf("Interface is nil: %s", v)
}
fmt.Printf("Interface is : %s", v)
l := v.([]interface{})
for _, raw := range l {
// Management server is a singleton resource. It is only present in one location per project. Hence returning only resource present.
return flattenBackupDRManagementServerResource(raw, d, config)
niharika-98 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}
func flattenBackupDRManagementServerResource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) map[string]interface{} {
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["type"] = flattenBackupDRManagementServerType(original["type"], d, config)
transformed["networks"] = flattenBackupDRManagementServerNetworks(original["networks"], d, config)
transformed["oauth2ClientId"] = flattenBackupDRManagementServerOauth2ClientId(original["oauth2ClientId"], d, config)
transformed["managementUri"] = flattenBackupDRManagementServerManagementUri(original["managementUri"], d, config)
transformed["name"] = flattenBackupDRManagementServerName(original["name"], d, config)
return transformed
}

func dataSourceGoogleCloudBackupDRServiceRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
project, err := tpgresource.GetProject(d, config)
if err != nil {
return err
}
billingProject := project
url, err := tpgresource.ReplaceVars(d, config, "{{BackupDRBasePath}}projects/{{project}}/locations/{{location}}/managementServers")
if err != nil {
return err
}
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
})
if err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}
resourceResponse := flattenBackupDRManagementServerResourceResp(res["managementServers"], d, config)
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}

if err := d.Set("type", resourceResponse["type"]); err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}
if err := d.Set("networks", resourceResponse["networks"]); err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}
if err := d.Set("oauth2_client_id", resourceResponse["oauth2ClientId"]); err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}
if err := d.Set("management_uri", resourceResponse["managementUri"]); err != nil {
return fmt.Errorf("Error reading ManagementServer: %s", err)
}

id := fmt.Sprintf("%s", resourceResponse["name"])
d.SetId(id)
name := id[strings.LastIndex(id, "/")+1:]
d.Set("name", name)
return nil
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<% autogen_exception -%>
package backupdr_test
<% unless version == 'ga' -%>

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
)

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

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "backupdr-managementserver-basic"),
shuyama1 marked this conversation as resolved.
Show resolved Hide resolved
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleBackupDRManagementServer_basic(context),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceState("data.google_backup_dr_management_server.foo", "google_backup_dr_management_server.foo"),
),
},
},
})
}

func testAccDataSourceGoogleBackupDRManagementServer_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_network" "default" {
name = "vpc-network"
}

resource "google_backup_dr_management_server" "foo" {
location = "us-central1"
name = "management-server-1"
type = "BACKUP_RESTORE"
networks {
network = google_compute_network.default.id
peering_mode = "PRIVATE_SERVICE_ACCESS"
}
}
shuyama1 marked this conversation as resolved.
Show resolved Hide resolved

data "google_backup_dr_management_server" "foo" {
location = "us-central1"
depends_on = [ google_backup_dr_management_server.foo ]
}
`, context)
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
subcategory: "BackupDR Management Server"
description: |-
Get information about a Backupdr Management server.
---

# google\_backup\_dr\_management\_server

Get information about a Google Backup DR Management server.

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.

## Example Usage

```hcl
data google_backup_dr_management_server my-backup-dr-management-server {
location = "us-central1"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Required) The region in which the management server resource belongs.

- - -

## Attributes Reference

See [google_backupdr_management_server](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/backup_dr_management_server) resource for details of the available attributes.