Skip to content

Commit

Permalink
Initial work on adding support for the multiple TF Providers
Browse files Browse the repository at this point in the history
Signed-off-by: ytimocin <[email protected]>
  • Loading branch information
ytimocin committed Feb 26, 2024
1 parent c0b50a5 commit 8dab28e
Show file tree
Hide file tree
Showing 35 changed files with 1,053 additions and 361 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":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/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":214},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":237},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":274},"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":275}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":281}]},"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}]}}}
2 changes: 1 addition & 1 deletion hack/bicep-types-radius/src/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"typescript": "^4.6.3",
"yargs": "^17.4.0"
}
}
}
109 changes: 108 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.EnvVariables = 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.EnvVariables = fromRecipeConfigEnvDatamodel(config)

return recipeConfig
}

return nil
}

Expand Down Expand Up @@ -395,3 +406,99 @@ func fromRecipePropertiesClassificationDatamodel(e datamodel.EnvironmentRecipePr
}
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 _, provider := range v {
secrets := map[string]datamodel.RecipeSecret{}
for secretKey, secret := range provider.Secrets {
if secret.Source == nil || secret.Key == nil {
continue
}

secrets[secretKey] = datamodel.RecipeSecret{
Source: *secret.Source,
Key: *secret.Key,
}
}

dm[k] = append(dm[k], datamodel.ProviderConfigProperties{
AdditionalProperties: provider.AdditionalProperties,
Secrets: secrets,
})
}
}

return dm
}

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

providers := map[string][]*ProviderConfigProperties{}

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

for _, provider := range v {
secrets := map[string]*RecipeSecret{}
for secretKey, secret := range provider.Secrets {
secrets[secretKey] = &RecipeSecret{
Source: to.Ptr(secret.Source),
Key: to.Ptr(secret.Key),
}
}

providers[k] = append(providers[k], &ProviderConfigProperties{
AdditionalProperties: provider.AdditionalProperties,
Secrets: secrets,
})
}
}

return providers
}

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

secrets := make(map[string]datamodel.RecipeSecret, len(config.EnvVariables.Secrets))
for k, v := range config.EnvVariables.Secrets {
secrets[k] = datamodel.RecipeSecret{
Source: to.String(v.Source),
Key: to.String(v.Key),
}
}

return datamodel.EnvironmentVariables{
AdditionalProperties: config.EnvVariables.AdditionalProperties,
Secrets: secrets,
}
}

func fromRecipeConfigEnvDatamodel(config datamodel.RecipeConfigProperties) *EnvironmentVariables {
secrets := make(map[string]*RecipeSecret, len(config.EnvVariables.Secrets))
for k, v := range config.EnvVariables.Secrets {
secrets[k] = &RecipeSecret{
Source: to.Ptr(v.Source),
Key: to.Ptr(v.Key),
}
}

return &EnvironmentVariables{
AdditionalProperties: config.EnvVariables.AdditionalProperties,
Secrets: secrets,
}
}
Loading

0 comments on commit 8dab28e

Please sign in to comment.