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: add output ids for vault and secrets #76

Merged
merged 1 commit into from
Jul 26, 2022
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
9 changes: 9 additions & 0 deletions docs/resources/vault.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ resource "multy_vault" "v" {

### Read-Only

- `azure` (Object) Azure-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--azure))
- `id` (String) The ID of this resource.
- `resource_group_id` (String)

Expand All @@ -46,3 +47,11 @@ Optional:
- `project` (String) The project to use for this resource.


<a id="nestedatt--azure"></a>
### Nested Schema for `azure`

Read-Only:

- `key_vault_id` (String)


26 changes: 26 additions & 0 deletions docs/resources/vault_access_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ resource "multy_vault_access_policy" "kv_ap" {

### Read-Only

- `aws` (Object) AWS-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--aws))
- `azure` (Object) Azure-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--azure))
- `gcp` (Object) GCP-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--gcp))
- `id` (String) The ID of this resource.

<a id="nestedatt--aws"></a>
### Nested Schema for `aws`

Read-Only:

- `iam_policy_arn` (String)


<a id="nestedatt--azure"></a>
### Nested Schema for `azure`

Read-Only:

- `key_vault_access_policy_id` (String)


<a id="nestedatt--gcp"></a>
### Nested Schema for `gcp`

Read-Only:

- `secret_manager_secret_iam_membership_ids` (List of String)


27 changes: 27 additions & 0 deletions docs/resources/vault_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ resource "multy_vault_secret" s {

### Read-Only

- `aws` (Object) AWS-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--aws))
- `azure` (Object) Azure-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--azure))
- `gcp` (Object) GCP-specific ids of the underlying generated resources (see [below for nested schema](#nestedatt--gcp))
- `id` (String) The ID of this resource.

<a id="nestedatt--aws"></a>
### Nested Schema for `aws`

Read-Only:

- `ssm_parameter_arn` (String)


<a id="nestedatt--azure"></a>
### Nested Schema for `azure`

Read-Only:

- `key_vault_secret_id` (String)


<a id="nestedatt--gcp"></a>
### Nested Schema for `gcp`

Read-Only:

- `secret_manager_secret_id` (String)
- `secret_manager_secret_version_id` (String)


2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
google.golang.org/protobuf v1.28.0
)

//replace github.com/multycloud/multy v0.1.53 => ../multy
//replace github.com/multycloud/multy v0.1.54 => ../multy

require (
github.com/Azure/azure-sdk-for-go v59.2.0+incompatible // indirect
Expand Down
16 changes: 16 additions & 0 deletions multy/resource_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (

type ResourceVaultType struct{}

var vaultAzureOutputs = map[string]attr.Type{
"key_vault_id": types.StringType,
}

func (r ResourceVaultType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
MarkdownDescription: "Provides Multy Vault resource",
Expand Down Expand Up @@ -52,6 +56,11 @@ func (r ResourceVaultType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diag
Optional: true,
Computed: true,
},
"azure": {
Description: "Azure-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultAzureOutputs},
Computed: true,
},
"cloud": common.CloudsSchema,
"location": common.LocationSchema,
},
Expand Down Expand Up @@ -114,6 +123,7 @@ type Vault struct {
ResourceGroupId types.String `tfsdk:"resource_group_id"`

GcpOverridesObject types.Object `tfsdk:"gcp_overrides"`
AzureOutputs types.Object `tfsdk:"azure"`
}

func convertToVault(res *resourcespb.VaultResource) Vault {
Expand All @@ -124,6 +134,12 @@ func convertToVault(res *resourcespb.VaultResource) Vault {
Location: mtypes.LocationType.NewVal(res.CommonParameters.Location),
ResourceGroupId: types.String{Value: res.CommonParameters.ResourceGroupId},
GcpOverridesObject: convertToVaultGcpOverrides(res.GcpOverride).GcpOverridesToObj(),
AzureOutputs: common.OptionallyObj(res.AzureOutputs, types.Object{
Attrs: map[string]attr.Value{
"key_vault_id": common.DefaultToNull[types.String](res.GetAzureOutputs().GetKeyVaultId()),
},
AttrTypes: vaultAzureOutputs,
}),
}
}

Expand Down
58 changes: 54 additions & 4 deletions multy/resource_vault_access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@ package multy
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/multycloud/multy/api/proto/resourcespb"
"terraform-provider-multy/multy/common"
"terraform-provider-multy/multy/mtypes"
"terraform-provider-multy/multy/validators"
)

type ResourceVaultAccessPolicyType struct{}

var vaultAccessPolicyAwsOutputs = map[string]attr.Type{
"iam_policy_arn": types.StringType,
}

var vaultAccessPolicyAzureOutputs = map[string]attr.Type{
"key_vault_access_policy_id": types.StringType,
}

var vaultAccessPolicyGcpOutputs = map[string]attr.Type{
"secret_manager_secret_iam_membership_ids": types.ListType{ElemType: types.StringType},
}

func (r ResourceVaultAccessPolicyType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
MarkdownDescription: "Provides Multy Object Storage resource",
Expand Down Expand Up @@ -40,6 +54,21 @@ func (r ResourceVaultAccessPolicyType) GetSchema(_ context.Context) (tfsdk.Schem
Required: true,
Validators: []tfsdk.AttributeValidator{validators.NewValidator(mtypes.VaultAclType)},
},
"aws": {
Description: "AWS-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultAccessPolicyAwsOutputs},
Computed: true,
},
"azure": {
Description: "Azure-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultAccessPolicyAzureOutputs},
Computed: true,
},
"gcp": {
Description: "GCP-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultAccessPolicyGcpOutputs},
Computed: true,
},
},
}, nil
}
Expand Down Expand Up @@ -93,10 +122,13 @@ func deleteVaultAccessPolicy(ctx context.Context, p Provider, state VaultAccessP
}

