diff --git a/CHAP11/kitchen/Gemfile b/CHAP11/kitchen/Gemfile index 2ef6d5a..15de186 100644 --- a/CHAP11/kitchen/Gemfile +++ b/CHAP11/kitchen/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org/" do - gem "kitchen-terraform", "5.8.0" + gem "kitchen-terraform", "7.0.2" end diff --git a/CHAP11/opa/main.tf b/CHAP11/opa/main.tf index 729cf55..07a6645 100644 --- a/CHAP11/opa/main.tf +++ b/CHAP11/opa/main.tf @@ -17,10 +17,10 @@ resource "azurerm_resource_group" "rg" { } resource "azurerm_storage_account" "storage" { - name = "sademotestopa123" + name = "sademotestopa1" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location account_tier = "Standard" account_replication_type = "GRS" - enable_https_traffic_only = true #false + enable_https_traffic_only = false #true } \ No newline at end of file diff --git a/CHAP11/opa/tfplan.json b/CHAP11/opa/tfplan.json new file mode 100644 index 0000000..7079063 --- /dev/null +++ b/CHAP11/opa/tfplan.json @@ -0,0 +1 @@ +{"format_version":"1.1","terraform_version":"1.4.6","planned_values":{"root_module":{"resources":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_name":"registry.terraform.io/hashicorp/azurerm","schema_version":0,"values":{"location":"westeurope","name":"rg-demo-opa","tags":null,"timeouts":null},"sensitive_values":{}},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_name":"registry.terraform.io/hashicorp/azurerm","schema_version":3,"values":{"account_kind":"StorageV2","account_replication_type":"GRS","account_tier":"Standard","allow_nested_items_to_be_public":true,"allowed_copy_scope":null,"azure_files_authentication":[],"cross_tenant_replication_enabled":true,"custom_domain":[],"customer_managed_key":[],"default_to_oauth_authentication":false,"edge_zone":null,"enable_https_traffic_only":true,"identity":[],"immutability_policy":[],"infrastructure_encryption_enabled":false,"is_hns_enabled":false,"location":"westeurope","min_tls_version":"TLS1_2","name":"sademotestopa123","nfsv3_enabled":false,"public_network_access_enabled":true,"queue_encryption_key_type":"Service","resource_group_name":"rg-demo-opa","sas_policy":[],"sftp_enabled":false,"shared_access_key_enabled":true,"static_website":[],"table_encryption_key_type":"Service","tags":null,"timeouts":null},"sensitive_values":{"azure_files_authentication":[],"blob_properties":[],"custom_domain":[],"customer_managed_key":[],"identity":[],"immutability_policy":[],"network_rules":[],"queue_properties":[],"routing":[],"sas_policy":[],"share_properties":[],"static_website":[]}}]}},"resource_changes":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_name":"registry.terraform.io/hashicorp/azurerm","change":{"actions":["create"],"before":null,"after":{"location":"westeurope","name":"rg-demo-opa","tags":null,"timeouts":null},"after_unknown":{"id":true},"before_sensitive":false,"after_sensitive":{}}},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_name":"registry.terraform.io/hashicorp/azurerm","change":{"actions":["create"],"before":null,"after":{"account_kind":"StorageV2","account_replication_type":"GRS","account_tier":"Standard","allow_nested_items_to_be_public":true,"allowed_copy_scope":null,"azure_files_authentication":[],"cross_tenant_replication_enabled":true,"custom_domain":[],"customer_managed_key":[],"default_to_oauth_authentication":false,"edge_zone":null,"enable_https_traffic_only":true,"identity":[],"immutability_policy":[],"infrastructure_encryption_enabled":false,"is_hns_enabled":false,"location":"westeurope","min_tls_version":"TLS1_2","name":"sademotestopa123","nfsv3_enabled":false,"public_network_access_enabled":true,"queue_encryption_key_type":"Service","resource_group_name":"rg-demo-opa","sas_policy":[],"sftp_enabled":false,"shared_access_key_enabled":true,"static_website":[],"table_encryption_key_type":"Service","tags":null,"timeouts":null},"after_unknown":{"access_tier":true,"azure_files_authentication":[],"blob_properties":true,"custom_domain":[],"customer_managed_key":[],"id":true,"identity":[],"immutability_policy":[],"large_file_share_enabled":true,"network_rules":true,"primary_access_key":true,"primary_blob_connection_string":true,"primary_blob_endpoint":true,"primary_blob_host":true,"primary_connection_string":true,"primary_dfs_endpoint":true,"primary_dfs_host":true,"primary_file_endpoint":true,"primary_file_host":true,"primary_location":true,"primary_queue_endpoint":true,"primary_queue_host":true,"primary_table_endpoint":true,"primary_table_host":true,"primary_web_endpoint":true,"primary_web_host":true,"queue_properties":true,"routing":true,"sas_policy":[],"secondary_access_key":true,"secondary_blob_connection_string":true,"secondary_blob_endpoint":true,"secondary_blob_host":true,"secondary_connection_string":true,"secondary_dfs_endpoint":true,"secondary_dfs_host":true,"secondary_file_endpoint":true,"secondary_file_host":true,"secondary_location":true,"secondary_queue_endpoint":true,"secondary_queue_host":true,"secondary_table_endpoint":true,"secondary_table_host":true,"secondary_web_endpoint":true,"secondary_web_host":true,"share_properties":true,"static_website":[]},"before_sensitive":false,"after_sensitive":{"azure_files_authentication":[],"blob_properties":[],"custom_domain":[],"customer_managed_key":[],"identity":[],"immutability_policy":[],"network_rules":[],"primary_access_key":true,"primary_blob_connection_string":true,"primary_connection_string":true,"queue_properties":[],"routing":[],"sas_policy":[],"secondary_access_key":true,"secondary_blob_connection_string":true,"secondary_connection_string":true,"share_properties":[],"static_website":[]}}}],"configuration":{"provider_config":{"azurerm":{"name":"azurerm","full_name":"registry.terraform.io/hashicorp/azurerm","version_constraint":"~\u003e 3.0","expressions":{"features":[{}]}}},"root_module":{"resources":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_config_key":"azurerm","expressions":{"location":{"constant_value":"westeurope"},"name":{"constant_value":"rg-demo-opa"}},"schema_version":0},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_config_key":"azurerm","expressions":{"account_replication_type":{"constant_value":"GRS"},"account_tier":{"constant_value":"Standard"},"enable_https_traffic_only":{"constant_value":true},"location":{"references":["azurerm_resource_group.rg.location","azurerm_resource_group.rg"]},"name":{"constant_value":"sademotestopa123"},"resource_group_name":{"references":["azurerm_resource_group.rg.name","azurerm_resource_group.rg"]}},"schema_version":3}]}},"relevant_attributes":[{"resource":"azurerm_resource_group.rg","attribute":["location"]},{"resource":"azurerm_resource_group.rg","attribute":["name"]}]} diff --git a/CHAP11/pytest/test_tf.py b/CHAP11/pytest/test_tf.py index 04e2b15..938619e 100644 --- a/CHAP11/pytest/test_tf.py +++ b/CHAP11/pytest/test_tf.py @@ -4,6 +4,8 @@ @pytest.fixture(scope="session") def terraform_plan_output(): + + subprocess.run(["terraform", "init"]) # Run the Terraform plan command to generate the state file subprocess.run(["terraform", "plan", "-out", "plan.tfout"]) @@ -15,6 +17,9 @@ def terraform_plan_output(): def test_storage_account_https_only_enabled(terraform_plan_output): + + + assert terraform_plan_output["format_version"] == "1.1" # Get the value of the 'enable_https_traffic_only' property enable_https_traffic_only = terraform_plan_output['resource_changes'][1]['change']['after']['enable_https_traffic_only'] diff --git a/CHAP11/tf-compliance/main.tf b/CHAP11/tf-compliance/main.tf index e58386c..3c79c6a 100644 --- a/CHAP11/tf-compliance/main.tf +++ b/CHAP11/tf-compliance/main.tf @@ -24,7 +24,7 @@ resource "azurerm_storage_account" "storage" { account_tier = "Standard" account_replication_type = "GRS" enable_https_traffic_only = false #true - tags = { - DEMO = "book" - } + # tags = { + # DEMO = "book" + # } } \ No newline at end of file diff --git a/CHAP11/tf-compliance/out.tfplan.json b/CHAP11/tf-compliance/out.tfplan.json new file mode 100644 index 0000000..4b33218 --- /dev/null +++ b/CHAP11/tf-compliance/out.tfplan.json @@ -0,0 +1 @@ +{"format_version":"1.1","terraform_version":"1.3.6","planned_values":{"root_module":{"resources":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_name":"registry.terraform.io/hashicorp/azurerm","schema_version":0,"values":{"location":"westeurope","name":"rg-demo-compliance","tags":null,"timeouts":null},"sensitive_values":{}},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_name":"registry.terraform.io/hashicorp/azurerm","schema_version":3,"values":{"account_kind":"StorageV2","account_replication_type":"GRS","account_tier":"Standard","allow_nested_items_to_be_public":true,"allowed_copy_scope":null,"azure_files_authentication":[],"cross_tenant_replication_enabled":true,"custom_domain":[],"customer_managed_key":[],"default_to_oauth_authentication":false,"edge_zone":null,"enable_https_traffic_only":false,"identity":[],"immutability_policy":[],"infrastructure_encryption_enabled":false,"is_hns_enabled":false,"location":"westeurope","min_tls_version":"TLS1_2","name":"sademotestcomp123","nfsv3_enabled":false,"public_network_access_enabled":true,"queue_encryption_key_type":"Service","resource_group_name":"rg-demo-compliance","sas_policy":[],"sftp_enabled":false,"shared_access_key_enabled":true,"static_website":[],"table_encryption_key_type":"Service","tags":null,"timeouts":null},"sensitive_values":{"azure_files_authentication":[],"blob_properties":[],"custom_domain":[],"customer_managed_key":[],"identity":[],"immutability_policy":[],"network_rules":[],"queue_properties":[],"routing":[],"sas_policy":[],"share_properties":[],"static_website":[]}}]}},"resource_changes":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_name":"registry.terraform.io/hashicorp/azurerm","change":{"actions":["create"],"before":null,"after":{"location":"westeurope","name":"rg-demo-compliance","tags":null,"timeouts":null},"after_unknown":{"id":true},"before_sensitive":false,"after_sensitive":{}}},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_name":"registry.terraform.io/hashicorp/azurerm","change":{"actions":["create"],"before":null,"after":{"account_kind":"StorageV2","account_replication_type":"GRS","account_tier":"Standard","allow_nested_items_to_be_public":true,"allowed_copy_scope":null,"azure_files_authentication":[],"cross_tenant_replication_enabled":true,"custom_domain":[],"customer_managed_key":[],"default_to_oauth_authentication":false,"edge_zone":null,"enable_https_traffic_only":false,"identity":[],"immutability_policy":[],"infrastructure_encryption_enabled":false,"is_hns_enabled":false,"location":"westeurope","min_tls_version":"TLS1_2","name":"sademotestcomp123","nfsv3_enabled":false,"public_network_access_enabled":true,"queue_encryption_key_type":"Service","resource_group_name":"rg-demo-compliance","sas_policy":[],"sftp_enabled":false,"shared_access_key_enabled":true,"static_website":[],"table_encryption_key_type":"Service","tags":null,"timeouts":null},"after_unknown":{"access_tier":true,"azure_files_authentication":[],"blob_properties":true,"custom_domain":[],"customer_managed_key":[],"id":true,"identity":[],"immutability_policy":[],"large_file_share_enabled":true,"network_rules":true,"primary_access_key":true,"primary_blob_connection_string":true,"primary_blob_endpoint":true,"primary_blob_host":true,"primary_connection_string":true,"primary_dfs_endpoint":true,"primary_dfs_host":true,"primary_file_endpoint":true,"primary_file_host":true,"primary_location":true,"primary_queue_endpoint":true,"primary_queue_host":true,"primary_table_endpoint":true,"primary_table_host":true,"primary_web_endpoint":true,"primary_web_host":true,"queue_properties":true,"routing":true,"sas_policy":[],"secondary_access_key":true,"secondary_blob_connection_string":true,"secondary_blob_endpoint":true,"secondary_blob_host":true,"secondary_connection_string":true,"secondary_dfs_endpoint":true,"secondary_dfs_host":true,"secondary_file_endpoint":true,"secondary_file_host":true,"secondary_location":true,"secondary_queue_endpoint":true,"secondary_queue_host":true,"secondary_table_endpoint":true,"secondary_table_host":true,"secondary_web_endpoint":true,"secondary_web_host":true,"share_properties":true,"static_website":[]},"before_sensitive":false,"after_sensitive":{"azure_files_authentication":[],"blob_properties":[],"custom_domain":[],"customer_managed_key":[],"identity":[],"immutability_policy":[],"network_rules":[],"primary_access_key":true,"primary_blob_connection_string":true,"primary_connection_string":true,"queue_properties":[],"routing":[],"sas_policy":[],"secondary_access_key":true,"secondary_blob_connection_string":true,"secondary_connection_string":true,"share_properties":[],"static_website":[]}}}],"configuration":{"provider_config":{"azurerm":{"name":"azurerm","full_name":"registry.terraform.io/hashicorp/azurerm","version_constraint":"~\u003e 3.0","expressions":{"features":[{}]}}},"root_module":{"resources":[{"address":"azurerm_resource_group.rg","mode":"managed","type":"azurerm_resource_group","name":"rg","provider_config_key":"azurerm","expressions":{"location":{"constant_value":"westeurope"},"name":{"constant_value":"rg-demo-compliance"}},"schema_version":0},{"address":"azurerm_storage_account.storage","mode":"managed","type":"azurerm_storage_account","name":"storage","provider_config_key":"azurerm","expressions":{"account_replication_type":{"constant_value":"GRS"},"account_tier":{"constant_value":"Standard"},"enable_https_traffic_only":{"constant_value":false},"location":{"references":["azurerm_resource_group.rg.location","azurerm_resource_group.rg"]},"name":{"constant_value":"sademotestcomp123"},"resource_group_name":{"references":["azurerm_resource_group.rg.name","azurerm_resource_group.rg"]}},"schema_version":3}]}},"relevant_attributes":[{"resource":"azurerm_resource_group.rg","attribute":["name"]},{"resource":"azurerm_resource_group.rg","attribute":["location"]}]}