-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[upstream:9b9aa20fc8ac98a3fe9ac350b6c108822fb435d9] Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
4b55213
commit 412608b
Showing
5 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
`google_vmwareengine_vcenter_credentials` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
google/services/vmwareengine/data_source_google_vmwareengine_vcenter_credentials.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package vmwareengine | ||
|
||
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" | ||
) | ||
|
||
func DataSourceVmwareengineVcenterCredentials() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceVmwareengineVcenterCredentialsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"parent": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `The resource name of the private cloud which contains vcenter. | ||
Resource names are schemeless URIs that follow the conventions in https://cloud.google.com/apis/design/resource_names. | ||
For example: projects/my-project/locations/us-west1-a/privateClouds/my-cloud`, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Initial username.`, | ||
}, | ||
"password": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Initial password.`, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVmwareengineVcenterCredentialsRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}{{parent}}:showVcenterCredentials") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
billingProject := "" | ||
|
||
// err == nil indicates that the billing_project value was found | ||
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, | ||
ErrorAbortPredicates: []transport_tpg.RetryErrorPredicateFunc{transport_tpg.Is429QuotaError}, | ||
}) | ||
if err != nil { | ||
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("VmwareengineVcenterCredentials %q", d.Id())) | ||
} | ||
|
||
if err := d.Set("username", flattenVmwareengineVcenterCredentailsUsername(res["username"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading VcenterCredentails: %s", err) | ||
} | ||
if err := d.Set("password", flattenVmwareengineVcenterCredentailsPassword(res["password"], d, config)); err != nil { | ||
return fmt.Errorf("Error reading VcenterCredentails: %s", err) | ||
} | ||
|
||
id, err := tpgresource.ReplaceVars(d, config, "{{parent}}:vcenter-credentials") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return nil | ||
} | ||
|
||
func flattenVmwareengineVcenterCredentailsUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} | ||
|
||
func flattenVmwareengineVcenterCredentailsPassword(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
website/docs/d/vmwareengine_vcenter_credentials.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
subcategory: "Cloud VMware Engine" | ||
description: |- | ||
Get Vcenter Credentials of a Private Cloud. | ||
--- | ||
|
||
# google\_vmwareengine\_vcenter_credentials | ||
|
||
Use this data source to get Vcenter credentials for a Private Cloud. | ||
|
||
To get more information about private cloud Vcenter credentials, see: | ||
* [API documentation](https://cloud.google.com/vmware-engine/docs/reference/rest/v1/projects.locations.privateClouds/showVcenterCredentials) | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_vmwareengine_vcenter_credentials" "ds" { | ||
parent = "projects/my-project/locations/us-west1-a/privateClouds/my-cloud" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `parent` - (Required) The resource name of the private cloud which contains the Vcenter. | ||
|
||
## Attributes Reference | ||
|
||
In addition to the arguments listed above, the following computed attributes are exported: | ||
|
||
* `username` - The username of the Vcenter Credential. | ||
* `password` - The password of the Vcenter Credential. |