### spotinst_oceancd_rollout_spec Resource Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/oceancd_rollout_spec.md Example usage of the spotinst_oceancd_rollout_spec resource to define a rollout specification. ```APIDOC ## spotinst_oceancd_rollout_spec Resource ### Description Manages a Spotinst OceanCD Rollout Spec resource. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **rollout_spec_name** (string) - Required - The name of the rollout specification. - **failure_policy** (object) - Optional - Defines the action to take when a rollout fails. - **action** (string) - Required - The action to perform on failure (e.g., "abort"). - **spot_deployment** (object) - Optional - Configuration for a single spot deployment. - **spot_deployment_cluster_id** (string) - Required - The ID of the cluster for the spot deployment. - **spot_deployment_name** (string) - Required - The name of the spot deployment. - **spot_deployment_namespace** (string) - Required - The namespace for the spot deployment. - **spot_deployments** (object) - Optional - Configuration for multiple spot deployments. - **spot_deployments_cluster_id** (string) - Required - The ID of the cluster for the spot deployments. - **spot_deployment_name** (string) - Required - The name of the spot deployment. - **spot_deployments_namespace** (string) - Required - The namespace for the spot deployments. - **strategy** (object) - Optional - Defines the rollout strategy. - **strategy_name** (string) - Required - The name of the strategy. - **args** (array) - Optional - Arguments for the strategy. - **arg_name** (string) - Required - The name of the argument. - **arg_value** (string) - Optional - The value of the argument. - **value_from** (object) - Optional - Source for the argument value. - **field_ref** (object) - Optional - Reference to a field. - **field_path** (string) - Required - The path to the field. - **traffic** (object) - Optional - Defines the traffic management configuration. - **canary_service** (string) - Required - The name of the canary service. - **stable_service** (string) - Required - The name of the stable service. - **alb** (object) - Optional - Configuration for AWS Application Load Balancer. - **alb_annotation_prefix** (string) - Optional - Annotation prefix for ALB. - **alb_ingress** (string) - Required - The ALB ingress name. - **alb_root_service** (string) - Optional - The root service for ALB. - **service_port** (integer) - Required - The service port. - **stickiness_config** (object) - Optional - Stickiness configuration. - **duration_seconds** (integer) - Required - Duration in seconds for stickiness. - **enabled** (boolean) - Required - Whether stickiness is enabled. - **ambassador** (object) - Optional - Configuration for Ambassador. - **mappings** (array) - Required - List of Ambassador mappings. - (string) - **istio** (object) - Optional - Configuration for Istio. - **destination_rule** (object) - Optional - Istio destination rule configuration. - **canary_subset_name** (string) - Required - Name of the canary subset. - **destination_rule_name** (string) - Required - Name of the destination rule. - **stable_subset_name** (string) - Required - Name of the stable subset. - **virtual_services** (array) - Optional - Istio virtual services configuration. - **virtual_service_name** (string) - Required - Name of the virtual service. - **virtual_service_routes** (array) - Required - Routes for the virtual service. - (string) - **tls_routes** (object) - Optional - TLS routes configuration. - **port** (integer) - Required - The port for TLS routes. - **sni_hosts** (string) - Required - SNI hosts for TLS routes. - **nginx** (object) - Optional - Configuration for Nginx Ingress. - **nginx_annotation_prefix** (string) - Optional - Annotation prefix for Nginx. - **stable_ingress** (string) - Required - The stable ingress name. - **additional_ingress_annotation** (object) - Optional - Additional ingress annotations. - **canary_by_header** (string) - Optional - Header for canary routing. - **key1** (string) - Optional - Example annotation key. - **ping_pong** (object) - Optional - Configuration for Ping Pong traffic shifting. - **ping_service** (string) - Required - The stable service name. - **pong_service** (string) - Required - The canary service name. - **smi** (object) - Optional - Configuration for Service Mesh Interface (SMI). - **smi_root_service** (string) - Required - The root service name. - **traffic_split_name** (string) - Required - The name of the traffic split resource. ### Request Example ```hcl resource "spotinst_oceancd_rollout_spec" "example" { rollout_spec_name = "test-rollout_spec" failure_policy { action = "abort" } spot_deployment { spot_deployment_cluster_id = "Test-Cluster-Id" spot_deployment_name = "TestDeployment" spot_deployment_namespace = "default" } spot_deployments { spot_deployments_cluster_id = "Test-Cluster-Id" spot_deployment_name = "TestDeployment" spot_deployments_namespace = "default" } strategy { strategy_name = "Test_Strategy" args { arg_name = "Test-Arg" arg_value = "TestArgValue" value_from { field_ref { field_path = "metatdata.labels['app']" } } } } traffic { canary_service = "canary-service-test" stable_service = "stable-service-test" alb { alb_annotation_prefix = "custom-ingress-kubernates" alb_ingress = "test-ingress" alb_root_service = "test-root-service" service_port = 8080 stickiness_config { duration_seconds = 3600 enabled = true } } ambassador { mappings = ["test-mappong","test2-mapping"] } istio { destination_rule { canary_subset_name = "canary-subset" destination_rule_name = "test-dest-rule" stable_subset_name = "stable-subset" } virtual_services { virtual_service_name = "test-name" virtual_service_routes = ["route1","route2"] tls_routes { port = 80 sni_hosts = "spot.io" } } } nginx { nginx_annotation_prefix = "customIngress.nginx" stable_ingress = "hello-ingress" additional_ingress_annotation { canary_by_header = "x-canary-test" key1 = "test" } } ping_pong { ping_service = "stable-service" pong_service = "canary-service" } smi { smi_root_service = "stable-service" traffic_split_name = "rollout-expample-traffic-split" } } } ``` ### Response #### Success Response (200) - **name** (string) - The name of the created rollout spec. ``` -------------------------------- ### Build Terraform Provider with Make Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/README.md Build the provider using the 'make build' command. This will build and link the binary into your $GOPATH/bin directory, suitable for global installation. ```sh cd $GOPATH/src/github.com/spotinst/terraform-provider-spotinst make build ``` -------------------------------- ### Install Ocean Kubernetes Controller Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_gke_import.md Installs the Ocean controller using the Spotinst Terraform module. Ensure the `cluster_identifier` matches the one used for the `spotinst_ocean_gke_import` resource. ```hcl module "kubernetes-controller" { source = "spotinst/kubernetes-controller/ocean" # Credentials. spotinst_token = "redacted" spotinst_account = "redacted" # Configuration. cluster_identifier = "ocean-dev" } ``` -------------------------------- ### Build Terraform Provider with Go Build Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/README.md Build the provider using 'go build -o terraform-provider-spotinst'. This command compiles the provider and outputs an executable file. It's useful for local installations. ```sh cd $GOPATH/src/github.com/spotinst/terraform-provider-spotinst go build -o terraform-provider-spotinst ``` -------------------------------- ### Configure Spotinst Provider and Create Elastigroup Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/index.md Configure the Spotinst provider with your API token and account ID. This example also shows how to create an AWS Elastigroup. ```hcl # Configure the Spotinst provider provider "spotinst" { token = "${var.spotinst_token}" account = "${var.spotinst_account}" } # Create an Elastigroup resource "spotinst_elastigroup_aws" "foo" { # ... } ``` -------------------------------- ### Example Usage of spotinst_ocean_gke_import Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_gke_import.md Defines a Spotinst Ocean GKE cluster import resource. Configure `cluster_name`, `controller_cluster_id`, and `location`. Set `min_size`, `max_size`, and `desired_capacity` for scaling. Utilize `auto_update`, `whitelist`, `filters`, `backend_services`, `root_volume_type`, `shielded_instance_config`, and `use_as_template_only` for detailed cluster configuration. ```hcl resource "spotinst_ocean_gke_import" "example" { cluster_name = "example-cluster-name" controller_cluster_id = "example-controller-123124" location = "us-central1-a" min_size = 0 max_size = 2 desired_capacity = 0 auto_update { is_enabled = true } whitelist = ["n1-standard-1", "n1-standard-2"] filters { exclude_families = ["n2"] include_families = ["c2", "c3"] min_memory_gib = 8 max_memory_gib = 16 min_vcpu = 2 max_vcpu = 16 } backend_services { service_name = "example-backend-service" location_type = "regional" scheme = "INTERNAL" named_ports { name = "http" ports = [80, 8080] } } root_volume_type = "pd-ssd" shielded_instance_config { enable_secure_boot = true enable_integrity_monitoring = true } use_as_template_only = false } ``` -------------------------------- ### Install Ocean Kubernetes Controller Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_aks_np.md Installs the Ocean controller using the Terraform module. Ensure the `cluster_identifier` matches the one used for the `spotinst_ocean_aks_np` resource. ```hcl module "kubernetes-controller" { source = "spotinst/kubernetes-controller/ocean" # Credentials. spotinst_token = "redacted" spotinst_account = "redacted" # Configuration. cluster_identifier = "ocean-aks" } ``` -------------------------------- ### Example Usage of OceanCD Verification Provider Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/oceancd_verification_provider.md Configure a Spotinst OceanCD Verification Provider with credentials for Datadog, CloudWatch, Prometheus, New Relic, and Jenkins. Ensure all required fields for each provider are populated. ```hcl resource "spotinst_oceancd_verification_provider" "example" { name = "test-verification-provider" cluster_ids = [ "Example-Cluster-Id-1", "Example-Cluster-Id-2", "Example-Cluster-Id-3" ] datadog { address = 1024 api_key = 512 app_key = 0 } cloud_watch { iam_arn = "arn:aws:iam::123456789012:role/GetMetricData" } prometheus { address = "http://localhost:9090" } new_relic { personal_api_key = "AUO32RN20oUMD-40283" account_id = "account-0189718" region = "eu" base_url_rest = "https://rest.api.newrelic.eu" base_url_nerd_graph = "https://nerdgraph.api.newrelic.eu" } jenkins { base_url = "http://localhost:9090" username = "test-user" api_token = "AbCDeeFFGG" } } ``` -------------------------------- ### Example Usage of Ocean Spark Virtual Node Group Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_spark_virtual_node_group.md This HCL code demonstrates how to configure the Spotinst provider and define an ocean_spark_virtual_node_group resource. Ensure you have an existing Ocean cluster and Virtual Node Group. ```hcl provider "spotinst" { token = "redacted" account = "redacted" } resource "spotinst_ocean_spark_virtual_node_group" "example" { virtual_node_group_id = "vng_id" ocean_spark_cluster_id = "cluster_id" } ``` -------------------------------- ### Create a Spotinst Data Integration with S3 Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/data_integration.md Use this snippet to create a new data integration resource. Ensure the S3 bucket exists and the Spot IAM Role has `s3:putObject` permissions. The `subdir` is optional but recommended for organization. ```hcl resource "spotinst_data_integration" "example" { name = "foo" status = "enabled" s3 { bucketName = "terraform-test-do-not-delete" subdir = "terraform-test-data-integration" } } ``` -------------------------------- ### Elastigroup Azure Configuration Example Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_azure.md This snippet shows a basic Elastigroup configuration for Azure, including auto-healing settings. ```terraform auto_healing = false } // ------------------------------------------------------------------- // --- SCHEDULING ---------------------------------------------------- scheduling_task { is_enabled = true type = "scale" cron_expression = "52 10 * * *" scale_max_capacity = 8 scale_min_capacity = 0 scale_target_capacity = 2 } scheduling_task { is_enabled = true type = "scaleUp" cron_expression = "52 11 * * *" adjustment = 1 } // ------------------------------------------------------------------- // --- LOAD BALANCER ------------------------------------------------- load_balancer { type = "loadBalancer" resource_group_name = "AutomationResourceGroup" name = "Automation-Lb" sku = "Standard" backend_pool_names = ["Automation-Lb-BackendPool"] } // ------------------------------------------------------------------- } ``` -------------------------------- ### Importing a Spotinst Ocean ECS Launch Spec Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_ecs_launch_spec.md Use this command to import an existing Spotinst Ocean ECS Launch Specification using its ID. Ensure you have the correct resource name and ID. ```bash $ terraform import spotinst_ocean_ecs_launch_spec.nameOfTheResource ols-1a2345 ``` -------------------------------- ### Get Spotinst Ocean ECS Launch Spec ID Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/ocean_ecs_launch_spec.md Outputs the ID of the created Spotinst Ocean ECS Launch Spec resource. ```hcl output "ocean_launchspec_id" { value = spotinst_ocean_ecs_launch_spec.example.id } ``` -------------------------------- ### Configure Scheduled Task Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/stateful_node_aws.md Define a scheduled task for a stateful node, specifying its enablement, frequency, start time, cron expression, and type of action. ```hcl scheduled_task { is_enabled = "true" frequency = "hourly" start_time = "2019-11-20T23:59:59Z" cron_expression = "* * * * *" task_type = "pause" } ``` -------------------------------- ### Create Spotinst Programmatic User Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/organization_programmatic_user.md Use this resource to create a new programmatic user. Configure name, description, policies, and user group memberships. Note that 'accounts' and 'policies' arguments are mutually exclusive. ```hcl resource "spotinst_organization_programmatic_user" "terraform_prog_user" { name = "test-prog-user" description = "creating programmatic user" policies { policy_id = "pol-g75d8c06" policy_account_ids = ["act-a1b2c3d4"] } /*accounts { account_id = "act-a1b2c3d4" account_role = "viewer" }*/ user_group_ids=["ugr-abcd1234","ugr-defg8763"] // account and policies are exclusive } ``` -------------------------------- ### Create Spotinst Azure Credentials Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/credentials_azure.md Use this resource to set up Azure credentials within Spotinst. Ensure all required arguments, including account ID, client ID, client secret, tenant ID, subscription ID, and expiration date, are provided. ```hcl # set credential Azure resource "spotinst_credentials_azure" "credential" { account_id = "act-123456" client_id = "redacted" client_secret = "redacted" tenant_id = "redacted" subscription_id = "redacted" expiration_date = "2025-12-31T23:59:00.000Z" } ``` -------------------------------- ### Create a Spotinst Organization User Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/organization_user.md Use this resource to create a new user within your Spotinst organization. Ensure all required fields like email, first name, last name, and role are provided. Optional fields like password, policies, and user group IDs can also be configured. ```hcl resource "spotinst_organization_user" "terraform_user" { email = "abc@xyz.com" first_name = "test" last_name = "user" password = "testUser@123" role = "viewer" policies{ policy_id = "pol-abcd1236" policy_account_ids = ["act-abcf4245"] } user_group_ids=["ugr-abcd1234","ugr-defg8763"] } ``` -------------------------------- ### Configure Scaling Up Policy with SetMinTarget Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_aws.md Example of a scaling up policy using 'setMinTarget' action type. This policy adjusts the minimum target capacity based on CPU utilization. ```hcl scaling_up_policy { policy_name = "policy-name" metric_name = "CPUUtilization" namespace = "AWS/EC2" source = "" statistic = "average" unit = "" cooldown = 60 dimensions { name = "name-1" value = "value-1" } threshold = 10 operator = "gt" evaluation_periods = 10 period = 60 step_adjustments { threshold = 50 action { type = "setMinTarget" min_target_capacity = "3" } } // === MIN TARGET =================== action_type = "setMinTarget" min_target_capacity = 1 // ================================== // === ADJUSTMENT =================== # action_type = "adjustment" # action_type = "percentageAdjustment" # adjustment = "MAX(5,10)" // ================================== // === UPDATE CAPACITY ============== # action_type = "updateCapacity" ``` -------------------------------- ### Configure Elastigroup Azure V3 Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_azure.md This is a comprehensive example of configuring an Elastigroup for Azure, covering capacity, instance types, launch specifications, strategy, networking, and security settings. ```hcl resource "spotinst_elastigroup_azure_v3" "test_azure_group" { name = "example_elastigroup_azure" description = "Azure Elastigroup Resource through TF" resource_group_name = "spotinst-azure" region = "eastus" os = "Linux" zones = ["1", "2", "3"] preferred_zones = ["1", "3"] // --- CAPACITY ------------------------------------------------------ min_size = 0 max_size = 1 desired_capacity = 1 // ------------------------------------------------------------------- // --- INSTANCE TYPES ------------------------------------------------ vm_sizes { od_sizes = ["standard_a1_v1","standard_a1_v2"] spot_sizes = ["standard_a1_v1","standard_a1_v2"] preferred_spot_sizes = ["standard_a1_v2"] excluded_vm_sizes = ["standard_ds2_v3"] spot_size_attributes { max_cpu = 16 min_cpu = 2 max_memory = 64 min_memory = 8 max_storage = 512 min_storage = 32 } } // ------------------------------------------------------------------- // --- LAUNCH SPEC --------------------------------------------------- custom_data = "IyEvYmluL2Jhc2gKZWNobyAidGVzdCI=" shutdown_script = "IlRlc3RpbmcgRUci" //user_data = "IlRlc3RpbmcgRUci" vm_name_prefix = "prefixName" managed_service_identity { resource_group_name = "MC_ocean-westus-dev_ocean-westus-dev-aks_westus" name = "ocean-westus-dev-aks-agentpool" } tags { key = "key1" value = "value1" } tags { key = "key2" value = "value2" } os_disk { size_gb = 32 type = "Premium_LRS" } data_disk { size_gb = 8 type = "Premium_LRS" lun = 2 } // --- IMAGE --------------------------------------------------------- image { marketplace { publisher = "Canonical" offer = "UbuntuServer" sku = "18.04-LTS" version = "latest" } } // ------------------------------------------------------------------- // --- STRATEGY ------------------------------------------------------ //on_demand_count = 1 spot_percentage = 65 draining_timeout = 300 fallback_to_on_demand = true optimization_windows = ["Mon:19:46-Tue:20:46"] availability_vs_cost = 100 revert_to_spot { perform_at = "timeWindow" } signal { type = "vmReadyToShutdown" timeout = 60 } capacity_reservation { should_utilize = true utilization_strategy = "utilizeOverOD" capacity_reservation_groups { crg_name = "crg name" crg_resource_group_name = "resourceGroupName" crg_should_prioritize = true } } // ------------------------------------------------------------------- // --- NETWORK ------------------------------------------------------- network { virtual_network_name = "VirtualNetworkName" resource_group_name = "ResourceGroup" network_interfaces { subnet_name = "default" assign_public_ip = false is_primary = true public_ip_sku = "Standard" enable_ip_forwarding = true additional_ip_configs { name = "SecondaryIPConfig" PrivateIPVersion = "IPv4" } application_security_group { name = "ApplicationSecurityGroupName" resource_group_name = "ResourceGroup" } public_ips { name = "PublicIpName" resource_group_name = "ResourceGroup" } security_group { name = "NetworkSecurityGroupName" resource_group_name = "ResourceGroup" } } } // ------------------------------------------------------------------- proximity_placement_groups { name = "TestProximityPlacementGroup" resource_group_name = "ResourceGroup" } boot_diagnostics { is_enabled = true storage_url = "https://.blob.core.windows.net" type = "unmanaged" } secret { source_vault { name = "TestVault" resource_group_name = "ResourceGroup" } vault_certificates { certificate_url = "string" certificate_store = "string" } } security { security_type = "Standard" secure_boot_enabled = false vtpm_enabled = false confidential_os_disk_encryption = false encryption_at_host = false } // --- LOGIN --------------------------------------------------------- login { user_name = "admin" ssh_public_key = "33a2s1f3g5a1df5g1ad3f2g1adfg56dfg==" } // ------------------------------------------------------------------- // --- HEALTH -------------------------------------------------------- health { health_check_types = ["applicationGateway"] unhealthy_duration = 240 grace_period = 420 } ``` -------------------------------- ### Configure Spotinst Provider with Feature Flags Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/index.md Configure the Spotinst provider with an account and enable the 'MergeCredentialsChain' feature flag. This allows credentials to be merged from multiple sources. ```hcl provider "spotinst" { account = "${var.spotinst_account}" feature_flags = "MergeCredentialsChain=true" } ``` -------------------------------- ### Configure Elastigroup Scheduled Task Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_gcp.md Define a scheduled task to adjust Elastigroup capacity at specific times. This example disables a task and sets target, min, and max capacities. ```hcl scheduled_task { task_type = "setCapacity" cron_expression = "" is_enabled = false target_capacity = 5 min_capacity = 0 max_capacity = 10 } ``` -------------------------------- ### Configure Elastigroup Scaling Up Policy Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_gcp.md Set up a scaling policy to automatically increase the number of instances in an Elastigroup based on specified metrics and thresholds. This example uses Stackdriver metrics. ```hcl scaling_up_policy { policy_name = "scale_up_1" source = "stackdriver" metric_name = "instance/disk/read_ops_count" namespace = "compute" statistic = "average" unit = "percent" threshold = 10000 period = 300 cooldown = 300 operator = "gte" evaluation_periods = 1 action_type = "adjustment" adjustment = 1 dimensions { name = "storage_type" value = "pd-ssd" } } ``` -------------------------------- ### Configure AWS Beanstalk Scheduled Task Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_aws_beanstalk.md Example of a scheduled task configuration for AWS Beanstalk. This snippet demonstrates setting up a backup AMI task with specific scheduling and capacity parameters. ```hcl scheduled_task { task_type = "backup_ami" cron_expression = "" start_time = "1970-01-01T01:00:00Z" frequency = "hourly" scale_target_capacity = 5 scale_min_capacity = 0 scale_max_capacity = 10 is_enabled = false target_capacity = 5 min_capacity = 0 max_capacity = 10 batch_size_percentage = 33 grace_period = 300 } ``` -------------------------------- ### Create a Spotinst Notification Center Policy Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/notification_center_service.md Use this resource to create and manage a Spotinst Notification Center policy. Configure name, description, active status, privacy level, registered users, subscriptions, and compute policy settings. Ensure compute policy configuration includes events and either all resources, specific resource IDs, or dynamic rules. ```hcl resource "spotinst_notification_center" "notifications" { name = "Notification-Center" description = "Creation of notification center policy through terraform" is_active = true privacy_level = "public" registered_users { user_email = "sample@xyz.com" subscription_types = ["email"] } registered_users { user_email = "terraforma@spot.com" subscription_types = ["email", "console"] } subscriptions { endpoint = "testing@xyz.com" subscription_type = "email" } subscriptions { endpoint = "https://webhook.si" subscription_type = "webhook" } compute_policy_config { events { event = "Beanstalk Missing Permissions" event_type = "ERROR" } events { event = "Maximum capacity reached" event_type = "WARN" } should_include_all_resources = false //resource_ids = ["sig-123456789", "sig-987654321"] dynamic_rules { filter_conditions{ expression = "resourceId EQUALS 'sig-123456789'" identifier = "resource_id" operator = "equals" } } } } ``` -------------------------------- ### Create a Spotinst Subscription Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/subscription.md Use this snippet to create a new subscription for receiving event notifications. Configure the resource ID, event type, protocol, and endpoint. The format block allows customization of the notification content. ```hcl resource "spotinst_subscription" "default-subscription" { resource_id = "${spotinst_elastigroup_aws.my-eg.id}" event_type = "AWS_EC2_INSTANCE_LAUNCH" protocol = "http" endpoint = "http://endpoint.com" format = { event = "%event%" instance_id = "%instance-id%" resource_id = "%resource-id%" resource_name = "%resource-name%" tags = "foo,baz,baz" } } ``` -------------------------------- ### Add and Tidy Go Module Dependencies Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/README.md Manage provider dependencies using Go modules. 'go get' fetches a specific version, and 'go mod tidy' cleans up unused references. ```sh go get foo@v1.2.3 go mod tidy ``` -------------------------------- ### Set GCP Credentials Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/credentials_gcp.md Use this resource to configure GCP service account credentials for Spotinst. Ensure all required arguments, including sensitive information like private_key, are provided. ```hcl resource "spotinst_credentials_gcp" "cred_gcp" { account_id = "act-123456" type = "service_account" project_id = "demo-labs" private_key_id = "1234567890" private_key = "-----BEGIN PRIVATE KEY-----abcd1234-----END PRIVATE KEY-----" client_email = "demo-role-act-123456@demo-labs.iam.gserviceaccount.com" client_id = "1234567890" auth_uri = "https://accounts.google.com/o/oauth2/auth" token_uri = "https://oauth2.googleapis.com/token" auth_provider_x509_cert_url = "https://www.googleapis.com/oauth2/v1/certs" client_x509_cert_url = "https://www.googleapis.com/robot/v1/metadata/x509/demo-role-act-123456%40demo-labs.iam.gserviceaccount.com" lifecycle { ignore_changes = [ private_key, account_id ] }} ``` -------------------------------- ### Run Terraform Provider Acceptance Tests Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/README.md Run the full suite of acceptance tests using 'make testacc'. Be aware that these tests create real resources and may incur costs. ```sh make testacc ``` -------------------------------- ### Configure Termination Policies with CloudWatch Metrics Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/mrscaler_aws.md Define termination policies using CloudWatch metrics for EMR applications. This example sets up rules to terminate instances when the number of running or pending applications is below a certain threshold. ```hcl termination_policies { statements { namespace = "AWS/ElasticMapReduce" metric_name = "AppsRunning" statistic = "average" unit = "count" threshold = 1 period = 360 evaluation_periods = 4 operator = "lte" } statements { namespace = "AWS/ElasticMapReduce" metric_name = "AppsPending" statistic = "average" unit = "count" threshold = 0 period = 300 evaluation_periods = 3 operator = "lte" } } termination_policies { statements { namespace = "AWS/ElasticMapReduce" metric_name = "AppsRunning" statistic = "average" unit = "count" threshold = 0 period = 300 evaluation_periods = 3 operator = "lte" } } ``` -------------------------------- ### Configure Instance Metadata Service (IMDS) Options Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/stateful_node_aws.md Set options for accessing instance metadata, including hop limit for HTTP PUT requests and token requirements for IMDSv2. Ensure `http_tokens` is set to 'optional' or 'required' for IMDSv2. ```hcl metadata_options { http_put_response_hop_limit = 33 http_tokens = "optional" instance_metadata_tags = "enabled" } ``` -------------------------------- ### Example Elastigroup GKE Resource Configuration Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_gke.md This configuration defines an Elastigroup for a GKE cluster, including capacity, instance types, strategy, and GKE integration settings. Ensure `cluster_zone_name` and `cluster_id` are correctly set for your GKE environment. ```hcl resource "spotinst_elastigroup_gke" "example-gke-elastigroup" { name = "example-gke" // cluster_id = "terraform-acc-test-cluster" // deprecated cluster_zone_name = "us-central1-a" node_image = "COS" // --- CAPACITY ------------ max_size = 5 min_size = 1 desired_capacity = 3 // ------------------------- // --- INSTANCE TYPES -------------------------------- instance_types_ondemand = "n1-standard-1" instance_types_preemptible = ["n1-standard-1", "n1-standard-2"] // --------------------------------------------------- // --- STRATEGY -------------------- preemptible_percentage = 100 // --------------------------------- integration_gke { location = "us-central1-a" cluster_id = "example-cluster-id" autoscale_is_enabled = true autoscale_is_auto_config = false autoscale_cooldown = 300 autoscale_headroom { cpu_per_unit = 1024 memory_per_unit = 512 num_of_units = 2 } autoscale_down { evaluation_periods = 300 } autoscale_labels { key = "label_key" value = "label_value" } } backend_services { service_name = "backend-service" location_type = "global" named_ports { name = "http" ports = [80, 8080] } } } ``` -------------------------------- ### Configure an HTTP Health Check Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/health_check.md Defines an HTTP health check for a Spotinst resource. Specify the protocol, endpoint, port, and timing for health checks, along with thresholds for determining instance health. This example also includes proxy settings. ```hcl resource "spotinst_health_check" "http_check" { name = "terraform_healt_cheack" resource_id = "sig-123" check { protocol = "http" endpoint = "http://endpoint.com" port = 1337 interval = 10 timeout = 10 healthy = 1 unhealthy = 1 } proxy_address = "http://proxy.com" proxy_port = 80 } ``` -------------------------------- ### Configure Load Balancer Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/stateful_node_aws.md Set up load balancer configurations for a stateful node, including its name, ARN, and type (Classic or Target Group). ```hcl load_balancers { name = "name" arn = "arn" type = "CLASSIC" } ``` -------------------------------- ### Create Spotinst Organization Policy Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/organization_policy.md Use this resource to define and manage Spotinst access policies. Specify the policy name, description, and detailed content including actions, effects, and resources. ```hcl resource "spotinst_organization_policy" "terraform_policy" { name = "test-policy" description = "policy by terraform" policy_content { statements { actions = ["ocean:deleteCluster"] effect = "DENY" resources = ["o-abcd1234","o-defg6789"] } statements { actions = ["ocean:createCluster"] effect = "DENY" resources = ["o-fhau4752","o-761owf4r3"] } } } ``` -------------------------------- ### Configure Instance Health Checks Source: https://github.com/spotinst/terraform-provider-spotinst/blob/main/docs/resources/elastigroup_aws.md Set up health check configurations for instances, including the type of check, grace period, and duration before replacement if an instance becomes unhealthy. ```hcl health_check_type = "ELB" health_check_grace_period = 100 health_check_unhealthy_duration_before_replacement = 120 ```