hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.16k forks source link

[Bug]: aws_storagegateway_gateway outputs ID but resource doesn't actually exist #35059

Closed queglay closed 10 months ago

queglay commented 10 months ago

Terraform Core Version

1.5.6

AWS Provider Version

5.3.0

Affected Resource(s)

aws_storagegateway_gateway

Expected Behavior

This resource should be force to actually exist before outputting an ID

Actual Behavior

It's possible for it to occaisionally output an id, and troublingly release downstream dependencies like NFS file shares without the resource actually existing.

Relevant Error/Panic Output Snippet

Its not showing as an error, but a false positive since it attempts to refresh state, but doesn't detect the resource doesn't exist if I check the AWS management console. This fail state isn't always reproducible. If I destroy and recreate everything, the issue can go away but this isn't manageable for production.


2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.620] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_gateway.storage_gateway_resource[0]: Refreshing state... [id=arn:aws:storagegateway:**************:972620357255:gateway/sgw-3DE32054]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.640] [d-8PURENXH2][stdout]data.terraform_remote_state.predeploy: Read complete after 3s
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.643] [d-8PURENXH2][stdout]module.consul_cluster.aws_autoscaling_group.autoscaling_group: Refreshing state... [id=consul-dev-ami-0eacbdef2e1e47519-20231224083223515000000004]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.647] [d-8PURENXH2][stdout]module.terraform-aws-render-vpc-deploy-vpc-peering.aws_vpc_peering_connection.primary2secondary[0]: Refreshing state... [id=pcx-02aac663ebaef8050]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.701] [d-8PURENXH2][stdout]module.terraform-aws-render-vpc-deploy-vpc-peering.aws_route.primaryprivate2secondary[0]: Refreshing state... [id=r-rtb-0de59cf54134db0871949569277]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.702] [d-8PURENXH2][stdout]module.terraform-aws-render-vpc-deploy-vpc-peering.aws_route.secondarypublic2primary[0]: Refreshing state... [id=r-rtb-02f05b784ecefa6032244212790]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.704] [d-8PURENXH2][stdout]module.terraform-aws-render-vpc-deploy-vpc-peering.aws_route.primarypublic2secondary[0]: Refreshing state... [id=r-rtb-0e6a41aa10ff20e5a1949569277]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.705] [d-8PURENXH2][stdout]module.terraform-aws-render-vpc-deploy-vpc-peering.aws_route.secondaryprivate2primary[0]: Refreshing state... [id=r-rtb-09a4a501205c4382e2244212790]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.735] [d-8PURENXH2][stdout]null_resource.consul_connect: Refreshing state... [id=3230993667346246876]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.735] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_region.current: Reading...
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.737] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_s3_bucket.software_bucket: Reading...
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.744] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_region.current: Read complete after 0s [id=**************]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.746] [d-8PURENXH2][stdout]module.deadline_db_instance.data.template_file.user_data_auth_client: Reading...
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.755] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_subnet.private: Reading...
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.764] [d-8PURENXH2][stdout]module.bastion.data.template_file.user_data_auth_client: Reading...
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.766] [d-8PURENXH2][stdout]module.deadline_db_instance.data.template_file.user_data_auth_client: Read complete after 0s [id=6398bb917ccabc923415ba55da301fb82a2c5c57d71a14b8ffafe0bba16c97df]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.768] [d-8PURENXH2][stdout]module.bastion.data.template_file.user_data_auth_client: Read complete after 0s [id=88ee1890c0af4b1567b9e0baefd573fdff45425f3e4eef4489ee76f2181eb978]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.769] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_s3_bucket.software_bucket: Read complete after 0s [id=software.dev.firehawkvfx.com]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.773] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_security_group.deadline_db_instance[0]: Refreshing state... [id=sg-0cae6491ceca891e8]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.773] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_security_group.deadline_license_forwarder[0]: Refreshing state... [id=sg-095cdbc0d09d15a70]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.783] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["destroy_deployment"]: Refreshing state... [id=destroy_deployment]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.784] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["store_file.sh"]: Refreshing state... [id=store_file.sh]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.786] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["zip"]: Refreshing state... [id=zip]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.788] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["build.sh"]: Refreshing state... [id=build.sh]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.791] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["add_images_to_env"]: Refreshing state... [id=add_images_to_env]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.793] [d-8PURENXH2][stdout]module.deadline_db_instance.data.aws_subnet.private: Read complete after 0s [id=subnet-060d475e84e0fcc6c]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.798] [d-8PURENXH2][stdout]module.bastion.aws_instance.bastion[0]: Refreshing state... [id=i-0b8fd1c9a6b062ff0]
2023-12-24T09:11:16.849000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.801] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["create_deployment_artifact"]: Refreshing state... [id=create_deployment_artifact]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.842] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["install_log_agent"]: Refreshing state... [id=install_log_agent]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.850] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["codedeploy_zip"]: Refreshing state... [id=codedeploy_zip]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.883] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["builder-install-packages"]: Refreshing state... [id=builder-install-packages]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.899] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["update_vars.sh"]: Refreshing state... [id=update_vars.sh]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.921] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["create_deployment"]: Refreshing state... [id=create_deployment]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:16.949] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_s3_object.update_scripts["env_modules.sh"]: Refreshing state... [id=env_modules.sh]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.009] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.data.aws_storagegateway_local_disk.cache[0]: Reading...
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.009] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Refreshing state... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.023] [d-8PURENXH2][stdout]module.deadline_db_instance.aws_instance.deadline_db_instance[0]: Refreshing state... [id=i-04c4fa76ed30ceeb6]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.062] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.aws_ssm_parameter.nfs_file_share_path: Refreshing state... [id=/firehawk/resourcetier/dev/cloud_nfs_filegateway_export]
2023-12-24T09:11:17.100000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.064] [d-8PURENXH2][stdout]module.terraform-aws-user-data-rendernode.data.template_file.user_data_auth_client: Reading...
2023-12-24T09:11:17.351000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.069] [d-8PURENXH2][stdout]module.terraform-aws-user-data-rendernode.data.template_file.user_data_auth_client: Read complete after 0s [id=1532f68aae4b502446cb750111cb7abad535dc5cdb5494565ba06158b0806c91]
2023-12-24T09:11:17.351000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.101] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.data.aws_storagegateway_local_disk.cache[0]: Read complete after 0s [id=9380bd39-3c69-444c-b9be-0d115be32507]
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:17.102] [d-8PURENXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_cache.storage_gateway_cache_resource[0]: Refreshing state... [id=arn:aws:storagegateway:**************:972620357255:gateway/sgw-3DE32054:9380bd39-3c69-444c-b9be-0d115be32507]
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]Changes to Outputs:
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]  + file_gateway_private_ip     = "10.1.134.101"
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]  + storage_gateway_resource_id = "arn:aws:storagegateway:**************:972620357255:gateway/sgw-3DE32054"
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]
2023-12-24T09:11:18.354000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]You can apply this plan to save these new output values to the Terraform
Deployment in progress... Status: Succeeded
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:18.217] [d-8PURENXH2][stdout]state, without changing any real infrastructure.
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]Outputs:
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]file_gateway_private_ip = "10.1.134.101"
2023-12-24T09:11:21.613000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]fsx_dns_name = ""
2023-12-24T09:11:25.716000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:11:21.390] [d-8PURENXH2][stdout]storage_gateway_resource_id = "arn:aws:storagegateway:**************:972620357255:gateway/sgw-3DE32054"
Deployment succeeded. Status: Succeeded

