Skip to content

Commit ace6248

Browse files
committed
Fix terraform provisioner
1 parent c7c7388 commit ace6248

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

provisioner/terraform/parse.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func convertVariableToParameter(variable *tfconfig.Variable) (*proto.ParameterSc
3737
schema := &proto.ParameterSchema{
3838
Name: variable.Name,
3939
Description: variable.Description,
40-
Sensitive: variable.Sensitive,
40+
RedisplayValue: variable.Sensitive,
4141
ValidationValueType: variable.Type,
4242
}
4343

@@ -46,7 +46,14 @@ func convertVariableToParameter(variable *tfconfig.Variable) (*proto.ParameterSc
4646
if err != nil {
4747
return nil, xerrors.Errorf("parse variable %q default: %w", variable.Name, err)
4848
}
49-
schema.DefaultValue = string(defaultData)
49+
schema.DefaultSource = &proto.ParameterSource{
50+
Scheme: proto.ParameterSource_DATA,
51+
Value: string(defaultData),
52+
}
53+
schema.DefaultDestination = &proto.ParameterDestination{
54+
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
55+
Value: variable.Name,
56+
}
5057
}
5158

5259
if len(variable.Validations) > 0 && variable.Validations[0].Condition != nil {

provisioner/terraform/parse_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ func TestParse(t *testing.T) {
6363
},
6464
Response: &proto.Parse_Response{
6565
ParameterSchemas: []*proto.ParameterSchema{{
66-
Name: "A",
67-
DefaultValue: "\"wow\"",
66+
Name: "A",
67+
DefaultSource: &proto.ParameterSource{
68+
Scheme: proto.ParameterSource_DATA,
69+
Value: "\"wow\"",
70+
},
71+
DefaultDestination: &proto.ParameterDestination{
72+
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
73+
Value: "A",
74+
},
6875
}},
6976
},
7077
}, {

provisioner/terraform/provision.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ func (t *terraform) Provision(ctx context.Context, request *proto.Provision_Requ
3737
return nil, xerrors.Errorf("initialize terraform: %w", err)
3838
}
3939

40+
env := map[string]string{}
4041
options := make([]tfexec.ApplyOption, 0)
41-
for _, params := range request.ParameterValues {
42-
options = append(options, tfexec.Var(fmt.Sprintf("%s=%s", params.Name, params.Value)))
42+
for _, param := range request.ParameterValues {
43+
switch param.DestinationScheme {
44+
case proto.ParameterDestination_ENVIRONMENT_VARIABLE:
45+
env[param.Name] = param.Value
46+
case proto.ParameterDestination_PROVISIONER_VARIABLE:
47+
options = append(options, tfexec.Var(fmt.Sprintf("%s=%s", param.Name, param.Value)))
48+
default:
49+
return nil, xerrors.Errorf("unsupported parameter type %q for %q", param.DestinationScheme, param.Name)
50+
}
51+
}
52+
err = terraform.SetEnv(env)
53+
if err != nil {
54+
return nil, xerrors.Errorf("apply environment variables: %w", err)
4355
}
56+
4457
err = terraform.Apply(ctx, options...)
4558
if err != nil {
4659
return nil, xerrors.Errorf("apply terraform: %w", err)

provisioner/terraform/provision_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ func TestProvision(t *testing.T) {
6363
},
6464
Request: &proto.Provision_Request{
6565
ParameterValues: []*proto.ParameterValue{{
66-
Name: "A",
67-
Value: "example",
66+
DestinationScheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
67+
Name: "A",
68+
Value: "example",
6869
}},
6970
},
7071
Response: &proto.Provision_Response{},

0 commit comments

Comments
 (0)