@@ -151,6 +151,15 @@ Or: <code>original_yaml_string = file("/path/to/my/codefresh.yml")</code>
151
151
Type : schema .TypeString ,
152
152
},
153
153
},
154
+ "encrypted_variables" : {
155
+ Description : "Pipeline level encrypted variables. Please note that drift will not be detected for encrypted variables" ,
156
+ Type : schema .TypeMap ,
157
+ Optional : true ,
158
+ Elem : & schema.Schema {
159
+ Type : schema .TypeString ,
160
+ Sensitive : true ,
161
+ },
162
+ },
154
163
"trigger" : {
155
164
Description : "The pipeline's triggers (currently the only nested trigger supported is git; for other trigger types, use the `codefresh_pipeline_*_trigger` resources)." ,
156
165
Type : schema .TypeList ,
@@ -336,6 +345,15 @@ Or: <code>original_yaml_string = file("/path/to/my/codefresh.yml")</code>
336
345
Type : schema .TypeString ,
337
346
},
338
347
},
348
+ "encrypted_variables" : {
349
+ Description : "Trigger level encrypted variables. Please note that drift will not be detected for encrypted variables" ,
350
+ Type : schema .TypeMap ,
351
+ Optional : true ,
352
+ Elem : & schema.Schema {
353
+ Type : schema .TypeString ,
354
+ Sensitive : true ,
355
+ },
356
+ },
339
357
},
340
358
},
341
359
},
@@ -467,6 +485,15 @@ Or: <code>original_yaml_string = file("/path/to/my/codefresh.yml")</code>
467
485
Type : schema .TypeString ,
468
486
},
469
487
},
488
+ "encrypted_variables" : {
489
+ Description : "Trigger level encrypted variables. Please note that drift will not be detected for encrypted variables" ,
490
+ Type : schema .TypeMap ,
491
+ Optional : true ,
492
+ Elem : & schema.Schema {
493
+ Type : schema .TypeString ,
494
+ Sensitive : true ,
495
+ },
496
+ },
470
497
},
471
498
},
472
499
},
@@ -608,8 +635,8 @@ Pipeline concurrency policy: Builds on 'Pending Approval' state should be:
608
635
},
609
636
"enable_notifications" : {
610
637
Type : schema .TypeBool ,
611
- Optional : true ,
612
- Default : false ,
638
+ Optional : true ,
639
+ Default : false ,
613
640
},
614
641
},
615
642
},
@@ -717,7 +744,51 @@ func mapPipelineToResource(pipeline cfclient.Pipeline, d *schema.ResourceData) e
717
744
return err
718
745
}
719
746
720
- err = d .Set ("spec" , flattenSpec (pipeline .Spec ))
747
+ flattenedSpec := flattenSpec (pipeline .Spec )
748
+
749
+ // Set encrypted variables from resource data, as otherwise they cause constant diff as the value is always returned as *****
750
+ encryptedVariables , ok := flattenedSpec [0 ]["encrypted_variables" ].(map [string ]string )
751
+
752
+ if ok {
753
+ if len (encryptedVariables ) > 0 {
754
+ setEncryptedVariablesValuesFromResource (d , encryptedVariables , "spec.0.encrypted_variables" )
755
+ }
756
+ }
757
+
758
+ // Set trigger encrypted variables from resource data
759
+ triggers , getTriggersOK := flattenedSpec [0 ]["trigger" ]
760
+
761
+ if getTriggersOK {
762
+ for triggerIndex , triggerSpec := range triggers .([]map [string ]interface {}) {
763
+
764
+ triggerEncryptedVariables , ok := triggerSpec ["encrypted_variables" ].(map [string ]string )
765
+
766
+ if ok {
767
+ if len (triggerEncryptedVariables ) > 0 {
768
+ setEncryptedVariablesValuesFromResource (d , triggerEncryptedVariables , fmt .Sprintf ("spec.0.trigger.%d.encrypted_variables" , triggerIndex ))
769
+ }
770
+ }
771
+ }
772
+ }
773
+
774
+ // Set cron trigger encrypted variables from resource data
775
+ cronTriggers , getCronTriggersOK := flattenedSpec [0 ]["cron_trigger" ]
776
+
777
+ if getCronTriggersOK {
778
+ for triggerIndex , triggerSpec := range cronTriggers .([]map [string ]interface {}) {
779
+
780
+ triggerEncryptedVariables , ok := triggerSpec ["encrypted_variables" ].(map [string ]string )
781
+
782
+ if ok {
783
+ if len (triggerEncryptedVariables ) > 0 {
784
+ setEncryptedVariablesValuesFromResource (d , triggerEncryptedVariables , fmt .Sprintf ("spec.0.cron_trigger.%d.encrypted_variables" , triggerIndex ))
785
+ }
786
+ }
787
+ }
788
+ }
789
+
790
+ err = d .Set ("spec" , flattenedSpec )
791
+
721
792
if err != nil {
722
793
return err
723
794
}
@@ -735,9 +806,9 @@ func mapPipelineToResource(pipeline cfclient.Pipeline, d *schema.ResourceData) e
735
806
return nil
736
807
}
737
808
738
- func flattenSpec (spec cfclient.Spec ) []interface {} {
809
+ func flattenSpec (spec cfclient.Spec ) []map [ string ] interface {} {
739
810
740
- var res = make ([]interface {}, 0 )
811
+ var res = make ([]map [ string ] interface {}, 0 )
741
812
m := make (map [string ]interface {})
742
813
743
814
if len (spec .Triggers ) > 0 {
@@ -753,7 +824,8 @@ func flattenSpec(spec cfclient.Spec) []interface{} {
753
824
}
754
825
755
826
if len (spec .Variables ) != 0 {
756
- m ["variables" ] = datautil .ConvertVariables (spec .Variables )
827
+ // Do not set encrypted variables because they cause constant diff
828
+ m ["variables" ], m ["encrypted_variables" ] = datautil .ConvertVariables (spec .Variables )
757
829
}
758
830
759
831
if spec .RuntimeEnvironment != (cfclient.RuntimeEnvironment {}) {
@@ -884,7 +956,7 @@ func flattenTriggers(triggers []cfclient.Trigger) []map[string]interface{} {
884
956
m ["provider" ] = trigger .Provider
885
957
m ["type" ] = trigger .Type
886
958
m ["events" ] = trigger .Events
887
- m ["variables" ] = datautil .ConvertVariables (trigger .Variables )
959
+ m ["variables" ], m [ "encrypted_variables" ] = datautil .ConvertVariables (trigger .Variables )
888
960
if trigger .RuntimeEnvironment != nil {
889
961
m ["runtime_environment" ] = flattenSpecRuntimeEnvironment (* trigger .RuntimeEnvironment )
890
962
}
@@ -904,7 +976,7 @@ func flattenCronTriggers(cronTriggers []cfclient.CronTrigger) []map[string]inter
904
976
m ["disabled" ] = trigger .Disabled
905
977
m ["git_trigger_id" ] = trigger .GitTriggerId
906
978
m ["branch" ] = trigger .Branch
907
- m ["variables" ] = datautil .ConvertVariables (trigger .Variables )
979
+ m ["variables" ], m [ "encrypted_variables" ] = datautil .ConvertVariables (trigger .Variables )
908
980
if trigger .Options != nil {
909
981
m ["options" ] = flattenTriggerOptions (* trigger .Options )
910
982
}
@@ -977,7 +1049,11 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
977
1049
}
978
1050
979
1051
if variables , ok := d .GetOk ("spec.0.variables" ); ok {
980
- pipeline .SetVariables (variables .(map [string ]interface {}))
1052
+ pipeline .SetVariables (variables .(map [string ]interface {}), false )
1053
+ }
1054
+
1055
+ if encryptedVariables , ok := d .GetOk ("spec.0.encrypted_variables" ); ok {
1056
+ pipeline .SetVariables (encryptedVariables .(map [string ]interface {}), true )
981
1057
}
982
1058
983
1059
if triggers , ok := d .GetOk ("spec.0.trigger" ); ok {
@@ -1003,7 +1079,11 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
1003
1079
Events : datautil .ConvertStringArr (events ),
1004
1080
}
1005
1081
variables := d .Get (fmt .Sprintf ("spec.0.trigger.%v.variables" , idx )).(map [string ]interface {})
1006
- codefreshTrigger .SetVariables (variables )
1082
+ codefreshTrigger .SetVariables (variables , false )
1083
+
1084
+ encryptedVariables := d .Get (fmt .Sprintf ("spec.0.trigger.%v.encrypted_variables" , idx )).(map [string ]interface {})
1085
+ codefreshTrigger .SetVariables (encryptedVariables , true )
1086
+
1007
1087
if _ , ok := d .GetOk (fmt .Sprintf ("spec.0.trigger.%v.options" , idx )); ok {
1008
1088
options := cfclient.TriggerOptions {
1009
1089
NoCache : d .Get (fmt .Sprintf ("spec.0.trigger.%v.options.0.no_cache" , idx )).(bool ),
@@ -1039,7 +1119,10 @@ func mapResourceToPipeline(d *schema.ResourceData) (*cfclient.Pipeline, error) {
1039
1119
Branch : d .Get (fmt .Sprintf ("spec.0.cron_trigger.%v.branch" , idx )).(string ),
1040
1120
}
1041
1121
variables := d .Get (fmt .Sprintf ("spec.0.cron_trigger.%v.variables" , idx )).(map [string ]interface {})
1042
- codefreshCronTrigger .SetVariables (variables )
1122
+ codefreshCronTrigger .SetVariables (variables , false )
1123
+ encryptedVariables := d .Get (fmt .Sprintf ("spec.0.cron_trigger.%v.encrypted_variables" , idx )).(map [string ]interface {})
1124
+ codefreshCronTrigger .SetVariables (encryptedVariables , true )
1125
+
1043
1126
if _ , ok := d .GetOk (fmt .Sprintf ("spec.0.cron_trigger.%v.options" , idx )); ok {
1044
1127
options := cfclient.TriggerOptions {
1045
1128
NoCache : d .Get (fmt .Sprintf ("spec.0.cron_trigger.%v.options.0.no_cache" , idx )).(bool ),
@@ -1181,3 +1264,15 @@ func convertOnCreateBranchAttributeToPipelineFormat(src string) string {
1181
1264
return "_" + strings .ToLower (w )
1182
1265
})
1183
1266
}
1267
+
1268
+ func setEncryptedVariablesValuesFromResource (d * schema.ResourceData , flattenedVariables map [string ]string , schemaPath string ) error {
1269
+
1270
+ if len (flattenedVariables ) > 0 {
1271
+ // Iterate over variables and set the value from resource data
1272
+ for k := range flattenedVariables {
1273
+ flattenedVariables [k ] = d .Get (fmt .Sprintf ("%s.%s" , schemaPath , k )).(string )
1274
+ }
1275
+ }
1276
+
1277
+ return nil
1278
+ }
0 commit comments