type VaultAccessPolicy struct {
Id types.String `tfsdk:"id"`
VaultId types.String `tfsdk:"vault_id"`
Identity types.String `tfsdk:"identity"`
Access mtypes.EnumValue[resourcespb.VaultAccess_Enum] `tfsdk:"access"`
Id types.String `tfsdk:"id"`
VaultId types.String `tfsdk:"vault_id"`
Identity types.String `tfsdk:"identity"`
Access mtypes.EnumValue[resourcespb.VaultAccess_Enum] `tfsdk:"access"`
AwsOutputs types.Object `tfsdk:"aws"`
AzureOutputs types.Object `tfsdk:"azure"`
GcpOutputs types.Object `tfsdk:"gcp"`
}

func convertToVaultAccessPolicy(res *resourcespb.VaultAccessPolicyResource) VaultAccessPolicy {
Expand All @@ -105,6 +137,24 @@ func convertToVaultAccessPolicy(res *resourcespb.VaultAccessPolicyResource) Vaul
VaultId: types.String{Value: res.VaultId},
Identity: types.String{Value: res.Identity},
Access: mtypes.VaultAclType.NewVal(res.Access),
AwsOutputs: common.OptionallyObj(res.AwsOutputs, types.Object{
Attrs: map[string]attr.Value{
"iam_policy_arn": common.DefaultToNull[types.String](res.GetAwsOutputs().GetIamPolicyArn()),
},
AttrTypes: vaultAccessPolicyAwsOutputs,
}),
AzureOutputs: common.OptionallyObj(res.AzureOutputs, types.Object{
Attrs: map[string]attr.Value{
"key_vault_access_policy_id": common.DefaultToNull[types.String](res.GetAzureOutputs().GetKeyVaultAccessPolicyId()),
},
AttrTypes: vaultAccessPolicyAzureOutputs,
}),
GcpOutputs: common.OptionallyObj(res.GcpOutputs, types.Object{
Attrs: map[string]attr.Value{
"secret_manager_secret_iam_membership_ids": common.TypesStringListToListType(res.GetGcpOutputs().GetSecretManagerSecretIamMembershipId()),
},
AttrTypes: vaultAccessPolicyGcpOutputs,
}),
}
}