Additionally, if I try and destroy it hangs on downstream resources that dont exist. eg:

2023-12-24T09:33:14.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:33:10.147] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 3m30s elapsed]
Deployment in progress... Status: InProgress
Deployment in progress... Status: InProgress
2023-12-24T09:33:24.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:33:20.147] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 3m40s elapsed]
2023-12-24T09:33:34.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:33:30.148] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 3m50s elapsed]
Deployment in progress... Status: InProgress
Deployment in progress... Status: InProgress
2023-12-24T09:33:44.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:33:40.148] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m0s elapsed]
2023-12-24T09:33:54.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:33:50.149] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m10s elapsed]
Deployment in progress... Status: InProgress
Deployment in progress... Status: InProgress
2023-12-24T09:34:04.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:00.150] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m20s elapsed]
2023-12-24T09:34:14.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:10.150] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m30s elapsed]
Deployment in progress... Status: InProgress
2023-12-24T09:34:24.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:20.151] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m40s elapsed]
2023-12-24T09:34:34.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:30.152] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 4m50s elapsed]
Deployment in progress... Status: InProgress
Deployment in progress... Status: InProgress
2023-12-24T09:34:44.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:40.153] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 5m0s elapsed]
2023-12-24T09:34:54.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:34:50.154] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 5m10s elapsed]
Deployment in progress... Status: InProgress
Deployment in progress... Status: InProgress
2023-12-24T09:35:04.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:35:00.155] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 5m20s elapsed]
2023-12-24T09:35:14.640000+00:00 i-0be0d43a3e5dab12d-cdlog [2023-12-24 09:35:10.155] [d-TA6A6JXH2][stdout]module.terraform-aws-s3-file-gateway.aws_storagegateway_nfs_file_share.same_account[0]: Still destroying... [id=arn:aws:storagegateway:**************:972620357255:share/share-0D159C74, 5m30s elapsed]

Terraform Configuration Files

example module to reproduce the issue

