-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate azure_dev_ops_project from SDKv2 to Framework
- Loading branch information
Showing
6 changed files
with
121 additions
and
70 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
pkg/framework/objects/azure_dev_ops_project/data_source.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,75 @@ | ||
package azure_dev_ops_project | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &azureDevOpsProjectDataSource{} | ||
_ datasource.DataSourceWithConfigure = &azureDevOpsProjectDataSource{} | ||
) | ||
|
||
func AzureDevOpsProjectDataSource() datasource.DataSource { | ||
return &azureDevOpsProjectDataSource{} | ||
} | ||
|
||
type azureDevOpsProjectDataSource struct { | ||
client *dbt_cloud.Client | ||
} | ||
|
||
func (d *azureDevOpsProjectDataSource) Metadata( | ||
_ context.Context, | ||
req datasource.MetadataRequest, | ||
resp *datasource.MetadataResponse, | ||
) { | ||
resp.TypeName = req.ProviderTypeName + "azure_dev_ops_project" | ||
} | ||
|
||
func (d *azureDevOpsProjectDataSource) Read( | ||
ctx context.Context, | ||
req datasource.ReadRequest, | ||
resp *datasource.ReadResponse, | ||
) { | ||
var state AzureDevOpsProjectDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) | ||
|
||
projectName := state.Name.ValueString() | ||
|
||
azureDevOpsProject, err := d.client.GetAzureDevOpsProject(projectName) | ||
|
||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
fmt.Sprintf("Did not find Azure DevOps Project with name: %s", state.Name), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
state.Name = types.StringValue(azureDevOpsProject.Name) | ||
state.ID = types.StringValue(azureDevOpsProject.ID) | ||
state.URL = types.StringValue(azureDevOpsProject.URL) | ||
|
||
diags := resp.State.Set(ctx, &state) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
|
||
func (d *azureDevOpsProjectDataSource) Configure( | ||
_ context.Context, | ||
req datasource.ConfigureRequest, | ||
_ *datasource.ConfigureResponse, | ||
) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*dbt_cloud.Client) | ||
} |
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,9 @@ | ||
package azure_dev_ops_project | ||
|
||
import "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
type AzureDevOpsProjectDataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
URL types.String `tfsdk:"url"` | ||
} |
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,35 @@ | ||
package azure_dev_ops_project | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
) | ||
|
||
func (r *azureDevOpsProjectDataSource) Schema( | ||
_ context.Context, | ||
_ datasource.SchemaRequest, | ||
resp *datasource.SchemaResponse, | ||
) { | ||
resp.Schema = schema.Schema{ | ||
Description: `Use this data source to retrieve the ID of an Azure Dev Ops project | ||
based on its name. | ||
This data source requires connecting with a user token and doesn't work with a service token.`, | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Required: true, | ||
Description: "The internal Azure Dev Ops ID of the ADO Project", | ||
}, | ||
"name": schema.StringAttribute{ | ||
Required: true, | ||
Description: "The name of the ADO project", | ||
}, | ||
"url": schema.StringAttribute{ | ||
Required: true, | ||
Description: "The URL of the ADO project", | ||
}, | ||
}, | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.