-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yellow Shine <[email protected]>
- Loading branch information
1 parent
565c8dd
commit 7073b8a
Showing
6 changed files
with
165 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
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
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,42 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "zillizcloud_external_id Data Source - zillizcloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# zillizcloud_external_id (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
terraform { | ||
required_providers { | ||
zillizcloud = { | ||
source = "zilliztech/zillizcloud" | ||
} | ||
} | ||
} | ||
provider "zillizcloud" { | ||
byoc_mode = true | ||
} | ||
data "zillizcloud_external_id" "current" { | ||
} | ||
output "external_id" { | ||
value = data.zillizcloud_external_id.current.external_id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `external_id` (String) The external ID. | ||
- `id` (String) The ID of the external ID. |
18 changes: 18 additions & 0 deletions
18
examples/data-sources/zillizcloud_external_id/data-source.tf
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,18 @@ | ||
terraform { | ||
required_providers { | ||
zillizcloud = { | ||
source = "zilliztech/zillizcloud" | ||
} | ||
} | ||
} | ||
|
||
provider "zillizcloud" { | ||
byoc_mode = true | ||
} | ||
|
||
data "zillizcloud_external_id" "current" { | ||
} | ||
|
||
output "external_id" { | ||
value = data.zillizcloud_external_id.current.external_id | ||
} |
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,87 @@ | ||
package byoc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
zilliz "github.com/zilliztech/terraform-provider-zillizcloud/client" | ||
) | ||
|
||
// ExternalIdDataSource defines the data source implementation. | ||
type ExternalIdDataSource struct { | ||
client *zilliz.Client | ||
} | ||
|
||
func NewExternalIdDataSource() datasource.DataSource { | ||
return &ExternalIdDataSource{} | ||
} | ||
|
||
type ExternalIdDataSourceModel struct { | ||
Id types.String `tfsdk:"id"` | ||
ExternalId types.String `tfsdk:"external_id"` | ||
} | ||
|
||
func (d *ExternalIdDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_external_id" | ||
} | ||
|
||
func (d *ExternalIdDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The ID of the external ID.", | ||
Computed: true, | ||
}, | ||
"external_id": schema.StringAttribute{ | ||
MarkdownDescription: "The external ID.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *ExternalIdDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
// Prevent panic if the provider has not been configured. | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*zilliz.Client) | ||
|
||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Data Source Configure Type", | ||
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
func (d *ExternalIdDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var state ExternalIdDataSourceModel | ||
|
||
// Read Terraform configuration data into the model | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
externalId, err := d.client.GetExternalId() | ||
if err != nil { | ||
resp.Diagnostics.AddError("Error getting external ID", err.Error()) | ||
return | ||
} | ||
|
||
state.Id = types.StringValue(externalId) | ||
state.ExternalId = types.StringValue(externalId) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) | ||
} |
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