Skip to content

Commit

Permalink
rename fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Mar 12, 2024
1 parent fdb34a1 commit 7031d70
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
)

type AutomaticModel struct {
TimeAfterCreation string `tfschema:"time_after_creation"`
TimeBeforeExpiry string `tfschema:"time_before_expiry"`
DurationAfterCreation string `tfschema:"duration_after_creation"`
TimeBeforeExpiry string `tfschema:"time_before_expiry"`
}
type RotationPolicyModel struct {
Automatic []AutomaticModel `tfschema:"automatic"`
Expand All @@ -53,13 +53,13 @@ type KeyVaultManagedHardwareSecurityModuleKeyModel struct {
Curve string `tfschema:"curve"`
E string `tfschema:"e"`
ExpirationDate string `tfschema:"expiration_date"`
KeyOpts []string `tfschema:"key_opts"`
KeyOptions []string `tfschema:"key_options"`
KeySize int `tfschema:"key_size"`
KeyType string `tfschema:"key_type"`
ManagedHsmId string `tfschema:"managed_hsm_id"`
N string `tfschema:"n"`
Name string `tfschema:"name"`
NotBeforeDate string `tfschema:"not_before_date"`
NotUsableBeforeDate string `tfschema:"not_usable_before_date"`
PublicKeyOpenssh string `tfschema:"public_key_openssh"`
PublicKeyPem string `tfschema:"public_key_pem"`
ResourceId string `tfschema:"resource_id"`
Expand Down Expand Up @@ -152,7 +152,7 @@ func (KeyVaultManagedHardwareSecurityModuleKeyResouece) Arguments() map[string]*
ConflictsWith: []string{"curve"},
},

"key_opts": {
"key_options": {
// API Response order not stable
Type: pluginsdk.TypeSet,
Set: pluginsdk.HashString,
Expand Down Expand Up @@ -197,7 +197,7 @@ func (KeyVaultManagedHardwareSecurityModuleKeyResouece) Arguments() map[string]*
ConflictsWith: []string{"key_size"},
},

"not_before_date": {
"not_usable_before_date": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.IsRFC3339Time,
Expand Down Expand Up @@ -234,12 +234,12 @@ func (KeyVaultManagedHardwareSecurityModuleKeyResouece) Arguments() map[string]*
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"time_after_creation": {
"duration_after_creation": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validate.ISO8601Duration,
AtLeastOneOf: []string{
"rotation_policy.0.automatic.0.time_after_creation",
"rotation_policy.0.automatic.0.duration_after_creation",
"rotation_policy.0.automatic.0.time_before_expiry",
},
},
Expand All @@ -248,7 +248,7 @@ func (KeyVaultManagedHardwareSecurityModuleKeyResouece) Arguments() map[string]*
Optional: true,
ValidateFunc: validate.ISO8601Duration,
AtLeastOneOf: []string{
"rotation_policy.0.automatic.0.time_after_creation",
"rotation_policy.0.automatic.0.duration_after_creation",
"rotation_policy.0.automatic.0.time_before_expiry",
},
},
Expand Down Expand Up @@ -385,7 +385,7 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) Create() sdk.ResourceF
parameters.KeySize = utils.Int32(int32(model.KeySize))
}

