I have below code which I am using for create s3 bucket and cloud front in aws through terraform but terraform gives error. I am using latest version of terraform cli exe for windows. Main.tf Please find below code of main.tf file :
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.70.0"
}
}
}
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_s3_bucket" "mybucket" {
bucket = "${var.bucket_name}"
acl = "public-read"
website {
redirect_all_requests_to = "index.html"
}
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT","POST"]
allowed_origins = ["*"]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.bucket_name}/*"
}
]
}
EOF
}
resource "aws_cloudfront_distribution" "distribution" {
origin {
domain_name = "${aws_s3_bucket.mybucket.website_endpoint}"
origin_id = "S3-${aws_s3_bucket.mybucket.bucket}"
custom_origin_config {
http_port = 80
https_port = 443
origin_protocol_policy = "match-viewer"
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
}
}
default_root_object = "index.html"
enabled = true
custom_error_response {
error_caching_min_ttl = 3000
error_code = 404
response_code = 200
response_page_path = "/index.html"
}
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-${aws_s3_bucket.mybucket.bucket}"
forwarded_values {
query_string = true
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
# Restricts who is able to access this content
restrictions {
geo_restriction {
# type of restriction, blacklist, whitelist or none
restriction_type = "none"
}
}
# SSL certificate for the service.
viewer_certificate {
cloudfront_default_certificate = true
}
}
Please find below error message:
Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider registry.terraform.io/hashicorp/aws: failed to retrieve schema
│ from provider "registry.terraform.io/hashicorp/aws": Plugin did not respond: The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).GetProviderSchema call. The
│ plugin logs may contain more details...
Please help to resolve the issue , I'm new in terraforms. P.S. This error generated while terraform plan
I had faced the same issue. The error was a little different tho. I was following the HashiCups provider example.
It happens when initializing it fails to upgrade or detect corrupt cached providers, or if you have changed the version but when you only run terraform init
it finds the version in cache and decides to go with it. Delete the terraform directory and lock file, and then init again terraform init -upgrade
If you're on running it on Apple M1 chip, you might as well need to set this:
export GODEBUG=asyncpreemptoff=1;
https://discuss.hashicorp.com/t/terraform-aws-provider-panic-plugin-did-not-respond/23396 https://github.com/hashicorp/terraform/issues/26104