Skip to content

Commit

Permalink
Add datamodel changes for secret support to Terraform Providers (radi…
Browse files Browse the repository at this point in the history
…us-project#7731)

# Description

Added datamodel updates for secret support to Terraform Providers
configuration. This includes secrets in recipeConfig under specific
Provider configurations and environment variables.
Pls see link to associated [Design
Doc](https://github.com/radius-project/design-notes/pull/47/files)

NOTE: Updates to functional tests are commented till we merge in
corresponding PR in bicep repo :
radius-project/bicep#751

## Type of change
- This pull request fixes a bug in Radius and has an approved issue
(radius-project#6539)

Fixes: radius-project#6539
Signed-off-by: Reshma Abdul Rahim <[email protected]>
  • Loading branch information
lakshmimsft authored and Reshrahim committed Aug 27, 2024
1 parent 7e64704 commit bf11754
Show file tree
Hide file tree
Showing 20 changed files with 656 additions and 65 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/bicep-types-radius/generated/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":58},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":123},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":158},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":176},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":197},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":220},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":257},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":49},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":66},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":84},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":50},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":69},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":88},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":50}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":258}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":264}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":90}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":92}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":94}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":52}]}}}
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":58},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":123},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":161},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":179},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":200},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":223},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":260},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":49},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":66},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":84},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":50},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":69},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":88},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":50}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":261}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":267}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":90}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":92}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":94}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":52}]}}}
56 changes: 50 additions & 6 deletions pkg/corerp/api/v20231001preview/environment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func toRecipeConfigDatamodel(config *RecipeConfigProperties) datamodel.RecipeCon
}

recipeConfig.Env = toRecipeConfigEnvDatamodel(config)
recipeConfig.EnvSecrets = toSecretReferenceDatamodel(config.EnvSecrets)

return recipeConfig
}
Expand Down Expand Up @@ -239,6 +240,7 @@ func fromRecipeConfigDatamodel(config datamodel.RecipeConfigProperties) *RecipeC
}

recipeConfig.Env = fromRecipeConfigEnvDatamodel(config)
recipeConfig.EnvSecrets = fromSecretReferenceDatamodel(config.EnvSecrets)

return recipeConfig
}
Expand Down Expand Up @@ -417,32 +419,74 @@ func toRecipeConfigTerraformProvidersDatamodel(config *RecipeConfigProperties) m
for k, v := range config.Terraform.Providers {
dm[k] = []datamodel.ProviderConfigProperties{}

for _, providerAdditionalProperties := range v {
for _, providerConfigProperties := range v {
dm[k] = append(dm[k], datamodel.ProviderConfigProperties{
AdditionalProperties: providerAdditionalProperties,
AdditionalProperties: providerConfigProperties.AdditionalProperties,
Secrets: toSecretReferenceDatamodel(providerConfigProperties.Secrets),
})
}
}

return dm
}

func fromRecipeConfigTerraformProvidersDatamodel(config datamodel.RecipeConfigProperties) map[string][]map[string]any {
func fromRecipeConfigTerraformProvidersDatamodel(config datamodel.RecipeConfigProperties) map[string][]*ProviderConfigProperties {
if config.Terraform.Providers == nil {
return nil
}

providers := map[string][]map[string]any{}
providers := map[string][]*ProviderConfigProperties{}
for k, v := range config.Terraform.Providers {
providers[k] = []map[string]any{}
providers[k] = []*ProviderConfigProperties{}

for _, provider := range v {
providers[k] = append(providers[k], provider.AdditionalProperties)
providers[k] = append(providers[k], &ProviderConfigProperties{
AdditionalProperties: provider.AdditionalProperties,
Secrets: fromSecretReferenceDatamodel(provider.Secrets),
})
}
}

return providers
}

func toSecretReferenceDatamodel(configSecrets map[string]*SecretReference) map[string]datamodel.SecretReference {
var secrets map[string]datamodel.SecretReference

for secretKey, secretValue := range configSecrets {
if secretValue != nil {
secret := datamodel.SecretReference{
Source: to.String(secretValue.Source),
Key: to.String(secretValue.Key),
}

if secrets == nil {
secrets = map[string]datamodel.SecretReference{}
}
secrets[secretKey] = secret
}
}

return secrets
}

func fromSecretReferenceDatamodel(secrets map[string]datamodel.SecretReference) map[string]*SecretReference {
var converted map[string]*SecretReference

for secretKey, secretValue := range secrets {
if converted == nil {
converted = map[string]*SecretReference{}
}

converted[secretKey] = &SecretReference{
Source: to.Ptr(secretValue.Source),
Key: to.Ptr(secretValue.Key),
}
}

return converted
}

func toRecipeConfigEnvDatamodel(config *RecipeConfigProperties) datamodel.EnvironmentVariables {
if config.Env == nil {
return datamodel.EnvironmentVariables{}
Expand Down
Loading

0 comments on commit bf11754

Please sign in to comment.