Skip to content

Commit

Permalink
fix: Fixed acc failure
Browse files Browse the repository at this point in the history
  • Loading branch information
YanniHu1996 committed May 31, 2023
1 parent ded3b67 commit 4236e10
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bigAnimal_projects Data Source - terraform-provider-biganimal"
page_title: "biganimal_projects Data Source - terraform-provider-biganimal"
subcategory: ""
description: |-
The projects data source shows the BigAnimal Projects.
---

# bigAnimal_projects (Data Source)
# biganimal_projects (Data Source)

The projects data source shows the BigAnimal Projects.

Expand Down Expand Up @@ -36,7 +36,7 @@ output "projects" {

Required:

- `name` (String) Project Name of the project.
- `project_name` (String) Project Name of the project.

Optional:

Expand Down
5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ Credentials can be provided by using the `BA_BEARER_TOKEN` and optionally `BA_AP
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `ba_bearer_token` (String) BigAnimal Bearer Token

### Optional

- `ba_api_uri` (String) BigAnimal API URL
- `ba_bearer_token` (String) BigAnimal Bearer Token
24 changes: 5 additions & 19 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,18 @@ output "project" {

- `project_name` (String) Project Name of the project.

### Optional

- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only

- `cloud_providers` (Set of Object) Enabled Cloud Providers. (see [below for nested schema](#nestedatt--cloud_providers))
- `cloud_providers` (Attributes Set) Enabled Cloud Providers. (see [below for nested schema](#nestedatt--cloud_providers))
- `cluster_count` (Number) User Count of the project.
- `id` (String) The ID of this resource.
- `project_id` (String) Project ID of the project.
- `id` (String) Project ID of the project.
- `project_id` (String, Deprecated) Project ID of the project.
- `user_count` (Number) User Count of the project.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String)
- `delete` (String)
- `update` (String)


<a id="nestedatt--cloud_providers"></a>
### Nested Schema for `cloud_providers`

Read-Only:

- `cloud_provider_id` (String)
- `cloud_provider_name` (String)
- `cloud_provider_id` (String) Cloud Provider ID.
- `cloud_provider_name` (String) Cloud Provider Name.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"log"
)

Expand Down
41 changes: 32 additions & 9 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
schema2 "github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
diagv2 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"os"
)
Expand All @@ -30,6 +31,7 @@ func init() {
// Set descriptions to support markdown syntax, this will be used in document generation
// and the language server.
schema.DescriptionKind = schema.StringMarkdown

}

func New(version string) func() *schema.Provider {
Expand All @@ -38,14 +40,14 @@ func New(version string) func() *schema.Provider {
Schema: map[string]*schema.Schema{
"ba_bearer_token": {
Type: schema.TypeString,
Description: "BigAnimal Bearer Token",
Sensitive: false,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("BA_BEARER_TOKEN", nil),
Optional: true,
},
"ba_api_uri": {
Type: schema.TypeString,
Description: "BigAnimal API URL",
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BA_API_URI", "https://portal.biganimal.com/api/v3"),
},
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -83,6 +85,27 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
// api.BuildAPI(meta).RegionClient()

userAgent := fmt.Sprintf("%s/%s", "terraform-provider-biganimal", version)
diags := diag.Diagnostics{}

if ba_bearer_token == "" {
ba_bearer_token = os.Getenv("BA_BEARER_TOKEN")
}

if ba_bearer_token == "" {
diags = append(diags, diagv2.Diagnostic{
Severity: diagv2.Error,
Summary: "Unable to find ba_nearer_token",
Detail: "ba_nearer_token cannot be an empty string"})
return nil, diags
}

if ba_api_uri == "" {
ba_api_uri = os.Getenv("BA_API_URI")
}
if ba_api_uri == "" {
ba_api_uri = "https://portal.biganimal.com/api/v3"
}

return api.NewAPI(ba_bearer_token, ba_api_uri, userAgent), nil
}
}
Expand All @@ -93,8 +116,8 @@ type bigAnimalProvider struct {

// providerData can be used to store data from the Terraform configuration.
type providerData struct {
BaBearerToken string `tfsdk:"ba_bearer_token"`
BaAPIUri string `tfsdk:"ba_api_uri"`
BaBearerToken *string `tfsdk:"ba_bearer_token"`
BaAPIUri *string `tfsdk:"ba_api_uri"`
}

func NewProvider(version string) func() provider.Provider {
Expand All @@ -121,8 +144,8 @@ func (b bigAnimalProvider) Configure(ctx context.Context, req provider.Configure
}

var token = os.Getenv("BA_BEARER_TOKEN")
if data.BaBearerToken != "" {
token = data.BaBearerToken
if data.BaBearerToken != nil {
token = *data.BaBearerToken
}

if token == "" {
Expand All @@ -137,8 +160,8 @@ func (b bigAnimalProvider) Configure(ctx context.Context, req provider.Configure
if os.Getenv("BA_API_URI") != "" {
host = os.Getenv("BA_API_URI")
}
if data.BaAPIUri != "" {
host = data.BaAPIUri
if data.BaAPIUri != nil {
host = *data.BaAPIUri
}

userAgent := fmt.Sprintf("%s/%s", "terraform-provider-biganimal", b.version)
Expand Down
Loading

0 comments on commit 4236e10

Please sign in to comment.