Skip to content

Commit

Permalink
Update typespec to support all Terraform Recipe Providers and Env (ra…
Browse files Browse the repository at this point in the history
…dius-project#7202)

# Description
* Updated TypeSpec by adding Providers and EnvVariables to Environment
resource (w/o Secrets)
* Updated Data Models by adding Providers and EnvVariables to
Environment resource (w/o Secrets)
* Updated the Environment Conversion logic and its tests
* Updated RecipeConfigProperties

Note: **Secrets** for both **Providers** and **EnvSecrets** will be
added in another PR.

Design doc: radius-project/design-notes#39

## Type of change
- This pull request adds or changes features of Radius and has an
approved issue (issue link required).
Fixes: part of radius-project#6539

Signed-off-by: ytimocin <[email protected]>
  • Loading branch information
ytimocin authored Feb 28, 2024
1 parent db82383 commit 3cc1f92
Show file tree
Hide file tree
Showing 22 changed files with 782 additions and 170 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":154},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":172},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":193},"Applications.Core/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":207},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":230},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":267},"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":268}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":274}]},"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":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/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":211},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":234},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":271},"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":272}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":278}]},"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}]}}}
73 changes: 72 additions & 1 deletion pkg/corerp/api/v20231001preview/environment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const (
// ConvertTo converts from the versioned Environment resource to version-agnostic datamodel.
func (src *EnvironmentResource) ConvertTo() (v1.DataModelInterface, error) {
// Note: SystemData conversion isn't required since this property comes ARM and datastore.

converted := &datamodel.Environment{
BaseResource: v1.BaseResource{
TrackedResource: v1.TrackedResource{
Expand Down Expand Up @@ -204,9 +203,15 @@ func toRecipeConfigDatamodel(config *RecipeConfigProperties) datamodel.RecipeCon
}
}
}

recipeConfig.Terraform.Providers = toRecipeConfigTerraformProvidersDatamodel(config)
}

recipeConfig.Env = toRecipeConfigEnvDatamodel(config)

return recipeConfig
}

return datamodel.RecipeConfigProperties{}
}

Expand All @@ -229,9 +234,15 @@ func fromRecipeConfigDatamodel(config datamodel.RecipeConfigProperties) *RecipeC
}
}
}

recipeConfig.Terraform.Providers = fromRecipeConfigTerraformProvidersDatamodel(config)
}

recipeConfig.Env = fromRecipeConfigEnvDatamodel(config)

return recipeConfig
}

return nil
}

Expand Down Expand Up @@ -393,5 +404,65 @@ func fromRecipePropertiesClassificationDatamodel(e datamodel.EnvironmentRecipePr
PlainHTTP: to.Ptr(e.PlainHTTP),
}
}

return nil
}

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

dm := map[string][]datamodel.ProviderConfigProperties{}
for k, v := range config.Terraform.Providers {
dm[k] = []datamodel.ProviderConfigProperties{}

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

return dm
}

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

providers := map[string][]map[string]any{}
for k, v := range config.Terraform.Providers {
providers[k] = []map[string]any{}
for _, provider := range v {
providers[k] = append(providers[k], provider.AdditionalProperties)
}
}

return providers
}

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

additionalProperties := map[string]string{}
for k, v := range config.Env {
additionalProperties[k] = to.String(v)
}

return datamodel.EnvironmentVariables{
AdditionalProperties: additionalProperties,
}
}

func fromRecipeConfigEnvDatamodel(config datamodel.RecipeConfigProperties) map[string]*string {
env := map[string]*string{}
for k, v := range config.Env.AdditionalProperties {
env[k] = to.Ptr(v)
}

return env
}
Loading

0 comments on commit 3cc1f92

Please sign in to comment.