@@ -0,0 +1,982 @@
+s program terminate instances if proper tag is not used%0A%0A%22%22%22%0A%0Aimport time%0Aimport boto3%0A%0Astart_time = time.time()%0Aec2 = boto3.resource('ec2')%0Aec2_client =  boto3.client('ec2')%0Atag_deparment = %5B'Finance', 'Marketing', 'HumanResources', 'Research'%5D # Your departments%0Ashutdown_instance = False%0A%0A%0Afor instance in ec2.instances.all():%0A    instance_state = instance.state%5B'Name'%5D%0A    if instance_state == ('running' or 'pending'):%0A        for tags in instance.tags:%0A            for department in tag_deparment:%0A                if tags%5B'Value'%5D == department:%0A                    shutdown_instance = False%0A                    break%0A                else:%0A                    shutdown_instance = True%0A                    %0A        print('The following instance will be shutdown', instance.id, 'Shutdown = ', shutdown_instance)%0A        if shutdown_instance is True:%0A            ec2_client.stop_instances(%0A                InstanceIds = %5Binstance.id%5D,%0A                Force = True%0A            )%0A

Add terminate instances