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

Add logic to build configuration for multiple Terraform providers support #7189

Merged

Conversation

lakshmimsft
Copy link
Contributor

@lakshmimsft lakshmimsft commented Feb 22, 2024

Description

Adding logic to build configuration for multiple Terraform provider support. This is constructed from a combination of environment level recipe configuration located under RecipeConfig/Terraform/Providers section and the provider configurations registered with UCP. The environment level recipe configuration for providers takes precedence over UCP provider configurations.
link to PR for design doc

The design document describes a SecretReference type and ability to fetch data from secrets and populate Provider Configuration. This will be implemented in subsequent PRs.

Type of change

Fixes: Part of #6539

@lakshmimsft lakshmimsft changed the title Add logic to build/save config for multiple Terraform Providers <DO NOT REVIEW> Add logic to build/save config for multiple Terraform providers <DO NOT REVIEW> Feb 22, 2024
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch 2 times, most recently from da01510 to 725f211 Compare February 23, 2024 17:45
@lakshmimsft lakshmimsft marked this pull request as ready for review February 23, 2024 18:20
@lakshmimsft lakshmimsft requested review from a team as code owners February 23, 2024 18:20
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch from 725f211 to 12e1e49 Compare February 23, 2024 18:34
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/providers/types.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kachawla kachawla left a comment

Choose a reason for hiding this comment

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

Were you able to test these changes end to end locally?

Also, can you rebase with main since some of the code in this pr is duplicate of c0b50a5

pkg/corerp/datamodel/environment.go Outdated Show resolved Hide resolved
pkg/corerp/datamodel/environment.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config_test.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config_test.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/config_test.go Outdated Show resolved Hide resolved
@lakshmimsft lakshmimsft marked this pull request as draft February 25, 2024 21:56
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch 5 times, most recently from aa89820 to a01464d Compare February 26, 2024 08:41
@lakshmimsft lakshmimsft marked this pull request as ready for review February 26, 2024 18:20
Copy link
Contributor

@kachawla kachawla left a comment

Choose a reason for hiding this comment

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

PR title and description are out of date. Please update them. Also, it is good practice to write the description in a way that anyone can understand what the PR is about, think about someone looking at the commit in the future to understand what this change is, why it was etc. Same feedback for #7192

@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch from a01464d to bfc7466 Compare February 26, 2024 20:32
@lakshmimsft lakshmimsft changed the title Add logic to build/save config for multiple Terraform providers <DO NOT REVIEW> Add logic to build/save configuration for multiple Terraform providers support <DO NOT REVIEW> Feb 26, 2024
@lakshmimsft lakshmimsft changed the title Add logic to build/save configuration for multiple Terraform providers support <DO NOT REVIEW> Add logic to build configuration for multiple Terraform providers support <DO NOT REVIEW> Feb 26, 2024
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch 3 times, most recently from f3dde3e to 0a7d6a8 Compare February 26, 2024 22:45
@lakshmimsft lakshmimsft changed the title Add logic to build configuration for multiple Terraform providers support <DO NOT REVIEW> Add logic to build configuration for multiple Terraform providers support Feb 27, 2024
@kachawla kachawla requested a review from ytimocin February 27, 2024 02:27
Copy link
Contributor

@kachawla kachawla left a comment

Choose a reason for hiding this comment

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

This PR doesn't implement handling secrets, can you please call that out in the description?

Also, the typespec PR contains secrets, should that be split out into a separate PR given that backend isn't implemented?

Copy link
Contributor

@kachawla kachawla left a comment

Choose a reason for hiding this comment

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

Looks good overall. Couple of comments