if v := model.NotBeforeDate; v != "" {
if v := model.NotUsableBeforeDate; v != "" {
notBeforeDate, _ := time.Parse(time.RFC3339, v) // validated by schema
notBeforeUnixTime := date.UnixTime(notBeforeDate)
parameters.KeyAttributes.NotBefore = &notBeforeUnixTime
Expand Down Expand Up @@ -494,7 +494,7 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) Read() sdk.ResourceFun

if key := resp.Key; key != nil {
model.KeyType = string(key.Kty)
model.KeyOpts = pointer.From(key.KeyOps)
model.KeyOptions = pointer.From(key.KeyOps)

model.N = pointer.From(key.N)
model.E = pointer.From(key.N)
Expand All @@ -513,7 +513,7 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) Read() sdk.ResourceFun

if attributes := resp.Attributes; attributes != nil {
if v := attributes.NotBefore; v != nil {
model.NotBeforeDate = time.Time(*v).Format(time.RFC3339)
model.NotUsableBeforeDate = time.Time(*v).Format(time.RFC3339)
}

if v := attributes.Expires; v != nil {
Expand Down Expand Up @@ -629,7 +629,7 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) Update() sdk.ResourceF

parameters := keyvault.KeyUpdateParameters{}

if meta.ResourceData.HasChange("key_opts") {
if meta.ResourceData.HasChange("key_options") {
keyOptions := k.expandManagedHSMKeyOptions(&model)
parameters.KeyOps = keyOptions
}
Expand All @@ -638,11 +638,11 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) Update() sdk.ResourceF
parameters.Tags = expandTags(model.Tags)
}

if meta.ResourceData.HasChanges("not_before_date", "expiration_date") {
if meta.ResourceData.HasChanges("not_usable_before_date", "expiration_date") {
parameters.KeyAttributes = &keyvault.KeyAttributes{
Enabled: pointer.To(true),
}
if v := model.NotBeforeDate; v != "" {
if v := model.NotUsableBeforeDate; v != "" {
notBeforeDate, _ := time.Parse(time.RFC3339, v) // validated by schema
notBeforeUnixTime := date.UnixTime(notBeforeDate)
parameters.KeyAttributes.NotBefore = &notBeforeUnixTime
Expand Down Expand Up @@ -733,7 +733,7 @@ var _ sdk.ResourceWithCustomizeDiff = KeyVaultManagedHardwareSecurityModuleKeyRe
func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) expandManagedHSMKeyOptions(d *KeyVaultManagedHardwareSecurityModuleKeyModel) *[]keyvault.JSONWebKeyOperation {
results := make([]keyvault.JSONWebKeyOperation, 0)

for _, option := range d.KeyOpts {
for _, option := range d.KeyOptions {
results = append(results, keyvault.JSONWebKeyOperation(option))
}

Expand Down Expand Up @@ -763,8 +763,8 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) expandKeyVaultKeyRotat
}
autoRotationRaw := policy.Automatic[0]

if autoRotationRaw.TimeAfterCreation != "" {
lifetimeActionRotate.Trigger.TimeAfterCreate = &autoRotationRaw.TimeAfterCreation
if autoRotationRaw.DurationAfterCreation != "" {
lifetimeActionRotate.Trigger.TimeAfterCreate = &autoRotationRaw.DurationAfterCreation
}

if autoRotationRaw.TimeBeforeExpiry != "" {
Expand Down Expand Up @@ -800,7 +800,7 @@ func (k KeyVaultManagedHardwareSecurityModuleKeyResouece) flattenKeyVaultKeyRota
if action != nil && trigger != nil {
if strings.EqualFold(string(action.Type), string(keyvault.ActionTypeRotate)) {
var autoRotation AutomaticModel
autoRotation.TimeAfterCreation = pointer.From(trigger.TimeAfterCreate)
autoRotation.DurationAfterCreation = pointer.From(trigger.TimeAfterCreate)
autoRotation.TimeBeforeExpiry = pointer.From(trigger.TimeBeforeExpiry)
policy.Automatic = append(policy.Automatic, autoRotation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ resource "azurerm_key_vault_managed_hardware_security_module_key" "test" {
managed_hsm_id = azurerm_key_vault_managed_hardware_security_module.test.id
key_type = "EC-HSM"
key_opts = [
key_options = [
"sign",
"verify",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ The following arguments are supported:

* `key_type` - (Required) Specifies the Key Type to use for this Managed Hardware Security Module Key. Possible values are `EC-HSM`, `RSA-HSM` and `oct-HSM`. Changing this forces a new resource to be created.

* `key_size` - (Optional) Specifies the Size of the RSA key to create in bytes. For example, 1024 or 2048. *Note*: This field is required if `key_type` is `RSA-HSM`. Changing this forces a new resource to be created.
* `key_size` - (Optional) Specifies the Size of the RSA key to create in bytes. For example, `1024` or `2048`. *Note*: This field is required if `key_type` is `RSA-HSM`. Changing this forces a new resource to be created.

* `curve` - (Optional) Specifies the curve to use when creating an `EC` key. Possible values are `P-256`, `P-256K`, `P-384`, and `P-521`. This field will be required in a future release if `key_type` is `EC-HSM`. The API will default to `P-256` if nothing is specified. Changing this forces a new resource to be created.

* `key_opts` - (Required) A list of JSON web key operations. Possible values are `decrypt`, `encrypt`, `import`, `export`, `sign`, `unwrapKey`, `verify` and `wrapKey`. Please note these values are case sensitive.
* `key_options` - (Required) A list of JSON web key operations. Possible values are `decrypt`, `encrypt`, `import`, `export`, `sign`, `unwrapKey`, `verify` and `wrapKey`. Please note these values are case sensitive.

* `not_before_date` - (Optional) Key not usable before the provided UTC datetime (Y-m-d'T'H:M:S'Z').
* `not_usable_before_date` - (Optional) Key not usable before the provided UTC datetime (Y-m-d'T'H:M:S'Z').

* `expiration_date` - (Optional) Expiration UTC datetime (Y-m-d'T'H:M:S'Z').

Expand All @@ -213,7 +213,7 @@ A `rotation_policy` block supports the following:

An `automatic` block supports the following:

* `time_after_creation` - (Optional) Rotate automatically at a duration after create as an [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations).
* `duration_after_creation` - (Optional) Rotate automatically at a duration after create as an [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations).

* `time_before_expiry` - (Optional) Rotate automatically at a duration before expiry as an [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations).

Expand Down

0 comments on commit 7031d70

Please sign in to comment.