generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from michaelkrupp/main
Implement data source and allow custom request headers
- Loading branch information
Showing
7 changed files
with
383 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
argInitialized = "initialized" | ||
) | ||
|
||
func providerDatasource() *schema.Resource { | ||
return &schema.Resource{ | ||
// This description is used by the documentation generator and the language server. | ||
Description: "Resource for vault operator init", | ||
|
||
ReadContext: providerDatasourceRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
argInitialized: { | ||
Description: "The current initialization state of Vault.", | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func providerDatasourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*apiClient) | ||
|
||
d.SetId(client.url) | ||
|
||
res, err := client.client.Sys().InitStatus() | ||
if err != nil { | ||
logError("failed to read init status from Vault: %v", err) | ||
return diag.FromErr(err) | ||
} | ||
|
||
logDebug("response: %v", res) | ||
|
||
if err := d.Set(argInitialized, res); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diag.Diagnostics{} | ||
} |
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,32 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
var testAccDataSourceInitVar = fmt.Sprintf("data.%[1]s.test", resInit) | ||
var testAccDataSourceInit = fmt.Sprintf(` | ||
provider "%[1]s" { | ||
} | ||
data "%[2]s" "test" { | ||
} | ||
`, provider, resInit) | ||
|
||
func TestAccDataSourceInit(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceInit, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(testAccDataSourceInitVar, argInitialized), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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