Expand Down
60 changes: 56 additions & 4 deletions multy/resource_vault_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ package multy

import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/multycloud/multy/api/proto/resourcespb"
"terraform-provider-multy/multy/common"
)

type ResourceVaultSecretType struct{}

var vaultSecretAwsOutputs = map[string]attr.Type{
"ssm_parameter_arn": types.StringType,
}

var vaultSecretAzureOutputs = map[string]attr.Type{
"key_vault_secret_id": types.StringType,
}

var vaultSecretGcpOutputs = map[string]attr.Type{
"secret_manager_secret_id": types.StringType,
"secret_manager_secret_version_id": types.StringType,
}

func (r ResourceVaultSecretType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
MarkdownDescription: "Provides Multy Object Storage resource",
Expand All @@ -36,6 +51,21 @@ func (r ResourceVaultSecretType) GetSchema(_ context.Context) (tfsdk.Schema, dia
Required: true,
PlanModifiers: []tfsdk.AttributePlanModifier{tfsdk.RequiresReplace()},
},
"aws": {
Description: "AWS-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultSecretAwsOutputs},
Computed: true,
},
"azure": {
Description: "Azure-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultSecretAzureOutputs},
Computed: true,
},
"gcp": {
Description: "GCP-specific ids of the underlying generated resources",
Type: types.ObjectType{AttrTypes: vaultSecretGcpOutputs},
Computed: true,
},
},
}, nil
}
Expand Down Expand Up @@ -89,10 +119,13 @@ func deleteVaultSecret(ctx context.Context, p Provider, state VaultSecret) error
}

type VaultSecret struct {
Id types.String `tfsdk:"id"`
VaultId types.String `tfsdk:"vault_id"`
Name types.String `tfsdk:"name"`
Value types.String `tfsdk:"value"`
Id types.String `tfsdk:"id"`
VaultId types.String `tfsdk:"vault_id"`
Name types.String `tfsdk:"name"`
Value types.String `tfsdk:"value"`
AwsOutputs types.Object `tfsdk:"aws"`
AzureOutputs types.Object `tfsdk:"azure"`
GcpOutputs types.Object `tfsdk:"gcp"`
}

func convertToVaultSecret(res *resourcespb.VaultSecretResource) VaultSecret {
Expand All @@ -101,6 +134,25 @@ func convertToVaultSecret(res *resourcespb.VaultSecretResource) VaultSecret {
VaultId: types.String{Value: res.VaultId},
Name: types.String{Value: res.Name},
Value: types.String{Value: res.Value},
AwsOutputs: common.OptionallyObj(res.AwsOutputs, types.Object{
Attrs: map[string]attr.Value{
"ssm_parameter_arn": common.DefaultToNull[types.String](res.GetAwsOutputs().GetSsmParameterArn()),
},
AttrTypes: vaultSecretAwsOutputs,
}),
AzureOutputs: common.OptionallyObj(res.AzureOutputs, types.Object{
Attrs: map[string]attr.Value{
"key_vault_secret_id": common.DefaultToNull[types.String](res.GetAzureOutputs().GetKeyVaultSecretId()),
},
AttrTypes: vaultSecretAzureOutputs,
}),
GcpOutputs: common.OptionallyObj(res.GcpOutputs, types.Object{
Attrs: map[string]attr.Value{
"secret_manager_secret_id": common.DefaultToNull[types.String](res.GetGcpOutputs().GetSecretManagerSecretId()),
"secret_manager_secret_version_id": common.DefaultToNull[types.String](res.GetGcpOutputs().GetSecretManagerSecretVersionId()),
},
AttrTypes: vaultSecretGcpOutputs,
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/resources/vault_secret/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable cloud {
type = string
default = "aws"
default = "gcp"
}

resource multy_vault v {
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/vault_secret/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ terraform {
provider "multy" {
api_key = "secret-1"
server_endpoint = "localhost:8000"
aws = {}
azure = {}
gcp = { project = "multy-project" }
}