Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
terraform provider: terraform_random_number ephemeral resource type
Similar to terraform_data, this is really just here to use as a placeholder when one needs an ephemeral resource for some reason but doesn't need any specific one. This might get removed before the ephemeral_values experiment gets stabilized. For now it's here to use as an initial testing vehicle since we don't have any mechanism for offering experimental features in the provider plugin protocol, whereas this provider is not a plugin.
- Loading branch information
1 parent
e1bf50a
commit 1d7f970
Showing
3 changed files
with
76 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package terraform | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/zclconf/go-cty/cty" | ||
|
||
"github.com/hashicorp/terraform/internal/configs/configschema" | ||
"github.com/hashicorp/terraform/internal/providers" | ||
) | ||
|
||
func ephemeralRandomNumberSchema() providers.Schema { | ||
return providers.Schema{ | ||
Block: &configschema.Block{ | ||
Attributes: map[string]*configschema.Attribute{ | ||
"value": {Type: cty.String, Computed: true}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func openEphemeralRandomNumber(req providers.OpenEphemeralRequest) providers.OpenEphemeralResponse { | ||
result := rand.NormFloat64() | ||
return providers.OpenEphemeralResponse{ | ||
Result: cty.ObjectVal(map[string]cty.Value{ | ||
"value": cty.NumberFloatVal(result), | ||
}), | ||
} | ||
} | ||
|
||
func renewEphemeralRandomNumber(req providers.RenewEphemeralRequest) providers.RenewEphemeralResponse { | ||
// This resource type does not need renewing, but if we get asked to do | ||
// it for some reason then we'll just say it succeeded. | ||
return providers.RenewEphemeralResponse{} | ||
} | ||
|
||
func closeEphemeralRandomNumber(req providers.CloseEphemeralRequest) providers.CloseEphemeralResponse { | ||
// This resource type does not need closing because it isn't really | ||
// backed by any long-lived object, so we'll just say that closing it | ||
// succeeded even though we aren't really doing anything. | ||
return providers.CloseEphemeralResponse{} | ||
} |
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