mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-20 13:06:46 +00:00
Fix: when a provider is set in ComponentDefinition, it should look for the provider (#3047)
* Fix: when a provider is set in ComponentDefinition, it should look for the provider Fixed the issue "The error message is not correct when AWS provider is not available" Fix #3046 Signed-off-by: Zheng Xi Zhou <zzxwill@gmail.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: app-aws-s3
|
||||
spec:
|
||||
components:
|
||||
- name: sample-s3
|
||||
type: aws-s3
|
||||
properties:
|
||||
bucket: vela-website-202110191745
|
||||
acl: private
|
||||
|
||||
writeConnectionSecretToRef:
|
||||
name: s3-conn
|
||||
@@ -704,7 +704,14 @@ func generateTerraformConfigurationWorkload(wl *Workload, ns string) (*unstructu
|
||||
}
|
||||
if spec.ProviderReference != nil && !reflect.DeepEqual(configuration.Spec.ProviderReference, spec.ProviderReference) {
|
||||
configuration.Spec.ProviderReference = spec.ProviderReference
|
||||
} else if wl.FullTemplate != nil && wl.FullTemplate.ComponentDefinition != nil &&
|
||||
wl.FullTemplate.ComponentDefinition.Spec.Schematic != nil &&
|
||||
wl.FullTemplate.ComponentDefinition.Spec.Schematic.Terraform != nil &&
|
||||
wl.FullTemplate.ComponentDefinition.Spec.Schematic.Terraform.ProviderReference != nil {
|
||||
// Check whether the provider reference is set in ComponentDefinition
|
||||
configuration.Spec.ProviderReference = wl.FullTemplate.ComponentDefinition.Spec.Schematic.Terraform.ProviderReference
|
||||
}
|
||||
|
||||
if spec.Region != "" && configuration.Spec.Region != spec.Region {
|
||||
configuration.Spec.Region = spec.Region
|
||||
}
|
||||
|
||||
@@ -944,7 +944,6 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) {
|
||||
},
|
||||
|
||||
"workload's params is bad": {
|
||||
|
||||
args: args{
|
||||
params: badParam,
|
||||
hcl: "abc",
|
||||
@@ -952,8 +951,7 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) {
|
||||
want: want{err: errors.Wrap(badParamMarshalError, errFailToConvertTerraformComponentProperties)},
|
||||
},
|
||||
|
||||
"terraform workload has a provider reference": {
|
||||
|
||||
"terraform workload has a provider reference, but parameters are bad": {
|
||||
args: args{
|
||||
params: badParam,
|
||||
hcl: "abc",
|
||||
@@ -961,6 +959,14 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) {
|
||||
},
|
||||
want: want{err: errors.Wrap(badParamMarshalError, errFailToConvertTerraformComponentProperties)},
|
||||
},
|
||||
"terraform workload has a provider reference": {
|
||||
args: args{
|
||||
params: variable,
|
||||
hcl: "variable \"name\" {\n description = \"Name to be used on all resources as prefix. Default to 'TF-Module-EIP'.\"\n default = \"TF-Module-EIP\"\n type = string\n }",
|
||||
providerRef: &terraformtypes.Reference{Name: "aws", Namespace: "default"},
|
||||
},
|
||||
want: want{err: nil},
|
||||
},
|
||||
}
|
||||
|
||||
for tcName, tc := range testcases {
|
||||
@@ -1021,7 +1027,16 @@ func TestGenerateTerraformConfigurationWorkload(t *testing.T) {
|
||||
configSpec.WriteConnectionSecretToReference = tc.args.writeConnectionSecretToRef
|
||||
}
|
||||
if tc.args.providerRef != nil {
|
||||
template.Terraform.ProviderReference = tc.args.providerRef
|
||||
tf := &common.Terraform{}
|
||||
tf.ProviderReference = tc.args.providerRef
|
||||
template.ComponentDefinition = &v1beta1.ComponentDefinition{
|
||||
Spec: v1beta1.ComponentDefinitionSpec{
|
||||
Schematic: &common.Schematic{
|
||||
Terraform: tf,
|
||||
},
|
||||
},
|
||||
}
|
||||
configSpec.ProviderReference = tc.args.providerRef
|
||||
}
|
||||
|
||||
wl := &Workload{
|
||||
|
||||
Reference in New Issue
Block a user