diff --git a/data/data/aws/bootstrap/main.tf b/data/data/aws/bootstrap/main.tf index defcf71635c..89dacb91a92 100644 --- a/data/data/aws/bootstrap/main.tf +++ b/data/data/aws/bootstrap/main.tf @@ -46,10 +46,12 @@ resource "aws_s3_bucket_object" "ignition" { resource "aws_iam_instance_profile" "bootstrap" { name = "${var.cluster_id}-bootstrap-profile" - role = aws_iam_role.bootstrap.name + role = var.iam_role_name != "" ? var.iam_role_name : aws_iam_role.bootstrap[0].name } resource "aws_iam_role" "bootstrap" { + count = var.iam_role_name == "" ? 1 : 0 + name = "${var.cluster_id}-bootstrap-role" path = "/" @@ -78,8 +80,9 @@ EOF } resource "aws_iam_role_policy" "bootstrap" { + count = var.iam_role_name == "" ? 1 : 0 name = "${var.cluster_id}-bootstrap-policy" - role = aws_iam_role.bootstrap.id + role = aws_iam_role.bootstrap[0].id policy = < InstallConfig is the configuration for an OpenShift install. -`, + `, }, { path: []string{"publish"}, desc: ` @@ -226,7 +226,7 @@ VERSION: v1 RESOURCE: Publish controls how the user facing endpoints of the cluster like the Kubernetes API, OpenShift routes etc. are exposed. When no strategy is specified, the strategy is "External". -`, + `, }, { path: []string{"platform"}, desc: ` @@ -235,7 +235,7 @@ VERSION: v1 RESOURCE: Platform is the configuration for the specific platform upon which to perform the installation. -`, + `, }, { path: []string{"platform", "aws"}, desc: ` @@ -244,7 +244,7 @@ VERSION: v1 RESOURCE: AWS is the configuration used when installing on AWS. -`, + `, }, { path: []string{"platform", "azure"}, desc: ` @@ -252,8 +252,8 @@ KIND: InstallConfig VERSION: v1 RESOURCE: - Azure is the configuration used when installing on Azure. -`, + Azure is the configuration used when installing on Azure. + `, }, { path: []string{"platform", "aws", "region"}, desc: ` @@ -261,8 +261,8 @@ KIND: InstallConfig VERSION: v1 RESOURCE: - Region specifies the AWS region where the cluster will be created. -`, + Region specifies the AWS region where the cluster will be created. + `, }, { path: []string{"platform", "aws", "subnets"}, desc: ` @@ -270,8 +270,8 @@ KIND: InstallConfig VERSION: v1 RESOURCE: <[]string> - Subnets specifies existing subnets (by ID) where cluster resources will be created. Leave unset to have the installer create subnets in a new VPC on your behalf. -`, + Subnets specifies existing subnets (by ID) where cluster resources will be created. Leave unset to have the installer create subnets in a new VPC on your behalf. + `, }, { path: []string{"platform", "aws", "userTags"}, desc: ` @@ -279,8 +279,8 @@ KIND: InstallConfig VERSION: v1 RESOURCE: - UserTags additional keys and values that the installer will add as tags to all resources that it creates. Resources created by the cluster itself may not include these tags. -`, + UserTags additional keys and values that the installer will add as tags to all resources that it creates. Resources created by the cluster itself may not include these tags. + `, }, { path: []string{"platform", "aws", "serviceEndpoints"}, desc: ` @@ -288,8 +288,8 @@ KIND: InstallConfig VERSION: v1 RESOURCE: <[]object> - ServiceEndpoints list contains custom endpoints which will override default service endpoint of AWS Services. There must be only one ServiceEndpoint for a service. -`, + ServiceEndpoints list contains custom endpoints which will override default service endpoint of AWS Services. There must be only one ServiceEndpoint for a service. + `, }, { path: []string{"platform", "aws", "serviceEndpoints", "url"}, desc: ` @@ -298,7 +298,34 @@ VERSION: v1 RESOURCE: URL is fully qualified URI with scheme https, that overrides the default generated endpoint for a client. This must be provided and cannot be empty. -`, + `, + }, { + path: []string{"compute", "platform", "aws", "iamRole"}, + desc: ` +KIND: InstallConfig +VERSION: v1 + +RESOURCE: + IAMRole is the name of the IAM Role to use for the instance profile of the machine. Leave unset to have the installer create the IAM Role on your behalf. + `, + }, { + path: []string{"controlPlane", "platform", "aws", "iamRole"}, + desc: ` +KIND: InstallConfig +VERSION: v1 + +RESOURCE: + IAMRole is the name of the IAM Role to use for the instance profile of the machine. Leave unset to have the installer create the IAM Role on your behalf. + `, + }, { + path: []string{"platform", "aws", "defaultMachinePlatform", "iamRole"}, + desc: ` +KIND: InstallConfig +VERSION: v1 + +RESOURCE: + IAMRole is the name of the IAM Role to use for the instance profile of the machine. Leave unset to have the installer create the IAM Role on your behalf. + `, }} for _, test := range cases { t.Run("", func(t *testing.T) { diff --git a/pkg/tfvars/aws/aws.go b/pkg/tfvars/aws/aws.go index 16ed20cea12..01b7194120d 100644 --- a/pkg/tfvars/aws/aws.go +++ b/pkg/tfvars/aws/aws.go @@ -36,6 +36,8 @@ type config struct { SkipRegionCheck bool `json:"aws_skip_region_validation"` IgnitionBucket string `json:"aws_ignition_bucket"` BootstrapIgnitionStub string `json:"aws_bootstrap_stub_ignition"` + MasterIAMRoleName string `json:"aws_master_iam_role_name,omitempty"` + WorkerIAMRoleName string `json:"aws_worker_iam_role_name,omitempty"` } // TFVarsSources contains the parameters to be converted into Terraform variables @@ -53,6 +55,8 @@ type TFVarsSources struct { IgnitionBucket, IgnitionPresignedURL string AdditionalTrustBundle string + + MasterIAMRoleName, WorkerIAMRoleName string } // TFVars generates AWS-specific Terraform variables launching the cluster. @@ -123,6 +127,8 @@ func TFVars(sources TFVarsSources) ([]byte, error) { PublishStrategy: string(sources.Publish), SkipRegionCheck: !configaws.IsKnownRegion(masterConfig.Placement.Region), IgnitionBucket: sources.IgnitionBucket, + MasterIAMRoleName: sources.MasterIAMRoleName, + WorkerIAMRoleName: sources.WorkerIAMRoleName, } stubIgn, err := generateIgnitionShim(sources.IgnitionPresignedURL, sources.AdditionalTrustBundle) diff --git a/pkg/types/aws/machinepool.go b/pkg/types/aws/machinepool.go index 353e44f173c..ef597a67bbf 100644 --- a/pkg/types/aws/machinepool.go +++ b/pkg/types/aws/machinepool.go @@ -24,6 +24,11 @@ type MachinePool struct { // // +optional EC2RootVolume `json:"rootVolume"` + + // IAMRole is the name of the IAM Role to use for the instance profile of the machine. + // Leave unset to have the installer create the IAM Role on your behalf. + // +optional + IAMRole string `json:"iamRole,omitempty"` } // Set sets the values from `required` to `a`. @@ -56,6 +61,10 @@ func (a *MachinePool) Set(required *MachinePool) { if required.EC2RootVolume.KMSKeyARN != "" { a.EC2RootVolume.KMSKeyARN = required.EC2RootVolume.KMSKeyARN } + + if required.IAMRole != "" { + a.IAMRole = required.IAMRole + } } // EC2RootVolume defines the storage for an ec2 instance. diff --git a/pkg/types/installconfig.go b/pkg/types/installconfig.go index c4bde27fe42..4a7dc88b5e1 100644 --- a/pkg/types/installconfig.go +++ b/pkg/types/installconfig.go @@ -22,7 +22,8 @@ const ( // InstallConfigVersion is the version supported by this package. // If you bump this, you must also update the list of convertable values in // pkg/types/conversion/installconfig.go - InstallConfigVersion = "v1" + InstallConfigVersion = "v1" + workerMachinePoolName = "worker" ) var ( @@ -351,3 +352,14 @@ type BootstrapInPlace struct { // InstallationDisk is the target disk drive for coreos-installer InstallationDisk string `json:"installationDisk"` } + +// WorkerMachinePool retrieves the worker MachinePool from InstallConfig.Compute +func (c *InstallConfig) WorkerMachinePool() *MachinePool { + for _, machinePool := range c.Compute { + if machinePool.Name == workerMachinePoolName { + return &machinePool + } + } + + return nil +}