Comment on lines 60 to 64
for _, configDetails := range config {
configList = append(configList, configDetails.AdditionalProperties)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check if AdditionalProperties is non-empty/non-nil?

Suggested change
for _, configDetails := range config {
configList = append(configList, configDetails.AdditionalProperties)
}
for _, configDetails := range config {
if configDetails.AdditionalProperties != nil && len(configDetails.AdditionalProperties) > 0 {
configList = append(configList, configDetails.AdditionalProperties)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kachawla this is allowed here to accomodate 'default provider configuration' where no details are input. Tests are added for this case both in types_test.go and here: https://github.com/radius-project/radius/pull/7189/files#diff-c5c89506f1ba2fe9bd8ecf4eedc856e93714c251c295c32a15d875f5924df3bdR515-R530
a example resulting main.tf.json is here: pkg/recipes/terraform/config/testdata/providers-envrecipedefaultconfig.tf.json
I did a manual test to see provider configuration load successfully.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, thank you. During manual testing, in addition to checking that the config was loaded successfully, could you also confirm that terraform apply runs successfully for this scenario?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, can you please expand on "default provider configuration"? I'm not sure what we mean by this. Feel free to point me to the right section in the design if it is captured in the doc already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, confirming, terraform apply runs successfully for this scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to populate empty config though?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no concept of default empty configuration afaik, let's add this nil check unless there is a terraform documentation that mentions otherwise.

Copy link
Contributor Author

@lakshmimsft lakshmimsft Feb 28, 2024

Choose a reason for hiding this comment

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

added nil check.
per documentation , https://developer.hashicorp.com/terraform/language/providers/configuration#default-provider-configurations
default configuration is a block without alias argument. and if we provide all configurations with an alias, it picks the "implied empty configuration" as the default configuration.
The null input does not seem to be documented but seems to be handled by terraform without throwing errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

From the doc - "Terraform assumes an empty default configuration for any provider that is not explicitly configured." - this is already handled by Terraform. By adding empty configuration here, we are overriding any non-empty config that a user might have in their module. Unless there is a strong use case for passing empty config, I wouldn't recommend doing this.

pkg/recipes/terraform/config/providers/types.go Outdated Show resolved Hide resolved
pkg/recipes/terraform/config/providers/types.go Outdated Show resolved Hide resolved
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch 2 times, most recently from ea95250 to 3365e5c Compare February 27, 2024 18:19
@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch 3 times, most recently from 20cdcb1 to 30a4a2e Compare February 28, 2024 01:30
@radius-functional-tests
Copy link

radius-functional-tests bot commented Feb 28, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository lakshmimsft/radius-mainfork
Commit ref 30a4a2e
Unique ID 969a31487a
Image tag pr-969a31487a
Click here to see the list of tools in the current test run
  • gotestsum 1.10.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.1.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/functional/shared/recipes/<name>:pr-969a31487a
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-969a31487a
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-969a31487a
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-969a31487a
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting msgrp functional tests...
⌛ Starting ucp functional tests...
⌛ Starting shared functional tests...
⌛ Starting daprrp functional tests...
⌛ Starting samples functional tests...
⌛ Starting datastoresrp functional tests...
⌛ Starting kubernetes functional tests...
✅ msgrp functional tests succeeded
✅ kubernetes functional tests succeeded
✅ samples functional tests succeeded
✅ ucp functional tests succeeded
✅ datastoresrp functional tests succeeded
✅ daprrp functional tests succeeded
✅ shared functional tests succeeded

ytimocin
ytimocin previously approved these changes Feb 28, 2024
Copy link
Contributor

@ytimocin ytimocin left a comment

Choose a reason for hiding this comment

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

Asked a question but other than that LGTM

Comment on lines 60 to 64
for _, configDetails := range config {
configList = append(configList, configDetails.AdditionalProperties)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no concept of default empty configuration afaik, let's add this nil check unless there is a terraform documentation that mentions otherwise.

@radius-functional-tests
Copy link

radius-functional-tests bot commented Feb 28, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository lakshmimsft/radius-mainfork
Commit ref 20e5a9d
Unique ID 58920ee99a
Image tag pr-58920ee99a
Click here to see the list of tools in the current test run
  • gotestsum 1.10.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.1.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/functional/shared/recipes/<name>:pr-58920ee99a
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-58920ee99a
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-58920ee99a
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-58920ee99a
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting datastoresrp functional tests...
⌛ Starting samples functional tests...
⌛ Starting msgrp functional tests...
⌛ Starting shared functional tests...
⌛ Starting ucp functional tests...
⌛ Starting kubernetes functional tests...
✅ msgrp functional tests succeeded
✅ samples functional tests succeeded
✅ kubernetes functional tests succeeded
✅ daprrp functional tests succeeded
✅ ucp functional tests succeeded
✅ datastoresrp functional tests succeeded
✅ shared functional tests succeeded

@lakshmimsft lakshmimsft force-pushed the lakshmimsft/terraformproviders branch from 20e5a9d to ed988b7 Compare February 28, 2024 17:28
@radius-functional-tests
Copy link

radius-functional-tests bot commented Feb 28, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository lakshmimsft/radius-mainfork
Commit ref ed988b7
Unique ID 37905c29e7
Image tag pr-37905c29e7
Click here to see the list of tools in the current test run
  • gotestsum 1.10.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.1.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/functional/shared/recipes/<name>:pr-37905c29e7
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-37905c29e7
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-37905c29e7
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-37905c29e7
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting kubernetes functional tests...
⌛ Starting samples functional tests...
⌛ Starting datastoresrp functional tests...
⌛ Starting shared functional tests...
⌛ Starting msgrp functional tests...
⌛ Starting ucp functional tests...
⌛ Starting daprrp functional tests...
✅ kubernetes functional tests succeeded
✅ samples functional tests succeeded
✅ msgrp functional tests succeeded
✅ datastoresrp functional tests succeeded
✅ ucp functional tests succeeded
✅ daprrp functional tests succeeded
✅ shared functional tests succeeded

@lakshmimsft lakshmimsft merged commit 8a99607 into radius-project:main Feb 28, 2024
16 checks passed
willdavsmith pushed a commit to willdavsmith/radius that referenced this pull request Mar 4, 2024
…port (radius-project#7189)

# Description

Adding logic to build configuration for multiple Terraform provider
support. This is constructed from a combination of environment level
recipe configuration located under RecipeConfig/Terraform/Providers
section and the provider configurations registered with UCP. The
environment level recipe configuration for providers takes precedence
over UCP provider configurations.
[link to PR for design
doc](radius-project/design-notes#39)

The design document describes a SecretReference type and ability to
fetch data from secrets and populate Provider Configuration. This will
be implemented in subsequent PRs.

## Type of change
- This pull request adds or changes features of Radius and has an
approved issue radius-project#6539

Fixes: Part of radius-project#6539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants