generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [CDS-98117]: Onboard provider APIS to terraform (#1091)
* feat: [CDS-98117]: Onboard provider APIS to terraform * feat: [CDS-98117]: Onboard provider APIS to terraform * feat: [CDS-98117]: Onboard provider APIS to terraform * feat: [CDS-98117]: Onboard provider APIS to terraform * feat: [CDS-98117]: Update go-sdk version
- Loading branch information
1 parent
e5d6bf2
commit 51eb950
Showing
7 changed files
with
490 additions
and
3 deletions.
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
47 changes: 47 additions & 0 deletions
47
internal/service/platform/provider/data_source_provider.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,47 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/harness/terraform-provider-harness/helpers" | ||
"github.com/harness/terraform-provider-harness/internal" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceProvider() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Description: "Data source for Harness Provider.", | ||
|
||
ReadContext: dataSourceProviderRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"identifier": { | ||
Description: "The identifier of the provider entity.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
return resource | ||
} | ||
|
||
func dataSourceProviderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) | ||
identifier := d.Get("identifier").(string) | ||
|
||
resp, httpResp, err := c.ProviderApi.GetProvider(ctx, identifier, c.AccountId) | ||
if err != nil { | ||
return helpers.HandleApiError(err, d, httpResp) | ||
} | ||
|
||
if resp.Data == nil { | ||
d.SetId("") | ||
d.MarkNewResource() | ||
return nil | ||
} | ||
|
||
readProvider(d, resp.Data) | ||
|
||
return nil | ||
} |
51 changes: 51 additions & 0 deletions
51
internal/service/platform/provider/data_source_provider_test.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,51 @@ | ||
package provider_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/harness/harness-go-sdk/harness/utils" | ||
"github.com/harness/terraform-provider-harness/internal/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestDataSourceProvider(t *testing.T) { | ||
|
||
id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(6)) | ||
name := id | ||
resourceName := "data.harness_platform_provider.test" | ||
|
||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.TestAccPreCheck(t) }, | ||
ProviderFactories: acctest.ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceProvider(id, name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "identifier", id), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceProvider(id string, name string) string { | ||
return fmt.Sprintf(` | ||
resource "harness_platform_provider" "test" { | ||
identifier = "%[1]s" | ||
name = "%[2]s" | ||
spec { | ||
type = "BITBUCKET_SERVER" | ||
domain = "https://example.com" | ||
secret_manager_ref = "secret-ref" | ||
delegate_selectors = ["delegate-1", "delegate-2"] | ||
client_id = "client-id" | ||
client_secret_ref = "client-secret-ref" | ||
} | ||
} | ||
data "harness_platform_provider" "test" { | ||
identifier = harness_platform_provider.test.identifier | ||
} | ||
`, id, name) | ||
} |
Oops, something went wrong.