Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: override vra configuration cache #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ provider/**/schema-embed.json
**/version.txt
**/nuget
**/dist

__debug_bin
.vscode/*
.dev/*
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

The VRA Resource Provider lets you manage [VRA](https://www.vmware.com/products/vrealize-automation.html) resources.

## override vra configuration cache

The following configurations are overridable via env vars:

- access_token (access token for API operations) with env var VMWARE_VRA_ACCESS_TOKEN
- refresh_token (refresh token for API operations) with env var VMWARE_VRA_REFRESH_TOKEN
- url (base url for API operations) with env var VMWARE_VRA_URL
- reauthorizeTimeout (timeout for how often to reauthorize the access token) with env var VMWARE_VRA_REAUTHORIZE_TIMEOUT

## Installing

This package is available for several languages/platforms:
Expand Down
2 changes: 1 addition & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20220824175045-450992f2f5b9

require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0
github.com/pulumi/pulumi-terraform-bridge/v3 v3.28.1
github.com/vmware/terraform-provider-vra v0.5.3
)
Expand Down Expand Up @@ -122,7 +123,6 @@ require (
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/vault/api v1.1.1 // indirect
Expand Down
39 changes: 37 additions & 2 deletions provider/resources.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2016-2018, Pulumi Corporation.
//
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -16,11 +18,14 @@ package vra

import (
"fmt"
"os"
"path/filepath"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumiverse/pulumi-vra/provider/pkg/version"

shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/vmware/terraform-provider-vra/vra"
)

Expand All @@ -34,7 +39,37 @@ const (
// Provider returns additional overlaid schema and metadata associated with the provider..
func Provider() tfbridge.ProviderInfo {
// Instantiate the Terraform provider
p := shimv2.NewProvider(vra.Provider())
vraP := vra.Provider()
cf := vraP.ConfigureFunc
vraP.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
// override vra configuration cache, cache includes
// - access_token (access token for API operations) with env var VMWARE_VRA_ACCESS_TOKEN
// - refresh_token (refresh token for API operations) with env var VMWARE_VRA_REFRESH_TOKEN
// - url (base url for API operations) with env var VMWARE_VRA_URL
// - reauthorizeTimeout (timeout for how often to reauthorize the access token) with env var VMWARE_VRA_REAUTHORIZE_TIMEOUT
envAccessToken := os.Getenv("VMWARE_VRA_ACCESS_TOKEN")
if len(envAccessToken) != 0 {
d.Set("access_token", envAccessToken)
}

envRefreshToken := os.Getenv("VMWARE_VRA_REFRESH_TOKEN")
if len(envRefreshToken) != 0 {
d.Set("refresh_token", envRefreshToken)
}

envURL := os.Getenv("VMWARE_VRA_URL")
if len(envURL) != 0 {
d.Set("url", envURL)
}

envReauthorizeTimeout := os.Getenv("VMWARE_VRA_REAUTHORIZE_TIMEOUT")
if len(envReauthorizeTimeout) != 0 {
d.Set("reauthorize_timeout", envReauthorizeTimeout)
}

return cf(d)
}
p := shimv2.NewProvider(vraP)

// Create a Pulumi provider mapping
prov := tfbridge.ProviderInfo{
Expand Down
37 changes: 20 additions & 17 deletions sdk/go/vra/blockdevice/blockDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 38 additions & 30 deletions sdk/go/vra/blockdevice/getBlockDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdk/go/vra/blockdevice/getSnapshots.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading