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

Adding support for terraform private module source for git #7167

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8c41565
initial commit
vishwahiremat Feb 7, 2024
d212a66
adding changes to support private git repo
vishwahiremat Feb 13, 2024
de5399d
refactor
vishwahiremat Feb 13, 2024
ce877cc
adding comments
vishwahiremat Feb 13, 2024
d1a7ab7
Merge branch 'main' into vishwahiremat/private-repo-support
vishwahiremat Feb 13, 2024
3b29b9e
addressing comments
vishwahiremat Feb 15, 2024
70a6bfe
Merge branch 'main' into vishwahiremat/private-repo-support
vishwahiremat Feb 16, 2024
188e3d8
addressing comments
vishwahiremat Feb 16, 2024
e717d11
changing the field name secretstore->secret
vishwahiremat Feb 16, 2024
e2d4936
addressing comments
vishwahiremat Feb 20, 2024
4b6b8b9
adding change to add url config to gitconfig
vishwahiremat Feb 21, 2024
2149aad
addressing comments
vishwahiremat Feb 21, 2024
f66fcc7
adding comments
vishwahiremat Feb 21, 2024
4db184f
adding secret loader
vishwahiremat Feb 21, 2024
ec388f7
addressing comments
vishwahiremat Feb 22, 2024
89c32fa
addressing comments
vishwahiremat Feb 22, 2024
d5cefb8
merge conflicts
vishwahiremat Feb 22, 2024
c3b89df
addressing comments
vishwahiremat Feb 22, 2024
b843bc7
addressing comments
vishwahiremat Feb 23, 2024
6023202
addressing comments
vishwahiremat Feb 23, 2024
7f89d77
adding typespec examples
vishwahiremat Feb 23, 2024
81e5598
adding typespec examples
vishwahiremat Feb 23, 2024
2ada35f
Trigger Build
vishwahiremat Feb 23, 2024
fcdc510
Trigger Build
vishwahiremat Feb 23, 2024
8c178ca
adding error for write file
vishwahiremat Feb 23, 2024
c7091f0
fixing linter error
vishwahiremat Feb 23, 2024
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

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":148},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":166},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":187},"Applications.Core/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":201},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":224},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":261},"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":262}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":268}]},"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":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}]}}}
55 changes: 55 additions & 0 deletions pkg/corerp/api/v20231001preview/environment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v20231001preview

