Skip to content

Commit 8d0fe11

Browse files
committed
wip: configurable terraform aws version
1 parent 39d9e43 commit 8d0fe11

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

controllers/controlplane/kopscontrolplane_controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type KopsControlPlaneReconciler struct {
9595
Recorder record.EventRecorder
9696
TfExecPath string
9797
DryRun bool
98+
AWSProviderVersion string
9899
GetKopsClientSetFactory func(configBase string) (simple.Clientset, error)
99100
BuildCloudFactory func(*kopsapi.Cluster) (fi.Cloud, error)
100101
PopulateClusterSpecFactory func(ctx context.Context, kopsCluster *kopsapi.Cluster, kopsClientset simple.Clientset, cloud fi.Cloud) (*kopsapi.Cluster, error)
@@ -748,7 +749,12 @@ func (r *KopsControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
748749
}
749750

750751
// This is needed because this is normally created, but when deleting we don't create the kops resources files
751-
err = utils.CreateTerraformFilesFromTemplate("templates/provider.tf.tpl", "provider.tf", terraformOutputDir, nil)
752+
providerData := struct {
753+
Version string
754+
}{
755+
Version: r.AWSProviderVersion,
756+
}
757+
err = utils.CreateTerraformFilesFromTemplate("templates/provider.tf.tpl", "provider.tf", terraformOutputDir, providerData)
752758
if err != nil {
753759
return resultError, err
754760
}
@@ -939,6 +945,13 @@ func (r *KopsControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
939945
return resultError, err
940946
}
941947

948+
if r.AWSProviderVersion != "" {
949+
err = utils.CreateTerraformFilesFromTemplate("templates/versions.tf.tpl", "versions.tf", terraformOutputDir, r.AWSProviderVersion)
950+
if err != nil {
951+
return resultError, err
952+
}
953+
}
954+
942955
// Only Apply resources if DryRun isn't set from command line
943956
if r.DryRun {
944957
reconciler.log.Info(fmt.Sprintf("planning Terraform for %s", kopsControlPlane.ObjectMeta.GetName()))

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ func main() {
7171
var probeAddr string
7272
var controllerClass string
7373
var dryRun bool
74+
var awsProviderVersion string
7475
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7576
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7677
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
7778
"Enable leader election for controller manager. "+
7879
"Enabling this will ensure there is only one active controller manager.")
7980
flag.StringVar(&controllerClass, "controller-class", "", "The name of the controller class to associate with the controller.")
8081
flag.BoolVar(&dryRun, "dry-run", false, "Enable dry-run mode to plan without making actual changes.")
82+
flag.StringVar(&awsProviderVersion, "aws-provider-version", "", "The version of the AWS provider to use in Terraform templates.")
8183

8284
opts := zap.Options{
8385
Development: true,
@@ -162,6 +164,7 @@ func main() {
162164
Recorder: recorder,
163165
TfExecPath: tfExecPath,
164166
DryRun: dryRun,
167+
AWSProviderVersion: awsProviderVersion,
165168
GetKopsClientSetFactory: utils.GetKopsClientset,
166169
BuildCloudFactory: utils.BuildCloud,
167170
PopulateClusterSpecFactory: controlplane.PopulateClusterSpec,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "{{ . }}"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)