data "aws_ssm_parameter" "gateway_ami" {
  name = "/aws/service/storagegateway/ami/FILE_S3/latest"
}
resource "aws_instance" "gateway" { # To troubleshoot, the ssh with username 'admin@ip_address'
  count         = var.cloud_s3_gateway_enabled ? 1 : 0
  ami           = data.aws_ssm_parameter.gateway_ami.value
  instance_type = var.instance_type
  tags          = {
    Name = var.instance_name
    role = "filegateway"
  }

  # Refer to AWS File Gateway documentation for minimum system requirements.
  ebs_optimized = true
  subnet_id     = length(local.subnet_ids) > 0 ? local.subnet_ids[0] : null

  ebs_block_device {
    device_name           = "/dev/xvdf"
    volume_size           = var.ebs_cache_volume_size
    volume_type           = "gp2"
    delete_on_termination = true
  }

  key_name = var.key_name

  vpc_security_group_ids = [
    var.storage_gateway_sg_id
  ]
}

locals {
  subnet_ids = var.use_public_subnet ? var.public_subnet_ids : var.private_subnet_ids
  private_ip          = aws_instance.gateway[0].private_ip
  public_ip           = aws_instance.gateway[0].public_ip
  file_gateway_id     = aws_storagegateway_gateway.storage_gateway_resource[0].id
  nfs_file_share_path = length(aws_storagegateway_nfs_file_share.same_account) > 0 ? aws_storagegateway_nfs_file_share.same_account[0].path : null
  smb_file_share_path = length(aws_storagegateway_smb_file_share.smb_share) > 0 ? aws_storagegateway_smb_file_share.smb_share[0].path : null
}

resource "aws_ssm_parameter" "nfs_file_share_path" {
  depends_on = [aws_instance.gateway]

  name      = "/firehawk/resourcetier/${var.resourcetier}/cloud_nfs_filegateway_export"
  type      = "String"
  value     = "${aws_instance.gateway[0].private_ip}:${local.nfs_file_share_path}"
  tags      = { "Name" : "cloud_nfs_filegateway_export" }
}

resource "aws_storagegateway_gateway" "storage_gateway_resource" {
  depends_on = [aws_instance.gateway]

  count              = var.cloud_s3_gateway_enabled ? 1 : 0
  gateway_ip_address = var.use_public_subnet ? local.public_ip : aws_instance.gateway[0].private_ip
  gateway_name       = var.gateway_name
  gateway_timezone   = var.gateway_time_zone
  gateway_type       = "FILE_S3"
  smb_guest_password = "MYSMBPASSWORD"
}

data "aws_storagegateway_local_disk" "cache" {
  count       = var.cloud_s3_gateway_enabled ? 1 : 0
  disk_path   = "/dev/xvdf"
  disk_node   = "/dev/xvdf"
  gateway_arn = aws_storagegateway_gateway.storage_gateway_resource[0].id
}

resource "aws_storagegateway_cache" "storage_gateway_cache_resource" {
  count       = var.cloud_s3_gateway_enabled ? 1 : 0
  disk_id     = length(data.aws_storagegateway_local_disk.cache) > 0 ? data.aws_storagegateway_local_disk.cache[0].id : null
  gateway_arn = aws_storagegateway_gateway.storage_gateway_resource[0].id
}

resource "aws_storagegateway_nfs_file_share" "same_account" {
  depends_on = [ aws_instance.gateway, aws_storagegateway_gateway.storage_gateway_resource ]
  count        = ((var.cloud_s3_gateway_export_type == "NFS") && var.cloud_s3_gateway_enabled) ? 1 : 0
  client_list  = var.permitted_cidr_list_private
  gateway_arn  = aws_storagegateway_gateway.storage_gateway_resource[0].id
  role_arn     = var.filegateway_role_arn
  location_arn = var.aws_s3_bucket_arn

  squash = "NoSquash" # see https://forums.aws.amazon.com/thread.jspa?messageID=886347&tstart=0 and https://docs.aws.amazon.com/storagegateway/latest/userguide/managing-gateway-file.html#edit-nfs-client

  nfs_file_share_defaults {
    directory_mode = "0777"
    file_mode      = "0666"
    group_id       = var.group_id
    owner_id       = var.owner_id
  }
}

resource "aws_storagegateway_smb_file_share" "smb_share" {
  count          = ((var.cloud_s3_gateway_export_type == "SMB") && var.cloud_s3_gateway_enabled) ? 1 : 0
  authentication = "GuestAccess"
  gateway_arn    = aws_storagegateway_gateway.storage_gateway_resource[0].id
  location_arn   = var.aws_s3_bucket_arn
  role_arn       = var.filegateway_role_arn
}

Steps to Reproduce

Since the gateway exists in a private subnet, terraform must be run from an instance in the same VPC to reproduce and all instances need internet access.

Debug Output

No response

Panic Output

No response

Important Factoids

This file gateway is being launched in a private subnet

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 10 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

queglay commented 10 months ago

Closing this due to some info being innacurate. I will reopen another ticket

github-actions[bot] commented 9 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.