import (
"fmt"
"reflect"
"strings"

v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
Expand Down Expand Up @@ -62,6 +63,7 @@ func (src *EnvironmentResource) ConvertTo() (v1.DataModelInterface, error) {
return nil, err
}
converted.Properties.Compute = *envCompute
converted.Properties.RecipeConfig = toRecipeConfigDatamodel(src.Properties.RecipeConfig)

if src.Properties.Recipes != nil {
envRecipes := make(map[string]map[string]datamodel.EnvironmentRecipeProperties)
Expand Down Expand Up @@ -150,6 +152,7 @@ func (dst *EnvironmentResource) ConvertFrom(src v1.DataModelInterface) error {
}
dst.Properties.Recipes = recipes
}
dst.Properties.RecipeConfig = fromRecipeConfigDatamodel(env.Properties.RecipeConfig)

if env.Properties.Providers != (datamodel.Providers{}) {
dst.Properties.Providers = &Providers{}
Expand Down Expand Up @@ -180,6 +183,58 @@ func (dst *EnvironmentResource) ConvertFrom(src v1.DataModelInterface) error {
return nil
}

func toRecipeConfigDatamodel(config *RecipeConfigProperties) datamodel.RecipeConfigProperties {
if config != nil {
recipeConfig := datamodel.RecipeConfigProperties{}
if config.Terraform != nil {
recipeConfig.Terraform = datamodel.TerraformConfigProperties{}
if config.Terraform.Authentication != nil {
recipeConfig.Terraform.Authentication = datamodel.AuthConfig{}
gitConfig := config.Terraform.Authentication.Git
if gitConfig != nil {
recipeConfig.Terraform.Authentication.Git = datamodel.GitAuthConfig{}
if gitConfig.Pat != nil {
p := map[string]datamodel.SecretConfig{}
for k, v := range gitConfig.Pat {
p[k] = datamodel.SecretConfig{
Secret: to.String(v.Secret),
}
}
recipeConfig.Terraform.Authentication.Git.PAT = p
}
}
}
}
return recipeConfig
}
return datamodel.RecipeConfigProperties{}
}

func fromRecipeConfigDatamodel(config datamodel.RecipeConfigProperties) *RecipeConfigProperties {
if !reflect.DeepEqual(config, datamodel.RecipeConfigProperties{}) {
recipeConfig := &RecipeConfigProperties{}
if !reflect.DeepEqual(config.Terraform, datamodel.TerraformConfigProperties{}) {
kachawla marked this conversation as resolved.
Show resolved Hide resolved
recipeConfig.Terraform = &TerraformConfigProperties{}
if !reflect.DeepEqual(config.Terraform.Authentication, datamodel.AuthConfig{}) {
recipeConfig.Terraform.Authentication = &AuthConfig{}
if !reflect.DeepEqual(config.Terraform.Authentication.Git, datamodel.GitAuthConfig{}) {
recipeConfig.Terraform.Authentication.Git = &GitAuthConfig{}
if config.Terraform.Authentication.Git.PAT != nil {
recipeConfig.Terraform.Authentication.Git.Pat = map[string]*SecretConfig{}
for k, v := range config.Terraform.Authentication.Git.PAT {
recipeConfig.Terraform.Authentication.Git.Pat[k] = &SecretConfig{
Secret: to.Ptr(v.Secret),
}
}
}
}
}
}
return recipeConfig
}
return nil
}

func toEnvironmentComputeDataModel(h EnvironmentComputeClassification) (*rpv1.EnvironmentCompute, error) {
switch v := h.(type) {
case *KubernetesCompute:
Expand Down
21 changes: 21 additions & 0 deletions pkg/corerp/api/v20231001preview/environment_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func TestConvertVersionedToDataModel(t *testing.T) {
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup",
},
},
RecipeConfig: datamodel.RecipeConfigProperties{
Terraform: datamodel.TerraformConfigProperties{
Authentication: datamodel.AuthConfig{
Git: datamodel.GitAuthConfig{},
},
},
},
Recipes: map[string]map[string]datamodel.EnvironmentRecipeProperties{
ds_ctrl.MongoDatabasesResourceType: {
"cosmos-recipe": datamodel.EnvironmentRecipeProperties{
Expand Down Expand Up @@ -117,6 +124,19 @@ func TestConvertVersionedToDataModel(t *testing.T) {
Scope: "/planes/aws/aws/accounts/140313373712/regions/us-west-2",
},
},
RecipeConfig: datamodel.RecipeConfigProperties{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a few different layers and we could run into nil pointer exception easily. We should test it thoroughly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the PAT map from this test, we can see if we run into nil pointer exception above in the original conversion logic.

Terraform: datamodel.TerraformConfigProperties{
Authentication: datamodel.AuthConfig{
Git: datamodel.GitAuthConfig{
PAT: map[string]datamodel.SecretConfig{
"dev.azure.com": {
Secret: "/planes/radius/local/resourcegroups/default/providers/Applications.Core/secretStores/github",
},
},
},
},
},
},
Recipes: map[string]map[string]datamodel.EnvironmentRecipeProperties{
ds_ctrl.MongoDatabasesResourceType: {
"cosmos-recipe": datamodel.EnvironmentRecipeProperties{
Expand Down Expand Up @@ -368,6 +388,7 @@ func TestConvertDataModelToVersioned(t *testing.T) {
if tt.filename == "environmentresourcedatamodel.json" {
require.Equal(t, "Azure/cosmosdb/azurerm", string(*versioned.Properties.Recipes[ds_ctrl.MongoDatabasesResourceType]["terraform-recipe"].GetRecipeProperties().TemplatePath))
require.Equal(t, recipes.TemplateKindTerraform, string(*versioned.Properties.Recipes[ds_ctrl.MongoDatabasesResourceType]["terraform-recipe"].GetRecipeProperties().TemplateKind))
require.Equal(t, "/planes/radius/local/resourcegroups/default/providers/Applications.Core/secretStores/github", string(*versioned.Properties.RecipeConfig.Terraform.Authentication.Git.Pat["dev.azure.com"].Secret))
switch c := recipeDetails.(type) {
case *TerraformRecipeProperties:
require.Equal(t, "1.1.0", string(*c.TemplateVersion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"scope": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup"
}
},
"recipeConfig": {
"terraform": {
"authentication": {
"git": {}
}
}
},
"recipes": {
"Applications.Datastores/mongoDatabases":{
"cosmos-recipe": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
"scope": "/planes/aws/aws/accounts/140313373712/regions/us-west-2"
}
},
"recipeConfig": {
"terraform": {
"authentication": {
"git": {
"pat": {
"dev.azure.com":{
"secret":"/planes/radius/local/resourcegroups/default/providers/Applications.Core/secretStores/github"
}
}
}
}
}
},
"recipes": {
"Applications.Datastores/mongoDatabases":{
"cosmos-recipe": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
"scope": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup"
}
},
"recipeConfig": {
"terraform": {
"authentication": {
"git": {}
}
}
},
"recipes": {
"Applications.Datastores/mongoDatabases":{
"cosmos-recipe": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
"scope": "/planes/aws/aws/accounts/140313373712/regions/us-west-2"
}
},
"recipeConfig": {
"terraform": {
"authentication": {
"git": {
"pat": {
"dev.azure.com":{
"secret":"/planes/radius/local/resourcegroups/default/providers/Applications.Core/secretStores/github"
}
}
}
}
}
},
"recipes": {
"Applications.Datastores/mongoDatabases":{
"cosmos-recipe": {
Expand Down
39 changes: 39 additions & 0 deletions pkg/corerp/api/v20231001preview/zz_generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading