-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support custom Terraform backends #291
Conversation
Codecov Report
@@ Coverage Diff @@
## master #291 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 1 1
Lines 72 72
======================================
Misses 72 72
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
api/v1beta2/configuration_types.go
Outdated
InClusterConfig bool `json:"inClusterConfig,omitempty"` | ||
|
||
// HCL allows users to use raw hcl code to specify their Terraform backend configuration | ||
HCL string `json:"hcl,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have HCL
https://github.com/oam-dev/terraform-controller/pull/291/files#diff-56b818bb103c20f38071e987a12aebf0914429db0e363f0ec2cd58a817967b4eR30. It might get mixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change HCL
to something else, like raw
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Maybe you can use inline
.
api/v1beta2/configuration_types.go
Outdated
// Type specifies the Terraform backend type, for example, "kubernetes", "s3", etc | ||
Type string `json:"type,omitempty"` | ||
// Config is the detail configurations of the Terraform backend, | ||
// and it represents the key-value pairs inside the terraform backend block in the hcl files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users don't know how to set such fields. As Terraform backends are limited, we can support them one by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that the users can write the spec.backend
like this?
spec:
backend:
s3:
bucket: "mybucket"
key: "path/to/my/key"
region: "my-region"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the one hand, we need to use have a clear guide on how to set the backend just per the API, on the other hand, the spec.backend
should be as simple as possible. Let's set aside some time on the design to check whether it's possible.
Maybe we can refer a Backend object, like we referring to a Provider object in Configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can refer a Backend object, like we referring to a Provider object in Configuration.
I don't think it's necessary to maintain an additional Backend
object, if only to provide custom backend configuration in the Configuration
object.
But if we can add backup and restore
configuration and backup
life cycle management to Backend
object, I think it will make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1.
api/v1beta2/backend_types.go
Outdated
} | ||
|
||
// BackendSpecInnerMain defines all options supported by the Terraform backend configuration. | ||
type BackendSpecInnerMain struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the differences between creating a new Backend CRD and expanding spec.Backend of Configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new Backend
CRD will make the Configuration
more simple and we can also add more fields like options describing backup and resotre
to the new CRD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As one Configuration will match one Backend, so you can also describe backup in Configuration. The CRD yamls will get longer, but for end-users, it won't as they will only choose one backend.
Besides, maintaining another Object will need to take care of its deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I will move the spec into the Configuratoin
.
564db97
to
94f42f4
Compare
api/v1beta2/configuration_types.go
Outdated
|
||
// Artifactory is needed for the Terraform `artifactory` backend type. | ||
Artifactory ArtifactoryBackendConf `json:"artifactory,omitempty"` | ||
Artifactory *ArtifactoryBackendConf `json:"artifactory,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these backend are belong to Remote?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these backends don't belong to Remote. I think users can also use these backends if they use inline HCL configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these backend are belong to Remote?
The meaning of "Remote" is the spec.Remote
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
I would suggest you support Kubernetes first, then S3, and other backends in other PRs. Or you might get desperate with tons of unit-test lines:) |
Do we need to write unit-test for each backend type as different types of backend will be uniformly converted to backend TF string using reflection in the rendering stage? I think we just need to write unit-tests for some special types, like which has secretRef fields. |
Okay. |
c759a59
to
76795dc
Compare
5afacce
to
2eac213
Compare
api/v1beta2/configuration_types.go
Outdated
Inline string `json:"inline,omitempty"` | ||
|
||
// BackendType indicates which backend type to use. This field is needed for custom backend configuration. | ||
BackendType string `json:"backend_type,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use enum
to specify all its accepted values, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
api/v1beta2/configuration_types.go
Outdated
// ConsulBackendConf defines all options supported by the Terraform `consul` backend type. | ||
// You can refer to https://www.terraform.io/language/settings/backends/consul for the usage of each option. | ||
type ConsulBackendConf struct { | ||
Path string `json:"path" hcl:"path"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What hcl
is used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hcl
tag is used when encode the struct to hcl or decode the hcl into go struct.
|
||
} | ||
|
||
func handleInlineBackendHCL(code string) (string, string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to handle inlined backend HCL? How about transparently storing it in backend.tf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used to check for illegal properties in the inline hcl code.
func (d ConfData) Get(key string) interface{} { | ||
x, ok := d[key] | ||
if !ok || x == nil { | ||
klog.Errorf("fetch %s from the custom backend conf error", key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please print the backend information, or it will do any help for debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
568f271
to
336e8a4
Compare
api/v1beta2/configuration_types.go
Outdated
} | ||
|
||
// CurrentNSSecretSelector is used to specify the key in a secret in the current namespace. | ||
type CurrentNSSecretSelector struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the current namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same namespace as the configuration.
|
||
switch { | ||
|
||
case backend != nil && len(backend.Inline) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if Inline
is not empty and BackType is not empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we will use the inline
and ignore the backendType
.
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
…Backend configuration Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
aaad840
to
97feed1
Compare
Codecov Report
@@ Coverage Diff @@
## master #291 +/- ##
=========================================
Coverage ? 78.18%
=========================================
Files ? 23
Lines ? 1595
Branches ? 0
=========================================
Hits ? 1247
Misses ? 268
Partials ? 80
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
Signed-off-by: loheagn <[email protected]>
Signed-off-by: loheagn <[email protected]>
This pull request introduces 3 alerts when merging 6ab7aa0 into 8601f66 - view on LGTM.com new alerts:
|
This pr is supposed to implement the proposal which is the concluation of the issuse #288 .
Currently, the changes only add some fields to the
spec.backend
to enable the end-users to custom the Terraform backend configuration.Signed-off-by: loheagn [email protected]