Need insights on Providers for modules on the below qn as I am preparing for Terraform Associate exam

You have referred to a child module that has the following code.

resource “aws instance” “myec2” {

ami = “ami-082b5a644766e0e6f”

instance type = “t2.micro”
}

True or false: You can override the instance type from t2.micro to t2.large from code without making any change in the module.

False.
To be able to change the instance_type in your child module, you need to turn this value into a variable:

variable “instance_type” {
default = “t2.micro”
}

resource “aws_instance” “myec2” {
ami = “ami-082b5a644766e0e6f”
instance_type = var.instance_type
}

If you don’t override anything in the module call, the value will be t2.micro.
If you want to override it, pass the variable:

module “<my_module>” {

instance_type = “t2.large”
}

1 Like

Got it, thanks for the explanation